Skip to content

Commit

Permalink
Fix default selected namespace when using limited namespace visibility
Browse files Browse the repository at this point in the history
When the `--namespaces` arg is set to restrict namespace visibility,
the Dashboard was incorrectly defaulting to the first namespace in
the list on page load instead of using the namespace specified in
the URL.

Move the logic to select the default namespace from the top-level
app component into the header where we're already checking for the
selected namespace from the URL.
  • Loading branch information
AlanGreene committed Sep 28, 2023
1 parent ebbe9b1 commit fa6f4af
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/containers/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { useEffect, useMemo, useState } from 'react';
import React, { useMemo, useState } from 'react';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { hot } from 'react-hot-loader/root';
import { Link, Redirect, HashRouter as Router, Switch } from 'react-router-dom';
Expand Down Expand Up @@ -181,12 +181,6 @@ export function App({ lang }) {
isWebSocketConnected
);

useEffect(() => {
if (!isFetchingConfig && tenantNamespaces.length) {
setSelectedNamespace(tenantNamespaces[0]);
}
}, [isFetchingConfig, JSON.stringify(tenantNamespaces)]);

const logoutButton = <LogoutButton getLogoutURL={() => logoutURL} />;

const namespaceContext = useMemo(
Expand Down
4 changes: 3 additions & 1 deletion src/containers/HeaderBarContent/HeaderBarContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export default function HeaderBarContent({ isFetchingConfig, logoutButton }) {
useEffect(() => {
if (params.namespace) {
selectNamespace(params.namespace);
} else if (tenantNamespaces.length) {
selectNamespace(tenantNamespaces[0]);
}
}, [params.namespace]);
}, [params.namespace, JSON.stringify(tenantNamespaces)]);

function setPath(path, { dropQueryParams } = {}) {
navigate(`${path}${dropQueryParams ? '' : location.search}`);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/NamespacesDropdown/NamespacesDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const NamespacesDropdown = ({
disableWebSocket: true
});

let selectedItem = { ...originalSelectedItem };
const selectedItem = { ...originalSelectedItem };
if (selectedItem && selectedItem.id === ALL_NAMESPACES) {
selectedItem.text = allNamespacesString;
}
Expand Down

0 comments on commit fa6f4af

Please sign in to comment.