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

Refactor the options

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-06-27 14:43:38 -04:00
parent 9a62b4a9ae
commit c88a821792

View File

@ -60,7 +60,7 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names
equals: comparer.structural, equals: comparer.structural,
}); });
const optionsSortingSelected = observable.set(selectedNames.get()); const optionsSortingSelected = observable.set(selectedNames.get());
const sortNamespacesByIfTheyAreSelected = (left: string, right: string) => { const sortNamespacesByIfTheyHaveBeenSelected = (left: string, right: string) => {
const isLeftSelected = optionsSortingSelected.has(left); const isLeftSelected = optionsSortingSelected.has(left);
const isRightSelected = optionsSortingSelected.has(right); const isRightSelected = optionsSortingSelected.has(right);
@ -68,27 +68,26 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names
return 0; return 0;
} }
return isLeftSelected return isRightSelected
? 1 ? 1
: -1; : -1;
}; };
const options = computed((): readonly NamespaceSelectFilterOption[] => [
const options = computed((): readonly NamespaceSelectFilterOption[] => {
return [
{ {
value: selectAllNamespaces, value: selectAllNamespaces,
label: "All Namespaces", label: "All Namespaces",
id: "all-namespaces",
}, },
...namespaceStore ...namespaceStore
.items .items
.map(ns => ns.getName()) .map(ns => ns.getName())
.sort(sortNamespacesByIfTheyAreSelected) .sort(sortNamespacesByIfTheyHaveBeenSelected)
.map(namespace => ({ .map(namespace => ({
value: namespace, value: namespace,
label: namespace, label: namespace,
id: namespace,
})), })),
]; ]);
});
const menuIsOpen = computed(() => menuState.get() === SelectMenuState.Open); const menuIsOpen = computed(() => menuState.get() === SelectMenuState.Open);
const isOptionSelected: NamespaceSelectFilterModel["isOptionSelected"] = (option) => { const isOptionSelected: NamespaceSelectFilterModel["isOptionSelected"] = (option) => {
if (option.value === selectAllNamespaces) { if (option.value === selectAllNamespaces) {