Skip to content

Commit c1bc562

Browse files
committed
fix(Tenant): don't use HistoryAPI and redux-location-state together
1 parent 0604190 commit c1bc562

File tree

6 files changed

+55
-47
lines changed

6 files changed

+55
-47
lines changed

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import qs from 'qs';
33
import cn from 'bem-cn-lite';
44
import {Link} from 'react-router-dom';
55
import {useDispatch, useSelector} from 'react-redux';
6-
import {useHistory, useLocation} from 'react-router';
6+
import {useLocation} from 'react-router';
77

88
import {Switch, Tabs} from '@yandex-cloud/uikit';
99

@@ -34,8 +34,10 @@ import {TenantGeneralTabsIds, TenantTabsGroups} from '../TenantPages';
3434
import {GeneralPagesIds, DATABASE_PAGES, TABLE_PAGES, DIR_PAGES} from './DiagnosticsPages';
3535
//@ts-ignore
3636
import {enableAutorefresh, disableAutorefresh} from '../../../store/reducers/schema';
37+
import {setTopLevelTab, setDiagnosticsTab} from '../../../store/reducers/tenant';
3738

3839
import './Diagnostics.scss';
40+
3941
interface DiagnosticsProps {
4042
type: string;
4143
additionalTenantInfo?: any;
@@ -51,16 +53,17 @@ function Diagnostics(props: DiagnosticsProps) {
5153
currentSchema: currentItem = {},
5254
autorefresh,
5355
} = useSelector((state: any) => state.schema);
56+
const {
57+
diagnosticsTab = GeneralPagesIds.overview,
58+
} = useSelector((state: any) => state.tenant);
5459

5560
const location = useLocation();
5661

57-
const history = useHistory();
58-
5962
const queryParams = qs.parse(location.search, {
6063
ignoreQueryPrefix: true,
6164
});
6265

63-
const {name: tenantName, generalTab = GeneralPagesIds.overview} = queryParams;
66+
const {name: tenantName} = queryParams;
6467

6568
const isDatabase = currentSchemaPath === tenantName;
6669

@@ -79,22 +82,17 @@ function Diagnostics(props: DiagnosticsProps) {
7982
}, [props.type]);
8083

8184
const forwardToDiagnosticTab = (tab: GeneralPagesIds) => {
82-
history.push(
83-
createHref(routes.tenant, undefined, {
84-
...queryParams,
85-
[TenantTabsGroups.generalTab]: tab,
86-
}),
87-
);
85+
dispatch(setDiagnosticsTab(tab));
8886
};
8987
const activeTab = useMemo(() => {
90-
if (pages.find((el) => el.id === generalTab)) {
91-
return generalTab;
88+
if (pages.find((el) => el.id === diagnosticsTab)) {
89+
return diagnosticsTab;
9290
} else {
9391
const newPage = pages[0].id;
9492
forwardToDiagnosticTab(newPage);
9593
return newPage;
9694
}
97-
}, [pages, generalTab]);
95+
}, [pages, diagnosticsTab]);
9896

