From fc0baa5b3bf5587f8e012e19ab09b84d51fbd47c Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 21 Jun 2022 14:22:14 -0400 Subject: [PATCH] Fix check on NamespaceSelectFilter not updating Signed-off-by: Sebastian Malton --- .../namespace-select-filter-model.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx b/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx index 9731abf8b8..e529fa55bf 100644 --- a/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx +++ b/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ 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 { isMac } from "../../../../common/vars"; import type { ActionMeta } from "react-select"; @@ -26,13 +26,18 @@ export class NamespaceSelectFilterModel { autoBind(this); } + readonly selectedNames = computed(() => new Set(this.dependencies.namespaceStore.contextNamespaces), { + equals: comparer.structural, + }); + readonly options = computed((): readonly NamespaceSelectFilterOption[] => { const baseOptions = this.dependencies.namespaceStore.items.map(ns => ns.getName()); + const selectedNames = this.selectedNames.get(); baseOptions.sort(( (left, right) => - +this.selectedNames.has(right) - - +this.selectedNames.has(left) + +selectedNames.has(right) + - +selectedNames.has(left) )); return [ @@ -44,7 +49,7 @@ export class NamespaceSelectFilterModel { ...baseOptions.map(namespace => ({ value: namespace, label: namespace, - isSelected: this.selectedNames.has(namespace), + isSelected: selectedNames.has(namespace), })), ]; }); @@ -81,10 +86,6 @@ export class NamespaceSelectFilterModel { this.menuIsOpen.set(true); } - get selectedNames() { - return untracked(() => this.dependencies.namespaceStore.selectedNames); - } - isSelected(namespace: string | string[]) { return this.dependencies.namespaceStore.hasContext(namespace); }