Skip to content

Commit 3aec811

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

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/containers/App/Content.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import routes, {getClusterPath} from '../../routes';
1414
import type {RootState} from '../../store';
1515
import {authenticationApi} from '../../store/reducers/authentication/authentication';
1616
import {
17-
useCapabilitiesQuery,
17+
useAllCapablitiesStatus,
1818
useClusterWithoutAuthInUI,
1919
useMetaCapabilitiesLoaded,
2020
useMetaCapabilitiesQuery,
@@ -235,11 +235,7 @@ function GetNodesList() {
235235
}
236236

237237
function GetCapabilities({children}: {children: React.ReactNode}) {
238-
const {data, error} = useCapabilitiesQuery();
239-
240-
useMetaCapabilitiesQuery();
241-
// It is always true if there is no meta, since request finishes with an error
242-
const metaCapabilitiesLoaded = useMetaCapabilitiesLoaded();
238+
const {error, loading} = useAllCapablitiesStatus();
243239

244240
//do nothing, authentication is in progress upon redirect
245241
if (isRedirectToAuth(error)) {
@@ -250,10 +246,8 @@ function GetCapabilities({children}: {children: React.ReactNode}) {
250246
return <AccessDenied />;
251247
}
252248

253-
const capabilitiesLoaded = Boolean(data || error);
254-
255249
return (
256-
<LoaderWrapper loading={!capabilitiesLoaded || !metaCapabilitiesLoaded} size="l">
250+
<LoaderWrapper loading={loading} size="l">
257251
{children}
258252
</LoaderWrapper>
259253
);

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+
useAllCapablitiesStatus,
2223
useDatabasesAvailable,
2324
useDeleteDatabaseFeatureAvailable,
2425
useEditDatabaseFeatureAvailable,
@@ -50,6 +51,7 @@ import './Header.scss';
5051
const b = cn('header');
5152

5253
function Header() {
54+
const {loading} = useAllCapablitiesStatus();
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 (loading) {
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ export function useCapabilitiesLoaded() {
3030
return Boolean(data || error);
3131
}
3232

33+
export function useAllCapablitiesStatus() {
34+
const {data, error} = useCapabilitiesQuery();
35+
36+
useMetaCapabilitiesQuery();
37+
// It is always true if there is no meta, since request finishes with an error
38+
const metaCapabilitiesLoaded = useMetaCapabilitiesLoaded();
39+
40+
const capabilitiesLoaded = Boolean(data || error);
41+
42+
return {error, loading: !capabilitiesLoaded || !metaCapabilitiesLoaded};
43+
}
44+
3345
const useGetFeatureVersion = (feature: Capability) => {
3446
const database = useDatabaseFromQuery();
3547

0 commit comments

Comments
 (0)