Skip to content

Commit 5e503fc

Browse files
feat: add streaming query snippets (#3076)
1 parent 0ae80b4 commit 5e503fc

File tree

9 files changed

+218
-4
lines changed

9 files changed

+218
-4
lines changed

src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '../../../../store/reducers/capabilities/hooks';
1313
import {selectIsDirty, selectUserInput} from '../../../../store/reducers/query/query';
1414
import {schemaApi} from '../../../../store/reducers/schema/schema';
15+
import {streamingQueriesApi} from '../../../../store/reducers/streamingQuery/streamingQuery';
1516
import {tableSchemaDataApi} from '../../../../store/reducers/tableSchemaData';
1617
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema';
1718
import {uiFactory} from '../../../../uiFactory/uiFactory';
@@ -22,6 +23,7 @@ import {getSchemaControls} from '../../utils/controls';
2223
import {
2324
isChildlessPathType,
2425
mapPathTypeToNavigationTreeType,
26+
nodeStreamingQueryTypeToPathType,
2527
nodeTableTypeToPathType,
2628
} from '../../utils/schema';
2729
import {getActions} from '../../utils/schemaActions';
@@ -49,6 +51,10 @@ export function SchemaTree(props: SchemaTreeProps) {
4951
getTableSchemaDataQuery,
5052
{currentData: actionsSchemaData, isFetching: isActionsDataFetching},
5153
] = tableSchemaDataApi.useLazyGetTableSchemaDataQuery();
54+
const [
55+
getStreamingQueryInfo,
56+
{currentData: streamingSysData, isFetching: isStreamingInfoFetching},
57+
] = streamingQueriesApi.useLazyGetStreamingQueryInfoQuery();
5258

5359
const isTopicPreviewAvailable = useTopicDataAvailable();
5460

@@ -146,6 +152,8 @@ export function SchemaTree(props: SchemaTreeProps) {
146152
schemaData: actionsSchemaData,
147153
isSchemaDataLoading: isActionsDataFetching,
148154
hasMonitoring: typeof uiFactory.renderMonitoring === 'function',
155+
streamingQueryData: streamingSysData,
156+
isStreamingQueryTextLoading: isStreamingInfoFetching,
149157
},
150158
databaseFullPath,
151159
database,
@@ -157,9 +165,11 @@ export function SchemaTree(props: SchemaTreeProps) {
157165
input,
158166
isActionsDataFetching,
159167
isDirty,
168+
isStreamingInfoFetching,
160169
onActivePathUpdate,
161170
databaseFullPath,
162171
database,
172+
streamingSysData,
163173
]);
164174

