-
Notifications
You must be signed in to change notification settings - Fork 64
/
Routes.js
170 lines (156 loc) · 4.85 KB
/
Routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React, { Suspense, lazy, useEffect, useState } from 'react';
import { Navigate, useRoutes } from 'react-router-dom';
import RenderWrapper from './Utilities/Wrapper';
import useFeatureFlag from './Utilities/useFeatureFlag';
import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
import ErrorState from '@redhat-cloud-services/frontend-components/ErrorState';
import {
inventoryHasEdgeSystems,
inventoryHasBootcImages,
} from './Utilities/edge';
import { inventoryHasConventionalSystems } from './Utilities/conventional';
import Fallback from './components/SpinnerFallback';
import useWorkspaceFeatureFlag from './Utilities/hooks/useWorkspaceFeatureFlag';
import Redirect from './Utilities/Redirect';
import { AccountStatContext } from './Contexts';
const InventoryOrEdgeGroupDetailsView = lazy(() =>
import('./routes/InventoryOrEdgeGroupDetailsComponent')
);
const InventoryOrEdgeView = lazy(() =>
import('./routes/InventoryOrEdgeComponent')
);
const InventoryTable = lazy(() => import('./routes/InventoryPage'));
const InventoryDetail = lazy(() => import('./routes/InventoryDetail'));
const InventoryHostStaleness = lazy(() =>
import('./routes/InventoryHostStaleness')
);
const EdgeInventoryUpdate = lazy(() => import('./routes/SystemUpdate'));
export const routes = {
table: '/',
detail: '/:inventoryId',
detailWithModal: '/:inventoryId/:modalId',
groups: '/groups',
groupDetail: '/groups/:groupId',
update: '/:inventoryId/update',
edgeInventory: '/manage-edge-inventory',
staleness: '/staleness-and-deletion',
workspace: '/workspaces',
workspaceDetail: '/workspaces/:groupId',
};
export const Routes = () => {
const [hasConventionalSystems, setHasConventionalSystems] = useState(true);
const [hasEdgeDevices, setHasEdgeDevices] = useState(true);
const [hasBootcImages, setHasBootcImages] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const edgeParityInventoryListEnabled = useFeatureFlag(
'edgeParity.inventory-list'
);
const isBifrostEnabled = useFeatureFlag('hbi.ui.bifrost');
const isWorkspaceEnabled = useWorkspaceFeatureFlag();
useEffect(() => {
// zero state check
(async () => {
try {
const hasConventionalSystems = await inventoryHasConventionalSystems();
setHasConventionalSystems(hasConventionalSystems);
if (edgeParityInventoryListEnabled) {
const hasEdgeSystems = await inventoryHasEdgeSystems();
setHasEdgeDevices(hasEdgeSystems);
}
if (isBifrostEnabled) {
const hasBootc = await inventoryHasBootcImages();
setHasBootcImages(hasBootc);
}
setIsLoading(false);
} catch (error) {
console.error(error);
if (error.response.status === 403) {
setIsLoading(false);
}
}
})();
}, []);
let element = useRoutes([
{
path: '/',
element: <RenderWrapper cmp={InventoryTable} />,
},
{ path: '/:inventoryId', element: <InventoryDetail /> },
{ path: '/:inventoryId/:modalId', element: <InventoryDetail /> },
{
path: '/groups',
element: isWorkspaceEnabled ? (
<Redirect to="/insights/inventory/workspaces" replace="replace" />
) : (
<InventoryOrEdgeView />
),
},
{
path: '/groups/:groupId',
element: isWorkspaceEnabled ? (
<Redirect
to="/insights/inventory/workspaces/:groupId"
replace="replace"
/>
) : (
<InventoryOrEdgeGroupDetailsView />
),
},
{
path: '/workspaces',
element: <InventoryOrEdgeView />,
},
{
path: '/workspaces/:groupId',
element: <InventoryOrEdgeGroupDetailsView />,
},
{
path: '/:inventoryId/update',
element: <EdgeInventoryUpdate />,
},
{
path: '/manage-edge-inventory',
element: (
<RenderWrapper cmp={InventoryTable} isRbacEnabled isImmutableTabOpen />
),
},
{
path: '*',
element: <Navigate to="/" replace />,
},
{
path: '/staleness-and-deletion',
element: <InventoryHostStaleness />,
},
]);
//bootc images are part of conventional systems,
//zero-state is not influenced by them
const hasSystems = edgeParityInventoryListEnabled
? hasEdgeDevices || hasConventionalSystems
: hasConventionalSystems;
if (isLoading) {
return <Fallback />;
}
return !hasSystems ? (
<Suspense fallback={<Fallback />}>
<AsyncComponent
appId={'inventory_zero_state'}
appName="dashboard"
module="./AppZeroState"
scope="dashboard"
ErrorComponent={<ErrorState />}
app="Inventory"
/>
</Suspense>
) : (
<AccountStatContext.Provider
value={{
hasConventionalSystems,
hasEdgeDevices,
hasBootcImages,
}}
>
{element}
</AccountStatContext.Provider>
);
};