Skip to content

Commit

Permalink
frontend: k8s: Sort namespaces in UI
Browse files Browse the repository at this point in the history
This change alphabetically sorts namespaces in the UI, addressing the
case where namespace lists from k3d/k3s clusters are not sorted by
default.

Fixes: #2656

Signed-off-by: Evangelos Skopelitis <[email protected]>
  • Loading branch information
skoeva committed Dec 16, 2024
1 parent c97a07c commit 442954c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion frontend/src/components/common/NamespacesAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ function NamespacesFromClusterAutocomplete(
) {
const [namespacesList] = Namespace.useList();
const namespaceNames = useMemo(
() => namespacesList?.map(namespace => namespace.metadata.name) ?? [],
() =>
namespacesList
?.map(namespace => namespace.metadata.name)
.slice()
.sort((a, b) => a.localeCompare(b)) ?? [],
[namespacesList]
);

Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/common/Resource/ResourceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@ function TableFromResourceClass<KubeClass extends KubeObjectClass>(
const { resourceClass, id, ...otherProps } = props;
const { items, error, clusterErrors } = resourceClass.useList({ namespace: useNamespaces() });

const sortedItems = useMemo(() => {
if (!items) return items;
return items.slice().sort((a, b) => a.metadata.name.localeCompare(b.metadata.name));
}, [items]);

// throttle the update of the table to once per second
const throttledItems = useThrottle(items, 1000);
const throttledItems = useThrottle(sortedItems, 1000);
const dispatchHeadlampEvent = useEventCallback(HeadlampEventType.LIST_VIEW);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
tls-example-ingress
resource-example-ingress
</a>
</td>
<td
Expand Down Expand Up @@ -740,12 +740,11 @@
class="MuiTableCell-root MuiTableCell-alignLeft MuiTableCell-sizeMedium css-1e2xkc-MuiTableCell-root"
>
<span
aria-label="/ 🞂 service1:80
/second 🞂 service2:someport"
aria-label="/ 🞂 Service:service1"
class=""
data-mui-internal-clone-element="true"
>
/ 🞂 service1:80, /second 🞂 service2:someport
/ 🞂 Service:service1
</span>
</td>
<td
Expand Down Expand Up @@ -827,7 +826,7 @@
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
resource-example-ingress
tls-example-ingress
</a>
</td>
<td
Expand Down Expand Up @@ -858,11 +857,12 @@
class="MuiTableCell-root MuiTableCell-alignLeft MuiTableCell-sizeMedium css-1e2xkc-MuiTableCell-root"
>
<span
aria-label="/ 🞂 Service:service1"
aria-label="/ 🞂 service1:80
/second 🞂 service2:someport"
class=""
data-mui-internal-clone-element="true"
>
/ 🞂 Service:service1
/ 🞂 service1:80, /second 🞂 service2:someport
</span>
</td>
<td
Expand Down

0 comments on commit 442954c

Please sign in to comment.