Skip to content

Commit 2e3fb59

Browse files
feat: enable cluster events tab (#2710)
1 parent 4474b34 commit 2e3fb59

File tree

6 files changed

+88
-16
lines changed

6 files changed

+88
-16
lines changed

src/containers/Cluster/Cluster.tsx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
AdditionalTenantsProps,
2929
} from '../../types/additionalProps';
3030
import {EFlag} from '../../types/api/enums';
31+
import {uiFactory} from '../../uiFactory/uiFactory';
3132
import {cn} from '../../utils/cn';
3233
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
3334
import {useAppTitle} from '../App/AppTitleContext';
@@ -39,7 +40,13 @@ import {VersionsContainer} from '../Versions/Versions';
3940

4041
import {ClusterOverview} from './ClusterOverview/ClusterOverview';
4142
import type {ClusterTab} from './utils';
42-
import {clusterTabs, clusterTabsIds, getClusterPath, isClusterTab} from './utils';
43+
import {
44+
clusterTabs,
45+
clusterTabsIds,
46+
getClusterPath,
47+
isClusterTab,
48+
useShouldShowEventsTab,
49+
} from './utils';
4350

4451
import './Cluster.scss';
4552

@@ -60,6 +67,7 @@ export function Cluster({
6067
const isClusterDashboardAvailable = useClusterDashboardAvailable();
6168

6269
const shouldShowNetworkTable = useShouldShowClusterNetworkTable();
70+
const shouldShowEventsTab = useShouldShowEventsTab();
6371

6472
const [autoRefreshInterval] = useAutoRefreshInterval();
6573

@@ -99,12 +107,17 @@ export function Cluster({
99107
}, [dispatch]);
100108

101109
const actualClusterTabs = React.useMemo(() => {
102-
if (shouldShowNetworkTable) {
103-
return clusterTabs;
104-
} else {
105-
return clusterTabs.filter((tab) => tab.id !== clusterTabsIds.network);
110+
let tabs = clusterTabs;
111+
112+
if (!shouldShowNetworkTable) {
113+
tabs = tabs.filter((tab) => tab.id !== clusterTabsIds.network);
106114
}
107-
}, [shouldShowNetworkTable]);
115+
if (!shouldShowEventsTab) {
116+
tabs = tabs.filter((tab) => tab.id !== clusterTabsIds.events);
117+
}
118+
119+
return tabs;
120+
}, [shouldShowEventsTab, shouldShowNetworkTable]);
108121

109122
const getClusterTitle = () => {
110123
if (infoLoading) {
@@ -240,6 +253,17 @@ export function Cluster({
240253
>
241254
<VersionsContainer cluster={cluster} loading={infoLoading} />
242255
</Route>
256+
{shouldShowEventsTab && (
257+
<Route
258+
path={
259+
getLocationObjectFromHref(getClusterPath(clusterTabsIds.events))
260+
.pathname
261+
}
262+
>
263+
{uiFactory.renderEvents?.()}
264+
</Route>
265+
)}
266+
243267
<Route
244268
render={() => (
245269
<Redirect to={getLocationObjectFromHref(getClusterPath(activeTabId))} />
@@ -257,13 +281,19 @@ function useClusterTab() {
257281
const defaultTab = useTypedSelector((state) => state.cluster.defaultClusterTab);
258282

259283
const shouldShowNetworkTable = useShouldShowClusterNetworkTable();
284+
const shouldShowEventsTab = useShouldShowEventsTab();
260285

261286
const match = useRouteMatch<{activeTab: string}>(routes.cluster);
262287

263288
const {activeTab: activeTabFromParams} = match?.params || {};
264289
let activeTab: ClusterTab;
265290

266-
if (!shouldShowNetworkTable && activeTabFromParams === clusterTabsIds.network) {
291+
const shouldSwitchFromNetworkToDefault =
292+
!shouldShowNetworkTable && activeTabFromParams === clusterTabsIds.network;
293+
const shouldSwitchFromEventsToDefault =
294+
!shouldShowEventsTab && activeTabFromParams === clusterTabsIds.events;
295+
296+
if (shouldSwitchFromNetworkToDefault || shouldSwitchFromEventsToDefault) {
267297
activeTab = INITIAL_DEFAULT_CLUSTER_TAB;
268298
} else if (isClusterTab(activeTabFromParams)) {
269299
activeTab = activeTabFromParams;

src/containers/Cluster/i18n/en.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@
4040
"context_cpu-description": "CPU load is calculated as the cumulative usage across all actor system pools on all nodes in the cluster",
4141
"context_memory-description": "Memory usage is the total memory consumed by all nodes in the cluster",
4242
"context_storage-description": "Storage usage is a cumulative usage of raw disk space of all media types",
43-
"context_network-description": "Network usage is the average outgoing bandwidth usage across all nodes in the cluster"
43+
"context_network-description": "Network usage is the average outgoing bandwidth usage across all nodes in the cluster",
44+
45+
"tab_databases": "Databases",
46+
"tab_nodes": "Nodes",
47+
"tab_storage": "Storage",
48+
"tab_network": "Network",
49+
"tab_versions": "Versions",
50+
"tab_tablets": "Tablets",
51+
"tab_events": "Events"
4452
}

src/containers/Cluster/utils.tsx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type {CreateHrefOptions} from '../../routes';
22
import routes, {createHref} from '../../routes';
3+
import {useClusterEventsAvailable} from '../../store/reducers/capabilities/hooks';
34
import type {ClusterGroupsStats} from '../../store/reducers/cluster/types';
45
import type {ValueOf} from '../../types/common';
6+
import {uiFactory} from '../../uiFactory/uiFactory';
7+
8+
import i18n from './i18n';
59

610
export const clusterTabsIds = {
711
tenants: 'tenants',
@@ -10,36 +14,55 @@ export const clusterTabsIds = {
1014
network: 'network',
1115
versions: 'versions',
1216
tablets: 'tablets',
17+
events: 'events',
1318
} as const;
1419

1520
export type ClusterTab = ValueOf<typeof clusterTabsIds>;
1621

1722
const tenants = {
1823
id: clusterTabsIds.tenants,
19-
title: 'Databases',
24+
get title() {
25+
return i18n('tab_databases');
26+
},
2027
};
2128
const nodes = {
2229
id: clusterTabsIds.nodes,
23-
title: 'Nodes',
30+
get title() {
31+
return i18n('tab_nodes');
32+
},
2433
};
2534
const storage = {
2635
id: clusterTabsIds.storage,
27-
title: 'Storage',
36+
get title() {
37+
return i18n('tab_storage');
38+
},
2839
};
2940
const network = {
3041
id: clusterTabsIds.network,
31-
title: 'Network',
42+
get title() {
43+
return i18n('tab_network');
44+
},
3245
};
3346
const versions = {
3447
id: clusterTabsIds.versions,
35-
title: 'Versions',
48+
get title() {
49+
return i18n('tab_versions');
50+
},
3651
};
3752
const tablets = {
3853
id: clusterTabsIds.tablets,
39-
title: 'Tablets',
54+
get title() {
55+
return i18n('tab_tablets');
56+
},
57+
};
58+
const events = {
59+
id: clusterTabsIds.events,
60+
get title() {
61+
return i18n('tab_events');
62+
},
4063
};
4164

42-
export const clusterTabs = [tenants, nodes, storage, network, tablets, versions];
65+
export const clusterTabs = [tenants, nodes, storage, network, tablets, versions, events];
4366

4467
export function isClusterTab(tab: any): tab is ClusterTab {
4568
return Object.values(clusterTabsIds).includes(tab);
@@ -58,3 +81,7 @@ export const getTotalStorageGroupsUsed = (groupStats: ClusterGroupsStats) => {
5881
return acc;
5982
}, 0);
6083
};
84+
85+
export function useShouldShowEventsTab() {
86+
return useClusterEventsAvailable() && uiFactory.renderEvents;
87+
}

src/store/reducers/capabilities/hooks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,7 @@ export const useEditClusterFeatureAvailable = () => {
157157
export const useDeleteClusterFeatureAvailable = () => {
158158
return useGetMetaFeatureVersion('/meta/delete_cluster') >= 1;
159159
};
160+
161+
export const useClusterEventsAvailable = () => {
162+
return useGetMetaFeatureVersion('/meta/events') >= 1;
163+
};

src/types/api/capabilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ export type MetaCapability =
4949
| '/meta/stop_database'
5050
| '/meta/create_cluster'
5151
| '/meta/update_cluster'
52-
| '/meta/delete_cluster';
52+
| '/meta/delete_cluster'
53+
| '/meta/events';

src/uiFactory/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface UIFactory<H extends string = CommonIssueType> {
3737
scrollContainerRef: React.RefObject<HTMLDivElement>;
3838
}) => React.ReactNode;
3939

40+
renderEvents?: () => React.ReactNode;
41+
4042
healthcheck: {
4143
getHealthckechViewTitles: GetHealthcheckViewTitles<H>;
4244
getHealthcheckViewsOrder: GetHealthcheckViewsOrder<H>;

0 commit comments

Comments
 (0)