mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix namespace selector not closing after multi select
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
fc0baa5b3b
commit
8c6aabf29b
@ -5,12 +5,14 @@
|
||||
import { NamespaceSelectFilterModel } from "./namespace-select-filter-model";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import namespaceStoreInjectable from "../store.injectable";
|
||||
import isMacInjectable from "../../../../common/vars/is-mac.injectable";
|
||||
|
||||
const namespaceSelectFilterModelInjectable = getInjectable({
|
||||
id: "namespace-select-filter-model",
|
||||
|
||||
instantiate: (di) => new NamespaceSelectFilterModel({
|
||||
namespaceStore: di.inject(namespaceStoreInjectable),
|
||||
isMac: di.inject(isMacInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
import React from "react";
|
||||
import { observable, action, computed, makeObservable, comparer } from "mobx";
|
||||
import type { NamespaceStore } from "../store";
|
||||
import { isMac } from "../../../../common/vars";
|
||||
import type { ActionMeta } from "react-select";
|
||||
import { Icon } from "../../icon";
|
||||
import type { SelectOption } from "../../select";
|
||||
@ -13,6 +12,7 @@ import { autoBind } from "../../../utils";
|
||||
|
||||
interface Dependencies {
|
||||
readonly namespaceStore: NamespaceStore;
|
||||
readonly isMac: boolean;
|
||||
}
|
||||
|
||||
export const selectAllNamespaces = Symbol("all-namespaces-selected");
|
||||
@ -21,6 +21,14 @@ export type SelectAllNamespaces = typeof selectAllNamespaces;
|
||||
export type NamespaceSelectFilterOption = SelectOption<string | SelectAllNamespaces>;
|
||||
|
||||
export class NamespaceSelectFilterModel {
|
||||
private isSelectionKey = (event: React.KeyboardEvent): boolean => {
|
||||
if (this.dependencies.isMac) {
|
||||
return event.key === "Meta";
|
||||
}
|
||||
|
||||
return event.key === "Control"; // windows or linux
|
||||
};
|
||||
|
||||
constructor(private readonly dependencies: Dependencies) {
|
||||
makeObservable(this);
|
||||
autoBind(this);
|
||||
@ -105,13 +113,17 @@ export class NamespaceSelectFilterModel {
|
||||
break;
|
||||
case "deselect-option":
|
||||
if (typeof action.option === "string") {
|
||||
this.didToggle = true;
|
||||
this.dependencies.namespaceStore.toggleSingle(action.option);
|
||||
}
|
||||
break;
|
||||
case "select-option":
|
||||
if (action.option?.value === selectAllNamespaces) {
|
||||
this.didToggle = true;
|
||||
this.dependencies.namespaceStore.selectAll();
|
||||
} else if (action.option) {
|
||||
this.didToggle = true;
|
||||
|
||||
if (this.isMultiSelection) {
|
||||
this.dependencies.namespaceStore.toggleSingle(action.option.value);
|
||||
} else {
|
||||
@ -133,14 +145,20 @@ export class NamespaceSelectFilterModel {
|
||||
private isMultiSelection = false;
|
||||
|
||||
onKeyDown(event: React.KeyboardEvent) {
|
||||
if (isSelectionKey(event)) {
|
||||
if (this.isSelectionKey(event)) {
|
||||
this.isMultiSelection = true;
|
||||
}
|
||||
}
|
||||
|
||||
private didToggle = false;
|
||||
|
||||
onKeyUp(event: React.KeyboardEvent) {
|
||||
if (isSelectionKey(event)) {
|
||||
if (this.isSelectionKey(event)) {
|
||||
this.isMultiSelection = false;
|
||||
|
||||
if (this.didToggle) {
|
||||
this.closeMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,11 +168,3 @@ export class NamespaceSelectFilterModel {
|
||||
this.closeMenu();
|
||||
}
|
||||
}
|
||||
|
||||
const isSelectionKey = (event: React.KeyboardEvent): boolean => {
|
||||
if (isMac) {
|
||||
return event.key === "Meta";
|
||||
}
|
||||
|
||||
return event.key === "Control"; // windows or linux
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user