1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix check on NamespaceSelectFilter not updating

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-06-21 14:22:14 -04:00
parent 666d90dd3c
commit fc0baa5b3b

View File

@ -3,7 +3,7 @@
* 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, makeObservable } from "mobx"; import { observable, action, computed, makeObservable, comparer } 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";
@ -26,13 +26,18 @@ export class NamespaceSelectFilterModel {
autoBind(this); autoBind(this);
} }
readonly selectedNames = computed(() => new Set(this.dependencies.namespaceStore.contextNamespaces), {
equals: comparer.structural,
});
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());
const selectedNames = this.selectedNames.get();
baseOptions.sort(( baseOptions.sort((
(left, right) => (left, right) =>
+this.selectedNames.has(right) +selectedNames.has(right)
- +this.selectedNames.has(left) - +selectedNames.has(left)
)); ));
return [ return [
@ -44,7 +49,7 @@ export class NamespaceSelectFilterModel {
...baseOptions.map(namespace => ({ ...baseOptions.map(namespace => ({
value: namespace, value: namespace,
label: namespace, label: namespace,
isSelected: this.selectedNames.has(namespace), isSelected: selectedNames.has(namespace),
})), })),
]; ];
}); });
@ -81,10 +86,6 @@ export class NamespaceSelectFilterModel {
this.menuIsOpen.set(true); this.menuIsOpen.set(true);
} }
get selectedNames() {
return untracked(() => this.dependencies.namespaceStore.selectedNames);
}
isSelected(namespace: string | string[]) { isSelected(namespace: string | string[]) {
return this.dependencies.namespaceStore.hasContext(namespace); return this.dependencies.namespaceStore.hasContext(namespace);
} }