Skip to content

Commit

Permalink
fix(ui): use available namespace as selected before default fallback (#…
Browse files Browse the repository at this point in the history
…3719)

There could be situations when previously selected or default
namespace is not available for user. It could be the case that
default namespace was deleted or authz has a specific rules.
This PR will try to get the first available namespace before
falling back to default mock.

Signed-off-by: Roman Dmytrenko <[email protected]>
  • Loading branch information
erka authored Dec 12, 2024
1 parent 2ca2273 commit 729a965
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ui/src/app/namespaces/namespacesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,22 @@ export const selectNamespaces = createSelector(

export const selectCurrentNamespace = createSelector(
[(state: RootState) => state.namespaces],
(namespaces) =>
namespaces.namespaces[namespaces.currentNamespace] ||
({ key: 'default', name: 'Default', description: '' } as INamespace)
(state) => {
if (state.namespaces[state.currentNamespace]) {
return state.namespaces[state.currentNamespace];
}

if (state.namespaces.default) {
return state.namespaces.default;
}

const ns = Object.keys(state.namespaces);
if (ns.length > 0) {
return state.namespaces[ns[0]];
}

return { key: 'default', name: 'Default', description: '' } as INamespace;
}
);

export const namespaceApi = createApi({
Expand Down

0 comments on commit 729a965

Please sign in to comment.