Skip to content

Commit b3cab2e

Browse files
feat: enable cluster events tab
1 parent a4b737b commit b3cab2e

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
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 = clusterTabs.filter((tab) => tab.id !== clusterTabsIds.network);
106114
}
107-
}, [shouldShowNetworkTable]);
115+
if (!shouldShowEventsTab) {
116+
tabs = clusterTabs.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/utils.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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';
57

68
export const clusterTabsIds = {
79
tenants: 'tenants',
@@ -10,6 +12,7 @@ export const clusterTabsIds = {
1012
network: 'network',
1113
versions: 'versions',
1214
tablets: 'tablets',
15+
events: 'events',
1316
} as const;
1417

1518
export type ClusterTab = ValueOf<typeof clusterTabsIds>;
@@ -38,8 +41,12 @@ const tablets = {
3841
id: clusterTabsIds.tablets,
3942
title: 'Tablets',
4043
};
44+
const events = {
45+
id: clusterTabsIds.events,
46+
title: 'Events',
47+
};
4148

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

4451
export function isClusterTab(tab: any): tab is ClusterTab {
4552
return Object.values(clusterTabsIds).includes(tab);
@@ -58,3 +65,7 @@ export const getTotalStorageGroupsUsed = (groupStats: ClusterGroupsStats) => {
5865
return acc;
5966
}, 0);
6067
};
68+
69+
export function useShouldShowEventsTab() {
70+
return useClusterEventsAvailable() && uiFactory.renderEvents;
71+
}

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)