mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Selecting one namespace at a time (#2919)
Signed-off-by: vshakirova <vshakirova@mirantis.com>
This commit is contained in:
parent
52ab699426
commit
538c6c2013
@ -30,6 +30,8 @@ import { NamespaceSelect } from "./namespace-select";
|
|||||||
import { namespaceStore } from "./namespace.store";
|
import { namespaceStore } from "./namespace.store";
|
||||||
|
|
||||||
import type { SelectOption, SelectProps } from "../select";
|
import type { SelectOption, SelectProps } from "../select";
|
||||||
|
import { isLinux, isMac, isWindows } from "../../../common/vars";
|
||||||
|
import { observable } from "mobx";
|
||||||
|
|
||||||
const Placeholder = observer((props: PlaceholderProps<any, boolean>) => {
|
const Placeholder = observer((props: PlaceholderProps<any, boolean>) => {
|
||||||
const getPlaceholder = (): React.ReactNode => {
|
const getPlaceholder = (): React.ReactNode => {
|
||||||
@ -55,13 +57,16 @@ const Placeholder = observer((props: PlaceholderProps<any, boolean>) => {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
||||||
|
static isMultiSelection = observable.box(false);
|
||||||
|
static isMenuOpen = observable.box(false);
|
||||||
|
|
||||||
formatOptionLabel({ value: namespace, label }: SelectOption) {
|
formatOptionLabel({ value: namespace, label }: SelectOption) {
|
||||||
if (namespace) {
|
if (namespace) {
|
||||||
const isSelected = namespaceStore.hasContext(namespace);
|
const isSelected = namespaceStore.hasContext(namespace);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center">
|
||||||
<Icon small material="layers" />
|
<Icon small material="layers"/>
|
||||||
<span>{namespace}</span>
|
<span>{namespace}</span>
|
||||||
{isSelected && <Icon small material="check" className="box right"/>}
|
{isSelected && <Icon small material="check" className="box right"/>}
|
||||||
</div>
|
</div>
|
||||||
@ -72,26 +77,55 @@ export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChange([{ value: namespace }]: SelectOption[]) {
|
onChange([{ value: namespace }]: SelectOption[]) {
|
||||||
if (namespace) {
|
if (NamespaceSelectFilter.isMultiSelection.get() && namespace) {
|
||||||
namespaceStore.toggleContext(namespace);
|
namespaceStore.toggleContext(namespace);
|
||||||
|
} else if (!NamespaceSelectFilter.isMultiSelection.get() && namespace) {
|
||||||
|
namespaceStore.toggleSingle(namespace);
|
||||||
} else {
|
} else {
|
||||||
namespaceStore.toggleAll(false); // "All namespaces" clicked
|
namespaceStore.toggleAll(true); // "All namespaces" clicked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onKeyDown = (e: React.KeyboardEvent<any>) => {
|
||||||
|
if (isMac && e.metaKey || (isWindows || isLinux) && e.ctrlKey) {
|
||||||
|
NamespaceSelectFilter.isMultiSelection.set(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onKeyUp = (e: React.KeyboardEvent<any>) => {
|
||||||
|
if (isMac && e.key === "Meta" || (isWindows || isLinux) && e.key === "Control") {
|
||||||
|
NamespaceSelectFilter.isMultiSelection.set(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onClick = () => {
|
||||||
|
if (!NamespaceSelectFilter.isMultiSelection.get()) {
|
||||||
|
NamespaceSelectFilter.isMenuOpen.set(!NamespaceSelectFilter.isMenuOpen.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
reset = () => {
|
||||||
|
NamespaceSelectFilter.isMultiSelection.set(false);
|
||||||
|
NamespaceSelectFilter.isMenuOpen.set(false);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
<div onKeyUp={this.onKeyUp} onKeyDown={this.onKeyDown} onClick={this.onClick}>
|
||||||
<NamespaceSelect
|
<NamespaceSelect
|
||||||
isMulti={true}
|
isMulti={true}
|
||||||
|
menuIsOpen={NamespaceSelectFilter.isMenuOpen.get()}
|
||||||
components={{ Placeholder }}
|
components={{ Placeholder }}
|
||||||
showAllNamespacesOption={true}
|
showAllNamespacesOption={true}
|
||||||
closeMenuOnSelect={false}
|
closeMenuOnSelect={false}
|
||||||
controlShouldRenderValue={false}
|
controlShouldRenderValue={false}
|
||||||
placeholder={""}
|
placeholder={""}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
|
onBlur={this.reset}
|
||||||
formatOptionLabel={this.formatOptionLabel}
|
formatOptionLabel={this.formatOptionLabel}
|
||||||
className="NamespaceSelectFilter"
|
className="NamespaceSelectFilter"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -161,6 +161,12 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
toggleSingle(namespace: string){
|
||||||
|
this.clearSelected();
|
||||||
|
this.selectNamespaces(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
toggleAll(showAll?: boolean) {
|
toggleAll(showAll?: boolean) {
|
||||||
if (typeof showAll === "boolean") {
|
if (typeof showAll === "boolean") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user