9997
const onAutorefreshToggle = (value: boolean) => {
10098
if (value) {
@@ -105,20 +103,15 @@ function Diagnostics(props: DiagnosticsProps) {
105103
};
106104

107105
const forwardToGeneralTab = (tab: TenantGeneralTabsIds) => {
108-
history.push(
109-
createHref(routes.tenant, undefined, {
110-
...queryParams,
111-
[TenantTabsGroups.general]: tab,
112-
}),
113-
);
106+
dispatch(setTopLevelTab(tab));
114107
};
115108

116109
const renderTabContent = () => {
117110
const {type} = props;
118111

119112
const tenantNameString = tenantName as string;
120113

121-
switch (generalTab) {
114+
switch (diagnosticsTab) {
122115
case GeneralPagesIds.overview: {
123116
return (
124117
<DetailedOverview

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
PaneVisibilityToggleButtons,
3737
} from '../utils/paneVisibilityToggleHelpers';
3838
import {setShowPreview} from '../../../store/reducers/schema';
39+
import {setTopLevelTab} from '../../../store/reducers/tenant';
3940

4041
import './ObjectSummary.scss';
4142

@@ -222,12 +223,7 @@ function ObjectSummary(props: ObjectSummaryProps) {
222223

223224
const onOpenPreview = () => {
224225
dispatch(setShowPreview(true));
225-
history.push(
226-
createHref(routes.tenant, undefined, {
227-
...queryParams,
228-
[TenantTabsGroups.general]: TenantGeneralTabsIds.query,
229-
}),
230-
);
226+
dispatch(setTopLevelTab(TenantGeneralTabsIds.query));
231227
};
232228

233229
const renderCommonInfoControls = () => {

src/containers/Tenant/Schema/SchemaTree/SchemaTree.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {useDispatch} from 'react-redux';
2-
import {useHistory} from 'react-router';
32

43
import {NavigationTree} from 'ydb-ui-components';
54

@@ -26,7 +25,6 @@ export function SchemaTree(props: SchemaTreeProps) {
2625
} = props;
2726

2827
const dispatch = useDispatch();
29-
const history = useHistory();
3028

3129
const fetchPath = (path: string) => window.api.getSchema(
3230
{path},
@@ -55,7 +53,7 @@ export function SchemaTree(props: SchemaTreeProps) {
5553
collapsed: false,
5654
}}
5755
fetchPath={fetchPath}
58-
getActions={getActions(dispatch, history, handleActivePathUpdate)}
56+
getActions={getActions(dispatch, handleActivePathUpdate)}
5957
activePath={currentPath}
6058
onActivePathUpdate={handleActivePathUpdate}
6159
cache={false}

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import qs from 'qs';
21
import {Dispatch} from 'react';
3-
import {History} from 'history';
42
import type {NavigationTreeNodeType} from 'ydb-ui-components';
53

6-
import routes, {createHref} from '../../../routes';
74
import {changeUserInput} from '../../../store/reducers/executeQuery';
85
import {setShowPreview} from '../../../store/reducers/schema';
6+
import {setTopLevelTab} from '../../../store/reducers/tenant';
97
import createToast from '../../../utils/createToast';
10-
import {TenantGeneralTabsIds, TenantTabsGroups} from '../TenantPages';
8+
import {TenantGeneralTabsIds} from '../TenantPages';
119

1210
const createTableTemplate = (path: string) => {
1311
return `CREATE TABLE \`${path}/my_table\`
@@ -36,29 +34,16 @@ VALUES ( );`;
3634

3735
export const getActions = (
3836
dispatch: Dispatch<any>,
39-
history: History<unknown>,
4037
setActivePath: (path: string) => void,
4138
) =>
4239
(path: string, type: NavigationTreeNodeType) => {
43-
const queryParams = qs.parse(location.search, {
44-
ignoreQueryPrefix: true,
45-
});
46-
4740
const switchTabToQuery = () => {
48-
history.push(
49-
createHref(routes.tenant, undefined, {
50-
...queryParams,
51-
[TenantTabsGroups.general]: TenantGeneralTabsIds.query,
52-
}),
53-
);
41+
dispatch(setTopLevelTab(TenantGeneralTabsIds.query));
5442
};
5543

5644
const onCreateTableClick = () => {
5745
dispatch(changeUserInput({input: createTableTemplate(path)}));
5846
switchTabToQuery();
59-
// here and in the other handlers this should be called after switching tab:
60-
// redux-location-state catches the history.push event from the tab switching
61-
// before active path updates in url, preventing its update at all
6247
setActivePath(path);
6348
};
6449

src/store/reducers/tenant.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import '../../services/api';
33
import _ from 'lodash';
44

55
const FETCH_TENANT = createRequestActionTypes('tenant', 'FETCH_TENANT');
6+
const SET_TOP_LEVEL_TAB = 'tenant/SET_TOP_LEVEL_TAB';
7+
const SET_DIAGNOSTICS_TAB = 'tenant/SET_DIAGNOSTICS_TAB';
68

79
const tenantReducer = (state = {loading: false, tenant: {}}, action) => {
810
switch (action.type) {
@@ -41,6 +43,20 @@ const tenantReducer = (state = {loading: false, tenant: {}}, action) => {
4143
};
4244
}
4345

46+
case SET_TOP_LEVEL_TAB: {
47+
return {
48+
...state,
49+
topLevelTab: action.data,
50+
};
51+
}
52+
53+
case SET_DIAGNOSTICS_TAB: {
54+
return {
55+
...state,
56+
diagnosticsTab: action.data,
57+
};
58+
}
59+
4460
default:
4561
return state;
4662
}
@@ -73,4 +89,18 @@ export const getTenantInfo = ({path}) => {
7389
});
7490
};
7591

92+
export function setTopLevelTab(tab) {
93+
return {
94+
type: SET_TOP_LEVEL_TAB,
95+
data: tab,
96+
};
97+
}
98+
99+
export function setDiagnosticsTab(tab) {
100+
return {
101+
type: SET_DIAGNOSTICS_TAB,
102+
data: tab,
103+
};
104+
}
105+
76106
export default tenantReducer;

src/store/state-url-mapping.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ const paramSetup = {
4242
stateKey: 'tablets.typeFilter',
4343
type: 'array',
4444
},
45+
general: {
46+
stateKey: 'tenant.topLevelTab',
47+
},
48+
generalTab: {
49+
stateKey: 'tenant.diagnosticsTab',
50+
},
4551
},
4652
};
4753

0 commit comments

Comments
 (0)