-
Notifications
You must be signed in to change notification settings - Fork 594
/
TopologyPage.tsx
173 lines (160 loc) · 5.14 KB
/
TopologyPage.tsx
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
171
172
173
import * as React from 'react';
import { Helmet } from 'react-helmet';
import { matchPath, match as RMatch, Link, Redirect } from 'react-router-dom';
import { Tooltip, Popover, Button } from '@patternfly/react-core';
import { ListIcon, TopologyIcon, QuestionCircleIcon } from '@patternfly/react-icons';
import {
StatusBox,
Firehose,
HintBlock,
AsyncComponent,
removeQueryArgument,
} from '@console/internal/components/utils';
import EmptyState from '../EmptyState';
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import ProjectsExistWrapper from '../ProjectsExistWrapper';
import ProjectListPage from '../projects/ProjectListPage';
import ConnectedTopologyDataController, { RenderProps } from './TopologyDataController';
import Topology from './Topology';
import TopologyShortcuts from './TopologyShortcuts';
import { LAST_TOPOLOGY_VIEW_LOCAL_STORAGE_KEY } from './components/const';
import './TopologyPage.scss';
import { TOPOLOGY_SEARCH_FILTER_KEY } from './filters';
export interface TopologyPageProps {
match: RMatch<{
name?: string;
}>;
}
const setTopologyActiveView = (id: string) => {
localStorage.setItem(LAST_TOPOLOGY_VIEW_LOCAL_STORAGE_KEY, id);
};
const getTopologyActiveView = () => {
return localStorage.getItem(LAST_TOPOLOGY_VIEW_LOCAL_STORAGE_KEY);
};
const EmptyMsg = () => (
<EmptyState
title="Topology"
hintBlock={
<HintBlock title="No workloads found">
<p>
To add content to your project, create an application, component or service using one of
these options.
</p>
</HintBlock>
}
/>
);
export function renderTopology({ loaded, loadError, data, namespace }: RenderProps) {
return (
<StatusBox
data={data ? data.graph.nodes : null}
label="Topology"
loaded={loaded}
loadError={loadError}
EmptyMsg={EmptyMsg}
>
<div className="odc-topology">
<Topology data={data} namespace={namespace} />
</div>
</StatusBox>
);
}
export const TopologyPage: React.FC<TopologyPageProps> = ({ match }) => {
const namespace = match.params.name;
const showListView = !!matchPath(match.path, {
path: '*/list',
exact: true,
});
const showGraphView = !!matchPath(match.path, {
path: '*/graph',
exact: true,
});
const handleNamespaceChange = (ns: string) => {
if (ns !== namespace) {
removeQueryArgument(TOPOLOGY_SEARCH_FILTER_KEY);
}
};
React.useEffect(() => setTopologyActiveView(showListView && !showGraphView ? 'list' : 'graph'), [
showListView,
showGraphView,
]);
if (!showGraphView && !showListView) {
return (
<Redirect
to={`/topology/${namespace ? `ns/${namespace}` : 'all-namespaces'}/${
getTopologyActiveView() === 'list' ? 'list' : 'graph'
}`}
/>
);
}
return (
<>
<Helmet>
<title>Topology</title>
</Helmet>
<NamespacedPage
variant={showListView ? NamespacedPageVariants.light : NamespacedPageVariants.default}
hideApplications={showListView}
onNamespaceChange={handleNamespaceChange}
toolbar={
<>
{!showListView && namespace && (
<Popover
aria-label="Shortcuts"
bodyContent={TopologyShortcuts}
position="left"
maxWidth="100vw"
>
<Button
type="button"
variant="link"
className="odc-topology__shortcuts-button"
icon={<QuestionCircleIcon />}
data-test-id="topology-view-shortcuts"
>
View shortcuts
</Button>
</Popover>
)}
<Tooltip position="left" content={showListView ? 'Topology View' : 'List View'}>
<Link
className="pf-c-button pf-m-plain"
to={`/topology/${namespace ? `ns/${namespace}` : 'all-namespaces'}${
showListView ? '/graph' : '/list'
}`}
>
{showListView ? <TopologyIcon size="md" /> : <ListIcon size="md" />}
</Link>
</Tooltip>
</>
}
>
<Firehose resources={[{ kind: 'Project', prop: 'projects', isList: true }]}>
<ProjectsExistWrapper title="Topology">
{namespace ? (
showListView ? (
<AsyncComponent
mock={false}
match={match}
title=""
loader={() =>
import(
'@console/internal/components/overview' /* webpackChunkName: "topology-overview" */
).then((m) => m.Overview)
}
/>
) : (
<ConnectedTopologyDataController match={match} render={renderTopology} />
)
) : (
<ProjectListPage title="Topology">
Select a project to view the topology
</ProjectListPage>
)}
</ProjectsExistWrapper>
</Firehose>
</NamespacedPage>
</>
);
};
export default TopologyPage;