@@ -3,12 +3,13 @@ import type {NavigationTreeNodeType, NavigationTreeProps} from 'ydb-ui-component
33
44import type { AppDispatch } from '../../../store' ;
55import { changeUserInput } from '../../../store/reducers/executeQuery' ;
6+ import type { GetTableSchemaDataParams } from '../../../store/reducers/tableSchemaData' ;
67import { TENANT_PAGES_IDS , TENANT_QUERY_TABS_ID } from '../../../store/reducers/tenant/constants' ;
78import { setQueryTab , setTenantPage } from '../../../store/reducers/tenant/tenant' ;
89import type { QueryMode , QuerySettings } from '../../../types/store/query' ;
910import createToast from '../../../utils/createToast' ;
10- import { getTableDataPromise } from '../../../utils/hooks' ;
1111import { transformPath } from '../ObjectSummary/transformPath' ;
12+ import type { SchemaData } from '../Schema/SchemaViewer/types' ;
1213import i18n from '../i18n' ;
1314
1415import { nodeTableTypeToPathType } from './schema' ;
@@ -37,11 +38,9 @@ interface ActionsAdditionalEffects {
3738 updateQueryExecutionSettings : ( settings ?: Partial < QuerySettings > ) => void ;
3839 setActivePath : ( path : string ) => void ;
3940 showCreateDirectoryDialog ?: ( path : string ) => void ;
40- }
41-
42- interface AdditionalInputQueryOptions {
43- mode ?: QueryMode ;
44- withTableData ?: boolean ;
41+ getTableSchemaDataPromise ?: (
42+ params : GetTableSchemaDataParams ,
43+ ) => Promise < SchemaData [ ] | undefined > ;
4544}
4645
4746interface BindActionParams {
@@ -56,19 +55,28 @@ const bindActions = (
5655 dispatch : AppDispatch ,
5756 additionalEffects : ActionsAdditionalEffects ,
5857) => {
59- const { setActivePath, updateQueryExecutionSettings, showCreateDirectoryDialog} =
60- additionalEffects ;
61-
62- const inputQuery = ( tmpl : TemplateFn , options ?: AdditionalInputQueryOptions ) => ( ) => {
63- if ( options ?. mode ) {
64- updateQueryExecutionSettings ( { queryMode : options . mode } ) ;
58+ const {
59+ setActivePath,
60+ updateQueryExecutionSettings,
61+ showCreateDirectoryDialog,
62+ getTableSchemaDataPromise,
63+ } = additionalEffects ;
64+
65+ const inputQuery = ( tmpl : TemplateFn , mode ?: QueryMode ) => ( ) => {
66+ if ( mode ) {
67+ updateQueryExecutionSettings ( { queryMode : mode } ) ;
6568 }
6669
6770 const pathType = nodeTableTypeToPathType [ params . type ] ;
71+ const withTableData = [ selectQueryTemplate , upsertQueryTemplate ] . includes ( tmpl ) ;
6872
6973 const userInputDataPromise =
70- options ?. withTableData && pathType
71- ? getTableDataPromise ( params . path , params . tenantName , pathType , dispatch )
74+ withTableData && pathType && getTableSchemaDataPromise
75+ ? getTableSchemaDataPromise ( {
76+ path : params . path ,
77+ tenantName : params . tenantName ,
78+ type : pathType ,
79+ } )
7280 : Promise . resolve ( undefined ) ;
7381
7482 userInputDataPromise . then ( ( tableData ) => {
@@ -86,24 +94,24 @@ const bindActions = (
8694 showCreateDirectoryDialog ( params . path ) ;
8795 }
8896 : undefined ,
89- createTable : inputQuery ( createTableTemplate , { mode : 'script' } ) ,
90- createColumnTable : inputQuery ( createColumnTableTemplate , { mode : 'script' } ) ,
91- createAsyncReplication : inputQuery ( createAsyncReplicationTemplate , { mode : 'script' } ) ,
92- alterAsyncReplication : inputQuery ( alterAsyncReplicationTemplate , { mode : 'script' } ) ,
93- dropAsyncReplication : inputQuery ( dropAsyncReplicationTemplate , { mode : 'script' } ) ,
94- alterTable : inputQuery ( alterTableTemplate , { mode : 'script' } ) ,
95- selectQuery : inputQuery ( selectQueryTemplate , { withTableData : true } ) ,
96- upsertQuery : inputQuery ( upsertQueryTemplate , { withTableData : true } ) ,
97- createExternalTable : inputQuery ( createExternalTableTemplate , { mode : 'script' } ) ,
98- dropExternalTable : inputQuery ( dropExternalTableTemplate , { mode : 'script' } ) ,
99- selectQueryFromExternalTable : inputQuery ( selectQueryTemplate , { mode : 'query' } ) ,
100- createTopic : inputQuery ( createTopicTemplate , { mode : 'script' } ) ,
101- alterTopic : inputQuery ( alterTopicTemplate , { mode : 'script' } ) ,
102- dropTopic : inputQuery ( dropTopicTemplate , { mode : 'script' } ) ,
103- createView : inputQuery ( createViewTemplate , { mode : 'script' } ) ,
104- dropView : inputQuery ( dropViewTemplate , { mode : 'script' } ) ,
105- dropIndex : inputQuery ( dropTableIndex , { mode : 'script' } ) ,
106- addTableIndex : inputQuery ( addTableIndex , { mode : 'script' } ) ,
97+ createTable : inputQuery ( createTableTemplate , 'script' ) ,
98+ createColumnTable : inputQuery ( createColumnTableTemplate , 'script' ) ,
99+ createAsyncReplication : inputQuery ( createAsyncReplicationTemplate , 'script' ) ,
100+ alterAsyncReplication : inputQuery ( alterAsyncReplicationTemplate , 'script' ) ,
101+ dropAsyncReplication : inputQuery ( dropAsyncReplicationTemplate , 'script' ) ,
102+ alterTable : inputQuery ( alterTableTemplate , 'script' ) ,
103+ selectQuery : inputQuery ( selectQueryTemplate ) ,
104+ upsertQuery : inputQuery ( upsertQueryTemplate ) ,
105+ createExternalTable : inputQuery ( createExternalTableTemplate , 'script' ) ,
106+ dropExternalTable : inputQuery ( dropExternalTableTemplate , 'script' ) ,
107+ selectQueryFromExternalTable : inputQuery ( selectQueryTemplate , 'query' ) ,
108+ createTopic : inputQuery ( createTopicTemplate , 'script' ) ,
109+ alterTopic : inputQuery ( alterTopicTemplate , 'script' ) ,
110+ dropTopic : inputQuery ( dropTopicTemplate , 'script' ) ,
111+ createView : inputQuery ( createViewTemplate , 'script' ) ,
112+ dropView : inputQuery ( dropViewTemplate , 'script' ) ,
113+ dropIndex : inputQuery ( dropTableIndex , 'script' ) ,
114+ addTableIndex : inputQuery ( addTableIndex , 'script' ) ,
107115 copyPath : ( ) => {
108116 try {
109117 copy ( params . relativePath ) ;
0 commit comments