Skip to content

Commit b50db5f

Browse files
fix(ObjectSummary): fix issue on object change with active schema tab (#482)
1 parent ecdec2f commit b50db5f

File tree

7 files changed

+72
-44
lines changed

7 files changed

+72
-44
lines changed

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {ReactNode, useEffect, useReducer} from 'react';
22
import {useDispatch} from 'react-redux';
3-
import {useHistory, useLocation} from 'react-router';
3+
import {useLocation} from 'react-router';
44
import {Link} from 'react-router-dom';
55
import qs from 'qs';
66
import cn from 'bem-cn-lite';
@@ -31,19 +31,18 @@ import {
3131
DEFAULT_SIZE_TENANT_SUMMARY_KEY,
3232
} from '../../../utils/constants';
3333
import {setShowPreview} from '../../../store/reducers/schema/schema';
34-
import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
35-
import {TENANT_PAGES_IDS, TENANT_QUERY_TABS_ID} from '../../../store/reducers/tenant/constants';
34+
import {setQueryTab, setSummaryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
35+
import {
36+
TENANT_PAGES_IDS,
37+
TENANT_QUERY_TABS_ID,
38+
TENANT_SUMMARY_TABS_IDS,
39+
} from '../../../store/reducers/tenant/constants';
3640

3741
import {SchemaTree} from '../Schema/SchemaTree/SchemaTree';
3842
import {SchemaViewer} from '../Schema/SchemaViewer/SchemaViewer';
3943
import {Acl} from '../Acl/Acl';
4044

41-
import {
42-
TenantInfoTabsIds,
43-
TenantTabsGroups,
44-
TENANT_INFO_TABS,
45-
TENANT_SCHEMA_TAB,
46-
} from '../TenantPages';
45+
import {TenantTabsGroups, TENANT_INFO_TABS, TENANT_SCHEMA_TAB} from '../TenantPages';
4746
import {
4847
PaneVisibilityActionTypes,
4948
paneVisibilityToggleReducerCreator,
@@ -115,16 +114,17 @@ export function ObjectSummary({
115114
currentSchema: currentItem = {},
116115
loading: loadingSchema,
117116
} = useTypedSelector((state) => state.schema);
117+
const {summaryTab = TENANT_SUMMARY_TABS_IDS.overview} = useTypedSelector(
118+
(state) => state.tenant,
119+
);
118120

119121
const location = useLocation();
120122

121-
const history = useHistory();
122-
123123
const queryParams = qs.parse(location.search, {
124124
ignoreQueryPrefix: true,
125125
});
126126

127-
const {name: tenantName, info: infoTab} = queryParams;
127+
const {name: tenantName} = queryParams;
128128

129129
const pathData = tenantName ? data[tenantName.toString()]?.PathDescription?.Self : undefined;
130130
const currentObjectData = currentSchemaPath ? data[currentSchemaPath] : undefined;
@@ -143,13 +143,10 @@ export function ObjectSummary({
143143
useEffect(() => {
144144
const isTable = isTableType(type);
145145

146-
if (type && !isTable && !TENANT_INFO_TABS.find((el) => el.id === infoTab)) {
147-
history.push({
148-
pathname: location.pathname,
149-
search: qs.stringify({...queryParams, info: TenantInfoTabsIds.overview}),
150-
});
146+
if (type && !isTable && !TENANT_INFO_TABS.find((el) => el.id === summaryTab)) {
147+
dispatch(setSummaryTab(TENANT_SUMMARY_TABS_IDS.overview));
151148
}
152-
}, [type, history, infoTab, location, queryParams]);
149+
}, [dispatch, type, summaryTab]);
153150

154151
const renderTabs = () => {
155152
const isTable = isTableType(type);
@@ -160,12 +157,12 @@ export function ObjectSummary({
160157
<Tabs
161158
size="l"
162159
items={tabsItems}
163-
activeTab={infoTab as string}
160+
activeTab={summaryTab}
164161
wrapTo={({id}, node) => {
165162
const path = createHref(routes.tenant, undefined, {
166163
...queryParams,
167164
name: tenantName as string,
168-
[TenantTabsGroups.info]: id,
165+
[TenantTabsGroups.summaryTab]: id,
169166
});
170167
return (
171168
<Link to={path} key={id} className={b('tab')}>
@@ -218,11 +215,11 @@ export function ObjectSummary({
218215
};
219216

220217
const renderTabContent = () => {
221-
switch (infoTab) {
222-
case TenantInfoTabsIds.acl: {
218+
switch (summaryTab) {
219+
case TENANT_SUMMARY_TABS_IDS.acl: {
223220
return <Acl />;
224221
}
225-
case TenantInfoTabsIds.schema: {
222+
case TENANT_SUMMARY_TABS_IDS.schema: {
226223
return loadingSchema ? (
227224
renderLoader()
228225
) : (

src/containers/Tenant/TenantPages.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
import routes, {createHref} from '../../routes';
2+
import {TENANT_SUMMARY_TABS_IDS} from '../../store/reducers/tenant/constants';
23

3-
export enum TenantInfoTabsIds {
4-
overview = 'overview',
5-
acl = 'acl',
6-
schema = 'schema',
7-
}
8-
9-
export enum TenantTabsGroups {
10-
info = 'info',
11-
queryTab = 'queryTab',
12-
diagnosticsTab = 'diagnosticsTab',
13-
}
4+
export const TenantTabsGroups = {
5+
summaryTab: 'summaryTab',
6+
queryTab: 'queryTab',
7+
diagnosticsTab: 'diagnosticsTab',
8+
} as const;
149

1510
export const TENANT_INFO_TABS = [
1611
{
17-
id: TenantInfoTabsIds.overview,
12+
id: TENANT_SUMMARY_TABS_IDS.overview,
1813
title: 'Overview',
1914
},
2015
{
21-
id: TenantInfoTabsIds.acl,
16+
id: TENANT_SUMMARY_TABS_IDS.acl,
2217
title: 'ACL',
2318
},
2419
];
2520

2621
export const TENANT_SCHEMA_TAB = [
2722
{
28-
id: TenantInfoTabsIds.schema,
23+
id: TENANT_SUMMARY_TABS_IDS.schema,
2924
title: 'Schema',
3025
},
3126
];

src/containers/Tenants/Tenants.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {DEFAULT_TABLE_SETTINGS} from '../../utils/constants';
3131
import {useAutofetcher, useTypedSelector} from '../../utils/hooks';
3232
import {clusterName} from '../../store';
3333

34-
import {TenantTabsGroups, TENANT_INFO_TABS, getTenantPath} from '../Tenant/TenantPages';
34+
import {getTenantPath} from '../Tenant/TenantPages';
3535

3636
import './Tenants.scss';
3737

@@ -80,8 +80,6 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {
8080
};
8181

8282
const renderTable = () => {
83-
const initialTenantInfoTab = TENANT_INFO_TABS[0].id;
84-
8583
const getTenantBackend = (tenant: PreparedTenant) => {
8684
const backend = tenant.MonitoringEndpoint ?? tenant.backend;
8785
return additionalTenantsProps?.prepareTenantBackend?.(backend);
@@ -106,7 +104,6 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {
106104
path={getTenantPath({
107105
name: row.Name,
108106
backend,
109-
[TenantTabsGroups.info]: initialTenantInfoTab,
110107
})}
111108
/>
112109
{additionalTenantsProps?.getMonitoringLink?.(row.Name, row.Type)}

src/store/reducers/tenant/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ export const TENANT_DIAGNOSTICS_TABS_IDS = {
2525
consumers: 'consumers',
2626
partitions: 'partitions',
2727
} as const;
28+
29+
export const TENANT_SUMMARY_TABS_IDS = {
30+
overview: 'overview',
31+
acl: 'acl',
32+
schema: 'schema',
33+
} as const;

src/store/reducers/tenant/tenant.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
TenantPage,
88
TenantQueryTab,
99
TenantState,
10+
TenantSummaryTab,
1011
} from './types';
1112

1213
import '../../../services/api';
@@ -17,6 +18,7 @@ export const FETCH_TENANT = createRequestActionTypes('tenant', 'FETCH_TENANT');
1718
const SET_TOP_LEVEL_TAB = 'tenant/SET_TOP_LEVEL_TAB';
1819
const SET_QUERY_TAB = 'tenant/SET_QUERY_TAB';
1920
const SET_DIAGNOSTICS_TAB = 'tenant/SET_DIAGNOSTICS_TAB';
21+
const SET_SUMMARY_TAB = 'tenant/SET_SUMMARY_TAB';
2022
const CLEAR_TENANT = 'tenant/CLEAR_TENANT';
2123

2224
const initialState = {loading: false, wasLoaded: false};
@@ -75,6 +77,12 @@ const tenantReducer: Reducer<TenantState, TenantAction> = (state = initialState,
7577
diagnosticsTab: action.data,
7678
};
7779
}
80+
case SET_SUMMARY_TAB: {
81+
return {
82+
...state,
83+
summaryTab: action.data,
84+
};
85+
}
7886

7987
default:
8088
return state;
@@ -116,4 +124,11 @@ export function setDiagnosticsTab(tab: TenantDiagnosticsTab) {
116124
} as const;
117125
}
118126

127+
export function setSummaryTab(tab: TenantSummaryTab) {
128+
return {
129+
type: SET_SUMMARY_TAB,
130+
data: tab,
131+
} as const;
132+
}
133+
119134
export default tenantReducer;

src/store/reducers/tenant/types.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,34 @@ import type {TTenant} from '../../../types/api/tenant';
33
import type {ValueOf} from '../../../types/common';
44
import type {ApiRequestAction} from '../../utils';
55

6-
import {TENANT_QUERY_TABS_ID, TENANT_DIAGNOSTICS_TABS_IDS, TENANT_PAGES_IDS} from './constants';
7-
import {FETCH_TENANT, clearTenant, setDiagnosticsTab, setQueryTab, setTenantPage} from './tenant';
6+
import {
7+
TENANT_QUERY_TABS_ID,
8+
TENANT_DIAGNOSTICS_TABS_IDS,
9+
TENANT_PAGES_IDS,
10+
TENANT_SUMMARY_TABS_IDS,
11+
} from './constants';
12+
import {
13+
FETCH_TENANT,
14+
clearTenant,
15+
setDiagnosticsTab,
16+
setQueryTab,
17+
setSummaryTab,
18+
setTenantPage,
19+
} from './tenant';
820

921
export type TenantPage = ValueOf<typeof TENANT_PAGES_IDS>;
1022

1123
export type TenantQueryTab = ValueOf<typeof TENANT_QUERY_TABS_ID>;
1224
export type TenantDiagnosticsTab = ValueOf<typeof TENANT_DIAGNOSTICS_TABS_IDS>;
25+
export type TenantSummaryTab = ValueOf<typeof TENANT_SUMMARY_TABS_IDS>;
1326

1427
export interface TenantState {
1528
loading: boolean;
1629
wasLoaded: boolean;
1730
tenantPage?: TenantPage;
1831
queryTab?: TenantQueryTab;
1932
diagnosticsTab?: TenantDiagnosticsTab;
33+
summaryTab?: TenantSummaryTab;
2034
tenant?: TTenant;
2135
error?: IResponseError;
2236
}
@@ -26,4 +40,5 @@ export type TenantAction =
2640
| ReturnType<typeof clearTenant>
2741
| ReturnType<typeof setTenantPage>
2842
| ReturnType<typeof setQueryTab>
29-
| ReturnType<typeof setDiagnosticsTab>;
43+
| ReturnType<typeof setDiagnosticsTab>
44+
| ReturnType<typeof setSummaryTab>;

src/store/state-url-mapping.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const paramSetup = {
5151
diagnosticsTab: {
5252
stateKey: 'tenant.diagnosticsTab',
5353
},
54+
summaryTab: {
55+
stateKey: 'tenant.summaryTab',
56+
},
5457
shardsMode: {
5558
stateKey: 'shardsWorkload.filters.mode',
5659
},

0 commit comments

Comments
 (0)