From 26e7720822e335cc6c24acb05b5192f2ad166f2d Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Tue, 18 Nov 2025 17:46:43 +0300 Subject: [PATCH 1/2] feat: add "Show create table" sql snippet --- src/containers/Tenant/Query/NewSQL/NewSQL.tsx | 4 ++++ src/containers/Tenant/Query/NewSQL/i18n/en.json | 1 + src/containers/Tenant/i18n/en.json | 1 + src/containers/Tenant/utils/newSQLQueryActions.ts | 2 ++ src/containers/Tenant/utils/schemaActions.tsx | 13 ++++++++++++- src/containers/Tenant/utils/schemaQueryTemplates.ts | 8 ++++++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx index 8331b018e8..0c9f8fee24 100644 --- a/src/containers/Tenant/Query/NewSQL/NewSQL.tsx +++ b/src/containers/Tenant/Query/NewSQL/NewSQL.tsx @@ -79,6 +79,10 @@ export function NewSQL() { text: i18n('action.drop-index'), action: actions.dropTableIndex, }, + { + text: i18n('action.show-create-table'), + action: actions.showCreateTable, + }, ], }, { diff --git a/src/containers/Tenant/Query/NewSQL/i18n/en.json b/src/containers/Tenant/Query/NewSQL/i18n/en.json index e2730d7a3d..36d81f767d 100644 --- a/src/containers/Tenant/Query/NewSQL/i18n/en.json +++ b/src/containers/Tenant/Query/NewSQL/i18n/en.json @@ -36,6 +36,7 @@ "action.alter-transfer": "Alter transfer", "action.drop-transfer": "Drop transfer", "action.create-streaming-query": "Create streaming query", + "action.show-create-table": "Show Create SQL", "action.alter-streaming-query-settings": "Alter query settings", "action.alter-streaming-query-text": "Alter query text", "action.drop-streaming-query": "Drop query" diff --git a/src/containers/Tenant/i18n/en.json b/src/containers/Tenant/i18n/en.json index 46e11c5be9..502e0e7228 100644 --- a/src/containers/Tenant/i18n/en.json +++ b/src/containers/Tenant/i18n/en.json @@ -45,6 +45,7 @@ "actions.manageAutoPartitioning": "Manage auto partitioning...", "actions.addTableIndex": "Add index...", "actions.createCdcStream": "Create changefeed...", + "actions.showCreateTable": "Show Create SQL...", "actions.alterTopic": "Alter topic...", "actions.selectQuery": "Select query...", "actions.upsertQuery": "Upsert query...", diff --git a/src/containers/Tenant/utils/newSQLQueryActions.ts b/src/containers/Tenant/utils/newSQLQueryActions.ts index 61aa045ecf..06e6540b7d 100644 --- a/src/containers/Tenant/utils/newSQLQueryActions.ts +++ b/src/containers/Tenant/utils/newSQLQueryActions.ts @@ -30,6 +30,7 @@ import { grantPrivilegeTemplate, revokePrivilegeTemplate, selectQueryTemplate, + showCreateTableTemplate, updateTableTemplate, upsertQueryTemplate, } from './schemaQueryTemplates'; @@ -73,5 +74,6 @@ export const bindActions = (changeUserInput: (input: string) => void) => { dropGroup: inputQuery(dropGroupTemplate), addTableIndex: inputQuery(addTableIndex), dropTableIndex: inputQuery(dropTableIndex), + showCreateTable: inputQuery(showCreateTableTemplate), }; }; diff --git a/src/containers/Tenant/utils/schemaActions.tsx b/src/containers/Tenant/utils/schemaActions.tsx index 4b63ddf2f7..5992f91646 100644 --- a/src/containers/Tenant/utils/schemaActions.tsx +++ b/src/containers/Tenant/utils/schemaActions.tsx @@ -1,4 +1,4 @@ -import {CirclePlus, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons'; +import {CirclePlus, Code, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons'; import {Flex, Spin} from '@gravity-ui/uikit'; import copy from 'copy-to-clipboard'; import type {NavigationTreeNodeType} from 'ydb-ui-components'; @@ -46,6 +46,7 @@ import { dropViewTemplate, manageAutoPartitioningTemplate, selectQueryTemplate, + showCreateTableTemplate, upsertQueryTemplate, } from './schemaQueryTemplates'; import type {YdbNavigationTreeProps} from './types'; @@ -128,6 +129,7 @@ const bindActions = ( dropTable: inputQuery(dropTableTemplate), manageAutoPartitioning: inputQuery(manageAutoPartitioningTemplate), selectQuery: inputQuery(selectQueryTemplate), + showCreateTable: inputQuery(showCreateTableTemplate), upsertQuery: inputQuery(upsertQueryTemplate), createExternalTable: inputQuery(createExternalTableTemplate), dropExternalTable: inputQuery(dropExternalTableTemplate), @@ -244,6 +246,7 @@ export const getActions = }, ], }; + let DB_SET: ActionsSet = [[copyItem, connectToDBItem], createEntitiesSet]; const DIR_SET: ActionsSet = [[copyItem], createEntitiesSet]; @@ -263,6 +266,12 @@ export const getActions = DIR_SET.splice(1, 0, [createDirectoryItem]); } + const showCreateTableItem = { + text: i18n('actions.showCreateTable'), + action: actions.showCreateTable, + iconStart: , + }; + const ROW_TABLE_SET: ActionsSet = [ [copyItem], [ @@ -281,6 +290,7 @@ export const getActions = {text: i18n('actions.addTableIndex'), action: actions.addTableIndex}, {text: i18n('actions.createCdcStream'), action: actions.createCdcStream}, ], + [showCreateTableItem], ]; const COLUMN_TABLE_SET: ActionsSet = [ [copyItem], @@ -290,6 +300,7 @@ export const getActions = {text: i18n('actions.selectQuery'), action: actions.selectQuery}, {text: i18n('actions.upsertQuery'), action: actions.upsertQuery}, ], + [showCreateTableItem], ]; const TOPIC_SET: ActionsSet = [ diff --git a/src/containers/Tenant/utils/schemaQueryTemplates.ts b/src/containers/Tenant/utils/schemaQueryTemplates.ts index 682d5b3e39..be462bce6a 100644 --- a/src/containers/Tenant/utils/schemaQueryTemplates.ts +++ b/src/containers/Tenant/utils/schemaQueryTemplates.ts @@ -159,6 +159,14 @@ export const selectQueryTemplate = (params?: SchemaQueryParams) => { FROM ${path} ${filters}LIMIT \${5:10};`; }; + +export const showCreateTableTemplate = (params?: SchemaQueryParams) => { + const streamingQueryName = params?.relativePath + ? `\`${normalizeParameter(params.relativePath)}\`` + : '${2:}'; + return `SHOW CREATE TABLE ${streamingQueryName};`; +}; + export const upsertQueryTemplate = (params?: SchemaQueryParams) => { const path = params?.relativePath ? `\`${normalizeParameter(params.relativePath)}\`` From 8fc1b4f3baf87a013fc7556171cb46f26735ff8d Mon Sep 17 00:00:00 2001 From: Elena Makarova Date: Wed, 19 Nov 2025 09:37:07 +0300 Subject: [PATCH 2/2] fix: review --- src/containers/Tenant/utils/schemaQueryTemplates.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/Tenant/utils/schemaQueryTemplates.ts b/src/containers/Tenant/utils/schemaQueryTemplates.ts index be462bce6a..6f80ed51c6 100644 --- a/src/containers/Tenant/utils/schemaQueryTemplates.ts +++ b/src/containers/Tenant/utils/schemaQueryTemplates.ts @@ -161,10 +161,10 @@ ${filters}LIMIT \${5:10};`; }; export const showCreateTableTemplate = (params?: SchemaQueryParams) => { - const streamingQueryName = params?.relativePath + const tablePath = params?.relativePath ? `\`${normalizeParameter(params.relativePath)}\`` : '${2:}'; - return `SHOW CREATE TABLE ${streamingQueryName};`; + return `SHOW CREATE TABLE ${tablePath};`; }; export const upsertQueryTemplate = (params?: SchemaQueryParams) => {