Skip to content

Commit 41d711e

Browse files
committed
fix(Header): wait for capabilities before show content
1 parent c830f2a commit 41d711e

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/containers/App/Content.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import routes, {getClusterPath} from '../../routes';
1414
import type {RootState} from '../../store';
1515
import {authenticationApi} from '../../store/reducers/authentication/authentication';
1616
import {
17+
useAllCapabilitiesLoaded,
1718
useCapabilitiesQuery,
1819
useClusterWithoutAuthInUI,
1920
useMetaCapabilitiesLoaded,
@@ -235,11 +236,10 @@ function GetNodesList() {
235236
}
236237

237238
function GetCapabilities({children}: {children: React.ReactNode}) {
238-
const {data, error} = useCapabilitiesQuery();
239+
const {error} = useCapabilitiesQuery();
239240

240241
useMetaCapabilitiesQuery();
241-
// It is always true if there is no meta, since request finishes with an error
242-
const metaCapabilitiesLoaded = useMetaCapabilitiesLoaded();
242+
const capabilitiesLoaded = useAllCapabilitiesLoaded();
243243

244244
//do nothing, authentication is in progress upon redirect
245245
if (isRedirectToAuth(error)) {
@@ -250,10 +250,8 @@ function GetCapabilities({children}: {children: React.ReactNode}) {
250250
return <AccessDenied />;
251251
}
252252

253-
const capabilitiesLoaded = Boolean(data || error);
254-
255253
return (
256-
<LoaderWrapper loading={!capabilitiesLoaded || !metaCapabilitiesLoaded} size="l">
254+
<LoaderWrapper loading={!capabilitiesLoaded} size="l">
257255
{children}
258256
</LoaderWrapper>
259257
);

src/containers/Header/Header.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {checkIsClustersPage, checkIsTenantPage, getClusterPath} from '../../rout
1919
import {environment} from '../../store';
2020
import {
2121
useAddClusterFeatureAvailable,
22+
useAllCapabilitiesLoaded,
2223
useDatabasesAvailable,
2324
useDeleteDatabaseFeatureAvailable,
2425
useEditDatabaseFeatureAvailable,
@@ -50,6 +51,7 @@ import './Header.scss';
5051
const b = cn('header');
5152

5253
function Header() {
54+
const capabilitiesLoaded = useAllCapabilitiesLoaded();
5355
const {page, pageBreadcrumbsOptions} = useTypedSelector((state) => state.header);
5456
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);
5557
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
@@ -242,9 +244,12 @@ function Header() {
242244
return null;
243245
};
244246

245-
const renderHeader = () => {
247+
const renderContent = () => {
248+
if (!capabilitiesLoaded) {
249+
return null;
250+
}
246251
return (
247-
<header className={b()}>
252+
<React.Fragment>
248253
<Breadcrumbs className={b('breadcrumbs')}>
249254
{breadcrumbItems.map((item, index) => {
250255
const {icon, text, link} = item;
@@ -268,9 +273,13 @@ function Header() {
268273
</Breadcrumbs>
269274

270275
{renderRightControls()}
271-
</header>
276+
</React.Fragment>
272277
);
273278
};
279+
280+
const renderHeader = () => {
281+
return <header className={b()}>{renderContent()}</header>;
282+
};
274283
return renderHeader();
275284
}
276285

src/store/reducers/capabilities/hooks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export function useCapabilitiesLoaded() {
3030
return Boolean(data || error);
3131
}
3232

33+
export function useAllCapabilitiesLoaded() {
34+
// It is always true if there is no meta, since request finishes with an error
35+
const metaCapabilitiesLoaded = useMetaCapabilitiesLoaded();
36+
const capabilitiesLoaded = useCapabilitiesLoaded();
37+
38+
return metaCapabilitiesLoaded && capabilitiesLoaded;
39+
}
40+
3341
const useGetFeatureVersion = (feature: Capability) => {
3442
const database = useDatabaseFromQuery();
3543

0 commit comments

Comments
 (0)