@@ -117,10 +117,6 @@ export class MetabaseController extends AppController<MetabaseAppState> {
117117 const allSnippetsDict = await getSnippets ( ) as MetabaseStateSnippetsDict ;
118118 const allTemplateTags = getAllTemplateTagsInQuery ( sql , allSnippetsDict )
119119 const state = ( await this . app . getState ( ) ) as MetabaseAppStateSQLEditor ;
120- const userApproved = await RPCs . getUserConfirmation ( { content : sql , contentTitle : "Update SQL query?" , oldContent : state . sqlQuery } ) ;
121- if ( ! userApproved ) {
122- throw new Error ( "Action (and subsequent plan) cancelled!" ) ;
123- }
124120 if ( state . sqlEditorState == "closed" ) {
125121 await this . toggleSQLEditor ( "open" ) ;
126122 }
@@ -169,15 +165,11 @@ export class MetabaseController extends AppController<MetabaseAppState> {
169165 const actionContent : BlankMessageContent = {
170166 type : "BLANK" ,
171167 } ;
172- // sql = processSQLWithCtesOrModels(sql, ctes);
173- // const metabaseState = this.app as App<MetabaseAppState>;
174- // const allModels = metabaseState.useStore().getState().toolContext?.dbInfo?.models || [];
175- // use allModels for this replacement
176- // sql = replaceLLMFriendlyIdentifiersInSqlWithModels(sql, allModels)
177168 const state = ( await this . app . getState ( ) ) as MetabaseAppStateSQLEditor ;
178- const userApproved = await RPCs . getUserConfirmation ( { content : sql , contentTitle : "Update SQL query with parameters ?" , oldContent : state . sqlQuery } ) ;
169+ const { userApproved, userFeedback } = await RPCs . getUserConfirmation ( { content : sql , contentTitle : "Approve SQL Query ?" , oldContent : state . currentCard ?. dataset_query ?. native ?. query || state . sqlQuery || '' } ) ;
179170 if ( ! userApproved ) {
180- throw new Error ( "Action (and subsequent plan) cancelled!" ) ;
171+ actionContent . content = '<UserCancelled>Reason: ' + ( userFeedback === '' ? 'No particular reason given' : userFeedback ) + '</UserCancelled>' ;
172+ return actionContent ;
181173 }
182174 if ( state . sqlEditorState == "closed" ) {
183175 await this . toggleSQLEditor ( "open" ) ;
@@ -363,7 +355,7 @@ export class MetabaseController extends AppController<MetabaseAppState> {
363355 const actionContent : BlankMessageContent = {
364356 type : "BLANK" ,
365357 } ;
366- const userApproved = await RPCs . getUserConfirmation ( { content : memory , contentTitle : "Shall I add this to memory?" , oldContent : undefined , override : true } ) ;
358+ const { userApproved, userFeedback } = await RPCs . getUserConfirmation ( { content : memory , contentTitle : "Shall I add this to memory?" , oldContent : undefined , override : true } ) ;
367359 if ( userApproved ) {
368360 dispatch ( addMemory ( memory ) ) ;
369361 dispatch ( updateIsDevToolsOpen ( true ) )
@@ -387,10 +379,6 @@ export class MetabaseController extends AppController<MetabaseAppState> {
387379 }
388380 } )
389381 async executeSQLQuery ( ) {
390- const userApproved = await RPCs . getUserConfirmation ( { content : "Execute query" , contentTitle : "Accept below action?" , oldContent : undefined } ) ;
391- if ( ! userApproved ) {
392- throw new Error ( "Action (and subsequent plan) cancelled!" ) ;
393- }
394382 return await this . _executeSQLQueryInternal ( ) ;
395383 }
396384
@@ -451,22 +439,11 @@ export class MetabaseController extends AppController<MetabaseAppState> {
451439 const metabaseState = this . app as App < MetabaseAppState > ;
452440 const pageType = metabaseState . useStore ( ) . getState ( ) . toolContext ?. pageType ;
453441
454- // Check if template_tags or parameters are provided and non-empty
455- const hasTemplateTagsOrParams = ( template_tags && Object . keys ( template_tags ) . length > 0 ) || ( parameters && Array . isArray ( parameters ) && parameters . length > 0 ) ;
456-
457442 if ( pageType === 'sql' ) {
458- // if (hasTemplateTagsOrParams) {
459- return await this . updateSQLQueryWithParams ( { sql, template_tags, parameters, parameterValues, executeImmediately : true , _type : "markdown" , ctes : _ctes } ) ;
460- // } else {
461- // return await this.updateSQLQuery({ sql, executeImmediately: true, _type: "csv", ctes: _ctes });
462- // }
443+ return await this . updateSQLQueryWithParams ( { sql, template_tags, parameters, parameterValues, executeImmediately : true , _type : "markdown" , ctes : _ctes } ) ;
463444 }
464445 else if ( ( pageType === 'dashboard' ) || ( pageType === 'unknown' ) ) {
465- // if (hasTemplateTagsOrParams) {
466- return await this . runSQLQueryWithParams ( { sql, template_tags, parameters, ctes : _ctes } ) ;
467- // } else {
468- // return await this.runSQLQuery({ sql, ctes: _ctes });
469- // }
446+ return await this . runSQLQueryWithParams ( { sql, template_tags, parameters, ctes : _ctes } ) ;
470447 }
471448 }
472449
0 commit comments