Skip to content

Commit 46220c4

Browse files
authored
fix(SchemaTree): transfer Show Preview to SchemaTree (#505)
1 parent 2e8ab8e commit 46220c4

File tree

5 files changed

+80
-14
lines changed

5 files changed

+80
-14
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"reselect": "4.1.6",
4141
"sass": "1.32.8",
4242
"web-vitals": "1.1.2",
43-
"ydb-ui-components": "^3.2.2"
43+
"ydb-ui-components": "^3.3.1"
4444
},
4545
"scripts": {
4646
"start": "react-app-rewired start",

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

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {useQueryModes} from '../../../../utils/hooks';
99

1010
import {isChildlessPathType, mapPathTypeToNavigationTreeType} from '../../utils/schema';
1111
import {getActions} from '../../utils/schemaActions';
12+
import {getControls} from '../../utils/schemaControls';
1213

1314
interface SchemaTreeProps {
1415
rootPath: string;
@@ -78,6 +79,9 @@ export function SchemaTree(props: SchemaTreeProps) {
7879
setActivePath: handleActivePathUpdate,
7980
setQueryMode,
8081
})}
82+
renderAdditionalNodeElements={getControls(dispatch, {
83+
setActivePath: handleActivePathUpdate,
84+
})}
8185
activePath={currentPath}
8286
onActivePathUpdate={handleActivePathUpdate}
8387
cache={false}

src/containers/Tenant/utils/schemaActions.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {NavigationTreeNodeType, NavigationTreeProps} from 'ydb-ui-component
66
import type {QueryMode} from '../../../types/store/query';
77
import type {SetQueryModeIfAvailable} from '../../../utils/hooks';
88
import {changeUserInput} from '../../../store/reducers/executeQuery';
9-
import {setShowPreview} from '../../../store/reducers/schema/schema';
109
import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
1110
import {TENANT_QUERY_TABS_ID, TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
1211
import createToast from '../../../utils/createToast';
@@ -109,12 +108,6 @@ const bindActions = (
109108
});
110109
}
111110
},
112-
openPreview: () => {
113-
dispatch(setShowPreview(true));
114-
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
115-
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
116-
setActivePath(path);
117-
},
118111
};
119112
};
120113

@@ -125,14 +118,13 @@ export const getActions =
125118
(path: string, type: NavigationTreeNodeType) => {
126119
const actions = bindActions(path, dispatch, additionalEffects);
127120
const copyItem = {text: i18n('actions.copyPath'), action: actions.copyPath};
128-
const openPreview = {text: i18n('actions.openPreview'), action: actions.openPreview};
129121

130122
const DIR_SET: ActionsSet = [
131123
[copyItem],
132124
[{text: i18n('actions.createTable'), action: actions.createTable}],
133125
];
134126
const TABLE_SET: ActionsSet = [
135-
[openPreview, copyItem],
127+
[copyItem],
136128
[
137129
{text: i18n('actions.alterTable'), action: actions.alterTable},
138130
{text: i18n('actions.selectQuery'), action: actions.selectQuery},
@@ -141,7 +133,7 @@ export const getActions =
141133
];
142134

143135
const EXTERNAL_TABLE_SET = [
144-
[openPreview, copyItem],
136+
[copyItem],
145137
[
146138
{
147139
text: i18n('actions.selectQuery'),
@@ -169,6 +161,7 @@ export const getActions =
169161

170162
index_table: JUST_COPY,
171163
topic: JUST_COPY,
164+
stream: JUST_COPY,
172165

173166
index: JUST_COPY,
174167

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {Dispatch} from 'react';
2+
3+
import {NavigationTreeNodeType, NavigationTreeProps} from 'ydb-ui-components';
4+
import {Button} from '@gravity-ui/uikit';
5+
6+
import {setShowPreview} from '../../../store/reducers/schema/schema';
7+
import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
8+
import {TENANT_PAGES_IDS, TENANT_QUERY_TABS_ID} from '../../../store/reducers/tenant/constants';
9+
import {IconWrapper} from '../../../components/Icon';
10+
11+
import i18n from '../i18n';
12+
13+
interface ControlsAdditionalEffects {
14+
setActivePath: (path: string) => void;
15+
}
16+
17+
const bindActions = (
18+
path: string,
19+
dispatch: Dispatch<any>,
20+
additionalEffects: ControlsAdditionalEffects,
21+
) => {
22+
const {setActivePath} = additionalEffects;
23+
24+
return {
25+
openPreview: () => {
26+
dispatch(setShowPreview(true));
27+
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
28+
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
29+
setActivePath(path);
30+
},
31+
};
32+
};
33+
34+
type Controls = ReturnType<Required<NavigationTreeProps>['renderAdditionalNodeElements']>;
35+
36+
export const getControls =
37+
(dispatch: Dispatch<any>, additionalEffects: ControlsAdditionalEffects) =>
38+
(path: string, type: NavigationTreeNodeType) => {
39+
const options = bindActions(path, dispatch, additionalEffects);
40+
const openPreview = (
41+
<Button
42+
view="flat-secondary"
43+
onClick={options.openPreview}
44+
title={i18n('actions.openPreview')}
45+
size="s"
46+
>
47+
<IconWrapper name="tablePreview" />
48+
</Button>
49+
);
50+
51+
const nodeTypeToControls: Record<NavigationTreeNodeType, Controls> = {
52+
database: undefined,
53+
directory: undefined,
54+
55+
table: openPreview,
56+
column_table: openPreview,
57+
58+
index_table: undefined,
59+
topic: undefined,
60+
stream: undefined,
61+
62+
index: undefined,
63+
64+
external_table: openPreview,
65+
external_data_source: undefined,
66+
};
67+
68+
return nodeTypeToControls[type];
69+
};

0 commit comments

Comments
 (0)