165175
return (
@@ -188,6 +198,11 @@ export function SchemaTree(props: SchemaTreeProps) {
188198
getTableSchemaDataQuery({path, database, type: pathType, databaseFullPath});
189199
}
190200

201+
const streamingPathType = nodeStreamingQueryTypeToPathType[type];
202+
if (isOpen && streamingPathType) {
203+
getStreamingQueryInfo({database, path}, true); // preferCacheValue = true
204+
}
205+
191206
return [];
192207
}}
193208
renderAdditionalNodeElements={getSchemaControls(

src/containers/Tenant/Query/NewSQL/NewSQL.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import React from 'react';
33
import {ChevronDown, Persons} from '@gravity-ui/icons';
44
import type {DropdownMenuItem} from '@gravity-ui/uikit';
55
import {Button, DropdownMenu} from '@gravity-ui/uikit';
6-
import {AsyncReplicationIcon, TableIcon, TopicIcon, TransferIcon} from 'ydb-ui-components';
6+
import {
7+
AsyncReplicationIcon,
8+
StreamingQueryIcon,
9+
TableIcon,
10+
TopicIcon,
11+
TransferIcon,
12+
} from 'ydb-ui-components';
713

814
import {useChangeInputWithConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation';
915
import {insertSnippetToEditor} from '../../../../utils/monaco/insertSnippet';
@@ -93,6 +99,28 @@ export function NewSQL() {
9399
},
94100
],
95101
},
102+
{
103+
text: i18n('menu.streaming-query'),
104+
iconStart: <StreamingQueryIcon />,
105+
items: [
106+
{
107+
text: i18n('action.create-streaming-query'),
108+
action: actions.createStreamingQuery,
109+
},
110+
{
111+
text: i18n('action.alter-streaming-query-settings'),
112+
action: actions.alterStreamingQuerySettings,
113+
},
114+
{
115+
text: i18n('action.alter-streaming-query-text'),
116+
action: actions.alterStreamingQueryText,
117+
},
118+
{
119+
text: i18n('action.drop-streaming-query'),
120+
action: actions.dropStreamingQuery,
121+
},
122+
],
123+
},
96124
{
97125
text: i18n('menu.replication'),
98126
iconStart: <AsyncReplicationIcon />,

src/containers/Tenant/Query/NewSQL/i18n/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"action.drop-external-table": "Drop external table",
1515
"menu.tables": "Tables",
1616
"menu.topics": "Topics",
17+
"menu.streaming-query": "Streaming query",
1718
"menu.capture": "Change data capture",
1819
"menu.replication": "Async replication",
1920
"menu.transfer": "Transfer",
@@ -33,5 +34,9 @@
3334
"action.alter-async-replication": "Alter async replication",
3435
"action.drop-async-replication": "Drop async replication",
3536
"action.alter-transfer": "Alter transfer",
36-
"action.drop-transfer": "Drop transfer"
37+
"action.drop-transfer": "Drop transfer",
38+
"action.create-streaming-query": "Create streaming query",
39+
"action.alter-streaming-query-settings": "Alter query settings",
40+
"action.alter-streaming-query-text": "Alter query text",
41+
"action.drop-streaming-query": "Drop query"
3742
}

src/containers/Tenant/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"actions.createAsyncReplication": "Create async replication...",
3737
"actions.createTransfer": "Create transfer...",
3838
"actions.createView": "Create view...",
39+
"actions.createStreamingQuery": "Create streaming query...",
3940
"actions.dropTable": "Drop table...",
4041
"actions.dropTopic": "Drop topic...",
4142
"actions.dropView": "Drop view...",
@@ -51,6 +52,9 @@
5152
"actions.alterTransfer": "Alter transfer...",
5253
"actions.dropReplication": "Drop async replicaton...",
5354
"actions.dropTransfer": "Drop transfer...",
55+
"actions.dropStreamingQuery": "Drop query...",
56+
"actions.alterStreamingQuerySettings": "Alter query settings...",
57+
"actions.alterStreamingQueryText": "Alter query text...",
5458
"actions.createDirectory": "Create directory",
5559
"schema.tree.dialog.placeholder": "Relative path",
5660
"schema.tree.dialog.invalid": "Invalid path",

src/containers/Tenant/utils/newSQLQueryActions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
addTableIndex,
33
alterAsyncReplicationTemplate,
4+
alterStreamingQuerySettingsTemplate,
5+
alterStreamingQueryText,
46
alterTableTemplate,
57
alterTopicTemplate,
68
alterTransferTemplate,
@@ -9,6 +11,7 @@ import {
911
createColumnTableTemplate,
1012
createExternalTableTemplate,
1113
createGroupTemplate,
14+
createStreamingQueryTemplate,
1215
createTableTemplate,
1316
createTopicTemplate,
1417
createTransferTemplate,
@@ -18,6 +21,7 @@ import {
1821
dropAsyncReplicationTemplate,
1922
dropExternalTableTemplate,
2023
dropGroupTemplate,
24+
dropStreamingQueryTemplate,
2125
dropTableIndex,
2226
dropTableTemplate,
2327
dropTopicTemplate,
@@ -39,6 +43,7 @@ export const bindActions = (changeUserInput: (input: string) => void) => {
3943
createRowTable: inputQuery(createTableTemplate),
4044
createColumnTable: inputQuery(createColumnTableTemplate),
4145
createAsyncReplication: inputQuery(createAsyncReplicationTemplate),
46+
createStreamingQuery: inputQuery(createStreamingQueryTemplate),
4247
alterAsyncReplication: inputQuery(alterAsyncReplicationTemplate),
4348
dropAsyncReplication: inputQuery(dropAsyncReplicationTemplate),
4449
createTransfer: inputQuery(createTransferTemplate),
@@ -56,6 +61,9 @@ export const bindActions = (changeUserInput: (input: string) => void) => {
5661
dropTable: inputQuery(dropTableTemplate),
5762
deleteRows: inputQuery(deleteRowsTemplate),
5863
updateTable: inputQuery(updateTableTemplate),
64+
alterStreamingQueryText: inputQuery(alterStreamingQueryText),
65+
alterStreamingQuerySettings: inputQuery(alterStreamingQuerySettingsTemplate),
66+
dropStreamingQuery: inputQuery(dropStreamingQueryTemplate),
5967
createUser: inputQuery(createUserTemplate),
6068
createGroup: inputQuery(createGroupTemplate),
6169
createCdcStream: inputQuery(createCdcStreamTemplate),

src/containers/Tenant/utils/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export const nodeTableTypeToPathType: Partial<Record<NavigationTreeNodeType, EPa
5757
view: EPathType.EPathTypeView,
5858
};
5959

60+
export const nodeStreamingQueryTypeToPathType: Partial<Record<NavigationTreeNodeType, EPathType>> =
61+
{
62+
streaming_query: EPathType.EPathTypeStreamingQuery,
63+
};
64+
6065
export const mapPathTypeToNavigationTreeType = (
6166
type: EPathType = EPathType.EPathTypeDir,
6267
subType?: EPathSubType,

src/containers/Tenant/utils/schemaActions.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TENANT_QUERY_TABS_ID,
1212
} from '../../../store/reducers/tenant/constants';
1313
import {setDiagnosticsTab, setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
14+
import type {IQueryResult} from '../../../types/store/query';
1415
import createToast from '../../../utils/createToast';
1516
import {insertSnippetToEditor} from '../../../utils/monaco/insertSnippet';
1617
import {transformPath} from '../ObjectSummary/transformPath';
@@ -21,19 +22,23 @@ import type {TemplateFn} from './schemaQueryTemplates';
2122
import {
2223
addTableIndex,
2324
alterAsyncReplicationTemplate,
25+
alterStreamingQuerySettingsTemplate,
26+
alterStreamingQueryText,
2427
alterTableTemplate,
2528
alterTopicTemplate,
2629
alterTransferTemplate,
2730
createAsyncReplicationTemplate,
2831
createCdcStreamTemplate,
2932
createColumnTableTemplate,
3033
createExternalTableTemplate,
34+
createStreamingQueryTemplate,
3135
createTableTemplate,
3236
createTopicTemplate,
3337
createTransferTemplate,
3438
createViewTemplate,
3539
dropAsyncReplicationTemplate,
3640
dropExternalTableTemplate,
41+
dropStreamingQueryTemplate,
3742
dropTableIndex,
3843
dropTableTemplate,
3944
dropTopicTemplate,
@@ -53,6 +58,8 @@ interface ActionsAdditionalParams {
5358
schemaData?: SchemaData[];
5459
isSchemaDataLoading?: boolean;
5560
hasMonitoring?: boolean;
61+
streamingQueryData?: IQueryResult;
62+
isStreamingQueryTextLoading?: boolean;
5663
}
5764

5865
interface BindActionParams {
@@ -74,6 +81,7 @@ const bindActions = (
7481
getConfirmation,
7582
getConnectToDBDialog,
7683
schemaData,
84+
streamingQueryData,
7785
} = additionalEffects;
7886

7987
const inputQuery = (tmpl: TemplateFn) => () => {
@@ -82,7 +90,7 @@ const bindActions = (
8290
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
8391
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
8492
setActivePath(params.path);
85-
insertSnippetToEditor(tmpl({...params, schemaData}));
93+
insertSnippetToEditor(tmpl({...params, schemaData, streamingQueryData}));
8694
};
8795
if (getConfirmation) {
8896
const confirmedPromise = getConfirmation();
@@ -129,6 +137,10 @@ const bindActions = (
129137
dropTopic: inputQuery(dropTopicTemplate),
130138
createView: inputQuery(createViewTemplate),
131139
dropView: inputQuery(dropViewTemplate),
140+
createStreamingQuery: inputQuery(createStreamingQueryTemplate),
141+
alterStreamingQuerySettings: inputQuery(alterStreamingQuerySettingsTemplate),
142+
alterStreamingQueryText: inputQuery(alterStreamingQueryText),
143+
dropStreamingQuery: inputQuery(dropStreamingQueryTemplate),
132144
dropIndex: inputQuery(dropTableIndex),
133145
addTableIndex: inputQuery(addTableIndex),
134146
createCdcStream: inputQuery(createCdcStreamTemplate),
@@ -219,6 +231,7 @@ export const getActions =
219231
},
220232
{text: i18n('actions.createTopic'), action: actions.createTopic},
221233
{text: i18n('actions.createView'), action: actions.createView},
234+
{text: i18n('actions.createStreamingQuery'), action: actions.createStreamingQuery},
222235
];
223236

224237
const alterTableGroupItem = {
@@ -334,6 +347,25 @@ export const getActions =
334347
[copyItem, {text: i18n('actions.dropIndex'), action: actions.dropIndex}],
335348
];
336349

350+
const STREAMING_QUERY_SET: ActionsSet = [
351+
[copyItem],
352+
[
353+
{
354+
text: i18n('actions.alterStreamingQuerySettings'),
355+
action: actions.alterStreamingQuerySettings,
356+
},
357+
getActionWithLoader({
358+
text: i18n('actions.alterStreamingQueryText'),
359+
action: actions.alterStreamingQueryText,
360+
isLoading: additionalEffects.isStreamingQueryTextLoading,
361+
}),
362+
{
363+
text: i18n('actions.dropStreamingQuery'),
364+
action: actions.dropStreamingQuery,
365+
},
366+
],
367+
];
368+
337369
const JUST_COPY: ActionsSet = [copyItem];
338370

339371
// verbose mapping to guarantee a correct actions set for new node types
@@ -362,7 +394,7 @@ export const getActions =
362394

363395
view: VIEW_SET,
364396

365-
streaming_query: JUST_COPY,
397+
streaming_query: STREAMING_QUERY_SET,
366398
};
367399

368400
return nodeTypeToActions[type];

0 commit comments

Comments
 (0)