diff --git a/frontend/src/lib/k8s/api/v2/useKubeObjectList.ts b/frontend/src/lib/k8s/api/v2/useKubeObjectList.ts index 4e11f8033f..d4b383b068 100644 --- a/frontend/src/lib/k8s/api/v2/useKubeObjectList.ts +++ b/frontend/src/lib/k8s/api/v2/useKubeObjectList.ts @@ -313,9 +313,21 @@ export function useKubeObjectList({ queryParams: cleanedUpQueryParams, }); + const sortedItems = useMemo(() => { + if (!query.items) { + return query.items; + } + + if (kubeObjectClass.kind === 'Namespace') { + return query.items.slice().sort((a, b) => a.metadata.name.localeCompare(b.metadata.name)); + } + + return query.items; + }, [query.items, kubeObjectClass]); + // @ts-ignore - TS compiler gets confused with iterators return { - items: query.items, + items: sortedItems, clusterResults: query.clusterResults, clusterErrors: query.clusterErrors, isError: query.isError, @@ -323,7 +335,7 @@ export function useKubeObjectList({ isFetching: query.isFetching, isSuccess: query.isSuccess, *[Symbol.iterator](): ArrayIterator { - yield query.items; + yield sortedItems; yield query.errors[0] as any as ApiError; }, };