mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix NamespaceSelectFilter not opening
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
26062aa20b
commit
c89d63ad3e
@ -3,12 +3,13 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observable, action, untracked, computed } from "mobx";
|
import { observable, action, untracked, computed, makeObservable } from "mobx";
|
||||||
import type { NamespaceStore } from "../store";
|
import type { NamespaceStore } from "../store";
|
||||||
import { isMac } from "../../../../common/vars";
|
import { isMac } from "../../../../common/vars";
|
||||||
import type { ActionMeta } from "react-select";
|
import type { ActionMeta } from "react-select";
|
||||||
import { Icon } from "../../icon";
|
import { Icon } from "../../icon";
|
||||||
import type { SelectOption } from "../../select";
|
import type { SelectOption } from "../../select";
|
||||||
|
import { autoBind } from "../../../utils";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
readonly namespaceStore: NamespaceStore;
|
readonly namespaceStore: NamespaceStore;
|
||||||
@ -17,11 +18,13 @@ interface Dependencies {
|
|||||||
export const selectAllNamespaces = Symbol("all-namespaces-selected");
|
export const selectAllNamespaces = Symbol("all-namespaces-selected");
|
||||||
|
|
||||||
export type SelectAllNamespaces = typeof selectAllNamespaces;
|
export type SelectAllNamespaces = typeof selectAllNamespaces;
|
||||||
|
|
||||||
export type NamespaceSelectFilterOption = SelectOption<string | SelectAllNamespaces>;
|
export type NamespaceSelectFilterOption = SelectOption<string | SelectAllNamespaces>;
|
||||||
|
|
||||||
export class NamespaceSelectFilterModel {
|
export class NamespaceSelectFilterModel {
|
||||||
constructor(private readonly dependencies: Dependencies) {}
|
constructor(private readonly dependencies: Dependencies) {
|
||||||
|
makeObservable(this);
|
||||||
|
autoBind(this);
|
||||||
|
}
|
||||||
|
|
||||||
readonly options = computed((): readonly NamespaceSelectFilterOption[] => {
|
readonly options = computed((): readonly NamespaceSelectFilterOption[] => {
|
||||||
const baseOptions = this.dependencies.namespaceStore.items.map(ns => ns.getName());
|
const baseOptions = this.dependencies.namespaceStore.items.map(ns => ns.getName());
|
||||||
@ -46,7 +49,7 @@ export class NamespaceSelectFilterModel {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
formatOptionLabel = ({ value, isSelected }: NamespaceSelectFilterOption) => {
|
formatOptionLabel({ value, isSelected }: NamespaceSelectFilterOption) {
|
||||||
if (value === selectAllNamespaces) {
|
if (value === selectAllNamespaces) {
|
||||||
return "All Namespaces";
|
return "All Namespaces";
|
||||||
}
|
}
|
||||||
@ -64,34 +67,37 @@ export class NamespaceSelectFilterModel {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
readonly menuIsOpen = observable.box(false);
|
readonly menuIsOpen = observable.box(false);
|
||||||
|
|
||||||
closeMenu = action(() => {
|
@action
|
||||||
|
closeMenu() {
|
||||||
this.menuIsOpen.set(false);
|
this.menuIsOpen.set(false);
|
||||||
});
|
}
|
||||||
|
|
||||||
openMenu = action(() => {
|
@action
|
||||||
|
openMenu(){
|
||||||
this.menuIsOpen.set(true);
|
this.menuIsOpen.set(true);
|
||||||
});
|
}
|
||||||
|
|
||||||
get selectedNames() {
|
get selectedNames() {
|
||||||
return untracked(() => this.dependencies.namespaceStore.selectedNames);
|
return untracked(() => this.dependencies.namespaceStore.selectedNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
isSelected = (namespace: string | string[]) =>
|
isSelected(namespace: string | string[]) {
|
||||||
this.dependencies.namespaceStore.hasContext(namespace);
|
return this.dependencies.namespaceStore.hasContext(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
selectSingle = (namespace: string) => {
|
selectSingle(namespace: string) {
|
||||||
this.dependencies.namespaceStore.selectSingle(namespace);
|
this.dependencies.namespaceStore.selectSingle(namespace);
|
||||||
};
|
}
|
||||||
|
|
||||||
selectAll = () => {
|
selectAll() {
|
||||||
this.dependencies.namespaceStore.selectAll();
|
this.dependencies.namespaceStore.selectAll();
|
||||||
};
|
}
|
||||||
|
|
||||||
onChange = (namespace: unknown, action: ActionMeta<NamespaceSelectFilterOption>) => {
|
onChange(namespace: unknown, action: ActionMeta<NamespaceSelectFilterOption>) {
|
||||||
switch (action.action) {
|
switch (action.action) {
|
||||||
case "clear":
|
case "clear":
|
||||||
this.dependencies.namespaceStore.selectAll();
|
this.dependencies.namespaceStore.selectAll();
|
||||||
@ -113,34 +119,35 @@ export class NamespaceSelectFilterModel {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
onClick = () => {
|
onClick() {
|
||||||
if (!this.menuIsOpen) {
|
if (!this.menuIsOpen.get()) {
|
||||||
this.openMenu();
|
this.openMenu();
|
||||||
} else if (!this.isMultiSelection) {
|
} else if (!this.isMultiSelection) {
|
||||||
this.closeMenu();
|
this.closeMenu();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
private isMultiSelection = false;
|
private isMultiSelection = false;
|
||||||
|
|
||||||
onKeyDown = (event: React.KeyboardEvent) => {
|
onKeyDown(event: React.KeyboardEvent) {
|
||||||
if (isSelectionKey(event)) {
|
if (isSelectionKey(event)) {
|
||||||
this.isMultiSelection = true;
|
this.isMultiSelection = true;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
onKeyUp = (event: React.KeyboardEvent) => {
|
onKeyUp(event: React.KeyboardEvent) {
|
||||||
if (isSelectionKey(event)) {
|
if (isSelectionKey(event)) {
|
||||||
this.isMultiSelection = false;
|
this.isMultiSelection = false;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
reset = action(() => {
|
@action
|
||||||
|
reset() {
|
||||||
this.isMultiSelection = false;
|
this.isMultiSelection = false;
|
||||||
this.closeMenu();
|
this.closeMenu();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSelectionKey = (event: React.KeyboardEvent): boolean => {
|
const isSelectionKey = (event: React.KeyboardEvent): boolean => {
|
||||||
|
|||||||
@ -24,31 +24,28 @@ interface Dependencies {
|
|||||||
model: NamespaceSelectFilterModel;
|
model: NamespaceSelectFilterModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NonInjectedNamespaceSelectFilter = observer(({ model, id }: Dependencies & NamespaceSelectFilterProps) => {
|
const NonInjectedNamespaceSelectFilter = observer(({ model, id }: Dependencies & NamespaceSelectFilterProps) => (
|
||||||
return (
|
<div
|
||||||
<div
|
onKeyUp={model.onKeyUp}
|
||||||
onKeyUp={model.onKeyUp}
|
onKeyDown={model.onKeyDown}
|
||||||
onKeyDown={model.onKeyDown}
|
onClick={model.onClick}
|
||||||
onClick={model.onClick}
|
>
|
||||||
>
|
<Select<string | SelectAllNamespaces, NamespaceSelectFilterOption, true>
|
||||||
<Select<string | SelectAllNamespaces, NamespaceSelectFilterOption, true>
|
id={id}
|
||||||
id={id}
|
isMulti={true}
|
||||||
isMulti={true}
|
isClearable={false}
|
||||||
isClearable={false}
|
menuIsOpen={model.menuIsOpen.get()}
|
||||||
menuIsOpen={model.menuIsOpen.get()}
|
components={{ Placeholder }}
|
||||||
components={{ Placeholder }}
|
closeMenuOnSelect={false}
|
||||||
closeMenuOnSelect={false}
|
controlShouldRenderValue={false}
|
||||||
controlShouldRenderValue={false}
|
onChange={model.onChange}
|
||||||
onChange={model.onChange}
|
onBlur={model.reset}
|
||||||
onBlur={model.reset}
|
formatOptionLabel={model.formatOptionLabel}
|
||||||
formatOptionLabel={model.formatOptionLabel}
|
options={model.options.get()}
|
||||||
options={model.options.get()}
|
className="NamespaceSelect NamespaceSelectFilter"
|
||||||
className="NamespaceSelect NamespaceSelectFilter"
|
menuClass="NamespaceSelectFilterMenu" />
|
||||||
menuClass="NamespaceSelectFilterMenu"
|
</div>
|
||||||
/>
|
));
|
||||||
</div>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
export const NamespaceSelectFilter = withInjectables<Dependencies, NamespaceSelectFilterProps>(NonInjectedNamespaceSelectFilter, {
|
export const NamespaceSelectFilter = withInjectables<Dependencies, NamespaceSelectFilterProps>(NonInjectedNamespaceSelectFilter, {
|
||||||
getProps: (di, props) => ({
|
getProps: (di, props) => ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user