mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix namespace selector performance issues on large clusters
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
f6193718ff
commit
e89a5e4f20
@ -35,6 +35,10 @@ import { isMac } from "../../../common/vars";
|
|||||||
|
|
||||||
const Placeholder = observer((props: PlaceholderProps<any, boolean>) => {
|
const Placeholder = observer((props: PlaceholderProps<any, boolean>) => {
|
||||||
const getPlaceholder = (): React.ReactNode => {
|
const getPlaceholder = (): React.ReactNode => {
|
||||||
|
if (props.isFocused) {
|
||||||
|
return <>Search Namespaces ...</>;
|
||||||
|
}
|
||||||
|
|
||||||
const namespaces = namespaceStore.contextNamespaces;
|
const namespaces = namespaceStore.contextNamespaces;
|
||||||
|
|
||||||
if (namespaceStore.areAllSelectedImplicitly || !namespaces.length) {
|
if (namespaceStore.areAllSelectedImplicitly || !namespaces.length) {
|
||||||
@ -91,7 +95,11 @@ export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
|||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.isMenuOpen, newVal => {
|
reaction(() => this.isMenuOpen, newVal => {
|
||||||
if (newVal) { // rising edge of selection
|
if (newVal) { // rising edge of selection
|
||||||
|
if (namespaceStore.areAllSelectedImplicitly) {
|
||||||
|
this.selected.replace([""]);
|
||||||
|
} else {
|
||||||
this.selected.replace(namespaceStore.selectedNames);
|
this.selected.replace(namespaceStore.selectedNames);
|
||||||
|
}
|
||||||
this.didToggle = false;
|
this.didToggle = false;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@ -99,21 +107,23 @@ export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
formatOptionLabel({ value: namespace, label }: SelectOption) {
|
formatOptionLabel({ value: namespace, label }: SelectOption) {
|
||||||
|
let isSelected = false;
|
||||||
|
|
||||||
if (namespace) {
|
if (namespace) {
|
||||||
const isSelected = namespaceStore.hasContext(namespace);
|
isSelected = !namespaceStore.areAllSelectedImplicitly && namespaceStore.hasContext(namespace);
|
||||||
|
} else {
|
||||||
|
isSelected = namespaceStore.areAllSelectedImplicitly;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center">
|
||||||
<Icon small material="layers" />
|
<Icon small material={ namespace ? "layers" : "panorama_wide_angle" } />
|
||||||
<span>{namespace}</span>
|
<span>{label}</span>
|
||||||
{isSelected && <Icon small material="check" className="box right" />}
|
{isSelected && <Icon small material="check" className="box right" />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onChange = ([{ value: namespace }]: SelectOption[]) => {
|
onChange = ([{ value: namespace }]: SelectOption[]) => {
|
||||||
if (namespace) {
|
if (namespace) {
|
||||||
|
|||||||
@ -53,7 +53,7 @@ export class NamespaceSelect extends React.Component<Props> {
|
|||||||
|
|
||||||
@computed.struct get options(): SelectOption[] {
|
@computed.struct get options(): SelectOption[] {
|
||||||
const { customizeOptions, showAllNamespacesOption, sort } = this.props;
|
const { customizeOptions, showAllNamespacesOption, sort } = this.props;
|
||||||
let options: SelectOption[] = namespaceStore.items.map(ns => ({ value: ns.getName() }));
|
let options: SelectOption[] = namespaceStore.items.map(ns => ({ value: ns.getName(), label: ns.getName() }));
|
||||||
|
|
||||||
if (sort) {
|
if (sort) {
|
||||||
options.sort(sort);
|
options.sort(sort);
|
||||||
@ -82,6 +82,24 @@ export class NamespaceSelect extends React.Component<Props> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
filterOption = (option: SelectOption, rawInput: string) => {
|
||||||
|
if (option.value === "" || (!namespaceStore.areAllSelectedImplicitly && namespaceStore.selectedNames.has(option.value))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (namespaceStore.items.length > 500 && rawInput.length < 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rawInput && !option.value.includes(rawInput)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("raw", rawInput);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, showIcons, customizeOptions, components = {}, ...selectProps } = this.props;
|
const { className, showIcons, customizeOptions, components = {}, ...selectProps } = this.props;
|
||||||
|
|
||||||
@ -92,6 +110,7 @@ export class NamespaceSelect extends React.Component<Props> {
|
|||||||
formatOptionLabel={this.formatOptionLabel}
|
formatOptionLabel={this.formatOptionLabel}
|
||||||
options={this.options}
|
options={this.options}
|
||||||
components={components}
|
components={components}
|
||||||
|
filterOption={this.filterOption}
|
||||||
{...selectProps}
|
{...selectProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user