Skip to content

Commit 960e97f

Browse files
authored
feat: move query templates to a hierarchical menu at query editor (#1327)
1 parent 12010dd commit 960e97f

File tree

9 files changed

+509
-2
lines changed

9 files changed

+509
-2
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import {ChevronDown} from '@gravity-ui/icons';
2+
import {Button, DropdownMenu} from '@gravity-ui/uikit';
3+
4+
import {useTypedDispatch} from '../../../../utils/hooks';
5+
import {bindActions} from '../../utils/newSQLQueryActions';
6+
7+
import i18n from './i18n';
8+
9+
export function NewSQL() {
10+
const dispatch = useTypedDispatch();
11+
const actions = bindActions(dispatch);
12+
13+
const items = [
14+
{
15+
text: i18n('menu.tables'),
16+
items: [
17+
{
18+
text: i18n('action.create-row-table'),
19+
action: actions.createRowTable,
20+
},
21+
{
22+
text: i18n('action.create-column-table'),
23+
action: actions.createColumnTable,
24+
},
25+
{
26+
text: i18n('action.create-external-table'),
27+
action: actions.createExternalTable,
28+
},
29+
{
30+
text: i18n('action.upsert-to-table'),
31+
action: actions.upsertQuery,
32+
},
33+
{
34+
text: i18n('action.update-table'),
35+
action: actions.updateTable,
36+
},
37+
{
38+
text: i18n('action.alter-table'),
39+
action: actions.alterTable,
40+
},
41+
{
42+
text: i18n('action.select-rows'),
43+
action: actions.selectQuery,
44+
},
45+
{
46+
text: i18n('action.select-from-external-table'),
47+
action: actions.selectQueryFromExternalTable,
48+
},
49+
{
50+
text: i18n('action.delete-rows'),
51+
action: actions.deleteRows,
52+
},
53+
{
54+
text: i18n('action.drop-table'),
55+
action: actions.dropTable,
56+
},
57+
{
58+
text: i18n('action.drop-external-table'),
59+
action: actions.dropExternalTable,
60+
},
61+
],
62+
},
63+
{
64+
text: i18n('menu.topics'),
65+
items: [
66+
{
67+
text: i18n('action.create-topic'),
68+
action: actions.createTopic,
69+
},
70+
{
71+
text: i18n('action.alter-topic'),
72+
action: actions.alterTopic,
73+
},
74+
{
75+
text: i18n('action.drop-topic'),
76+
action: actions.dropTopic,
77+
},
78+
],
79+
},
80+
{
81+
text: i18n('menu.replication'),
82+
items: [
83+
{
84+
text: i18n('action.create-async-replication'),
85+
action: actions.createAsyncReplication,
86+
},
87+
{
88+
text: i18n('action.alter-async-replication'),
89+
action: actions.alterAsyncReplication,
90+
},
91+
{
92+
text: i18n('action.drop-async-replication'),
93+
action: actions.dropAsyncReplication,
94+
},
95+
],
96+
},
97+
{
98+
text: i18n('menu.capture'),
99+
items: [
100+
{
101+
text: i18n('action.create-cdc-stream'),
102+
action: actions.createCdcStream,
103+
},
104+
],
105+
},
106+
{
107+
text: i18n('menu.users'),
108+
items: [
109+
{
110+
text: i18n('action.create-user'),
111+
action: actions.createUser,
112+
},
113+
{
114+
text: i18n('action.create-group'),
115+
action: actions.createGroup,
116+
},
117+
{
118+
text: i18n('action.drop-user'),
119+
action: actions.dropUser,
120+
},
121+
{
122+
text: i18n('action.drop-group'),
123+
action: actions.dropGroup,
124+
},
125+
{
126+
text: i18n('action.grant-privilege'),
127+
action: actions.grantPrivilege,
128+
},
129+
{
130+
text: i18n('action.revoke-privilege'),
131+
action: actions.revokePrivilege,
132+
},
133+
],
134+
},
135+
];
136+
137+
return (
138+
<DropdownMenu
139+
items={items}
140+
renderSwitcher={(props) => (
141+
<Button {...props}>
142+
{i18n('button.new-sql')}
143+
<Button.Icon>
144+
<ChevronDown />
145+
</Button.Icon>
146+
</Button>
147+
)}
148+
popupProps={{placement: 'top'}}
149+
/>
150+
);
151+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"button.new-sql": "New SQL",
3+
"action.create-row-table": "Create row table",
4+
"action.create-column-table": "Create column table",
5+
"action.create-external-table": "Create external table",
6+
"action.upsert-to-table": "Upsert into table",
7+
"action.update-table": "Update table",
8+
"action.alter-table": "Alter table",
9+
"action.select-rows": "Select from a table",
10+
"action.select-from-external-table": "Select from external table",
11+
"action.delete-rows": "Delete rows",
12+
"action.drop-table": "Drop table",
13+
"action.drop-external-table": "Drop external table",
14+
"menu.tables": "Tables",
15+
"menu.topics": "Topics",
16+
"menu.capture": "Change data capture",
17+
"menu.replication": "Async replication",
18+
"menu.users": "Users",
19+
"action.create-topic": "Create Topic",
20+
"action.drop-topic": "Drop Topic",
21+
"action.alter-topic": "Alter Topic",
22+
"action.create-cdc-stream": "Create CDC Stream",
23+
"action.create-async-replication": "Create async replication",
24+
"action.create-user": "Create user",
25+
"action.create-group": "Create group",
26+
"action.drop-user": "Drop user",
27+
"action.drop-group": "Drop group",
28+
"action.grant-privilege": "Grant privilege",
29+
"action.revoke-privilege": "Revoke privilege",
30+
"action.alter-async-replication": "Alter async replication",
31+
"action.drop-async-replication": "Drop async replication"
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {registerKeysets} from '../../../../../utils/i18n';
2+
3+
import en from './en.json';
4+
5+
const COMPONENT = 'ydb-new-sql';
6+
7+
export default registerKeysets(COMPONENT, {en});

src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
min-height: 40px;
99
padding: 5px 0px;
1010

11+
&__right,
1112
&__left {
1213
display: flex;
1314
gap: 12px;

src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import QuerySettingsDescription from '../../../../components/QuerySettingsDescri
66
import type {QueryAction} from '../../../../types/store/query';
77
import {cn} from '../../../../utils/cn';
88
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
9+
import {NewSQL} from '../NewSQL/NewSQL';
910
import {SaveQuery} from '../SaveQuery/SaveQuery';
1011
import i18n from '../i18n';
1112

@@ -107,7 +108,10 @@ export const QueryEditorControls = ({
107108
</Button>
108109
<SettingsButton onClick={onSettingsButtonClick} runIsLoading={isLoading} />
109110
</div>
110-
<SaveQuery isSaveButtonDisabled={disabled} />
111+
<div className={b('right')}>
112+
<NewSQL />
113+
<SaveQuery isSaveButtonDisabled={disabled} />
114+
</div>
111115
</div>
112116
);
113117
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {changeUserInput} from '../../../store/reducers/executeQuery';
2+
3+
import {
4+
alterAsyncReplicationTemplate,
5+
alterTableTemplate,
6+
alterTopicTemplate,
7+
createAsyncReplicationTemplate,
8+
createCdcStreamTemplate,
9+
createColumnTableTemplate,
10+
createExternalTableTemplate,
11+
createGroupTemplate,
12+
createTableTemplate,
13+
createTopicTemplate,
14+
createUserTemplate,
15+
createViewTemplate,
16+
deleteRowsTemplate,
17+
dropAsyncReplicationTemplate,
18+
dropExternalTableTemplate,
19+
dropGroupTemplate,
20+
dropTableTemplate,
21+
dropTopicTemplate,
22+
dropUserTemplate,
23+
grantPrivilegeTemplate,
24+
revokePrivilegeTemplate,
25+
selectQueryTemplate,
26+
updateTableTemplate,
27+
upsertQueryTemplate,
28+
} from './newSQLQueryTemplates';
29+
30+
export const bindActions = (dispatch: React.Dispatch<any>) => {
31+
const inputQuery = (query: () => string) => () => {
32+
dispatch(changeUserInput({input: query()}));
33+
};
34+
35+
return {
36+
createRowTable: inputQuery(createTableTemplate),
37+
createColumnTable: inputQuery(createColumnTableTemplate),
38+
createAsyncReplication: inputQuery(createAsyncReplicationTemplate),
39+
alterAsyncReplication: inputQuery(alterAsyncReplicationTemplate),
40+
dropAsyncReplication: inputQuery(dropAsyncReplicationTemplate),
41+
alterTable: inputQuery(alterTableTemplate),
42+
selectQuery: inputQuery(selectQueryTemplate),
43+
upsertQuery: inputQuery(upsertQueryTemplate),
44+
createExternalTable: inputQuery(createExternalTableTemplate),
45+
dropExternalTable: inputQuery(dropExternalTableTemplate),
46+
selectQueryFromExternalTable: inputQuery(selectQueryTemplate),
47+
createTopic: inputQuery(createTopicTemplate),
48+
alterTopic: inputQuery(alterTopicTemplate),
49+
dropTopic: inputQuery(dropTopicTemplate),
50+
createView: inputQuery(createViewTemplate),
51+
dropTable: inputQuery(dropTableTemplate),
52+
deleteRows: inputQuery(deleteRowsTemplate),
53+
updateTable: inputQuery(updateTableTemplate),
54+
createUser: inputQuery(createUserTemplate),
55+
createGroup: inputQuery(createGroupTemplate),
56+
createCdcStream: inputQuery(createCdcStreamTemplate),
57+
grantPrivilege: inputQuery(grantPrivilegeTemplate),
58+
revokePrivilege: inputQuery(revokePrivilegeTemplate),
59+
dropUser: inputQuery(dropUserTemplate),
60+
dropGroup: inputQuery(dropGroupTemplate),
61+
};
62+
};

0 commit comments

Comments
 (0)