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