Skip to content

Commit 42a8595

Browse files
fix limitedEntities to have only names in v2 code path; add selectedDbInfo back (#289)
1 parent 71e316d commit 42a8595

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

apps/src/metabase/helpers/DOMToState.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { MetabaseTableOrModel } from './metabaseAPITypes';
2323

2424
const {modifySqlForMxModels} = catalogAsModels
2525

26-
interface ExtractedDataBase {
26+
export interface ExtractedDataBase {
2727
name: string;
2828
description?: string;
2929
id: number;
@@ -106,7 +106,7 @@ export { type MetabasePageType } from '../defaultState'
106106

107107
export type MetabaseAppState = MetabaseAppStateSQLEditor | MetabaseAppStateDashboard | MetabaseSemanticQueryAppState | MetabaseAppStateMBQLEditor;
108108

109-
async function getRelevantEntitiesWithFields(sqlQuery: string): Promise<FormattedTable[]> {
109+
async function getRelevantEntitiesWithFields(sqlQuery: string): Promise<MetabaseTableOrModel[]> {
110110
const appSettings = RPCs.getAppSettings();
111111

112112
// Early return if conditions not met
@@ -146,23 +146,22 @@ async function getRelevantEntitiesWithFields(sqlQuery: string): Promise<Formatte
146146
const relevantModelsWithFields = await getModelsWithFields(relevantModels);
147147

148148
// Transform and combine tables and models with type annotations
149-
const relevantTablesWithFieldsAndType = relevantTablesWithFields.map(table => ({
150-
...table,
149+
const relevantTablesWithFieldsAndType: MetabaseTableOrModel[] = relevantTablesWithFields.map(table => ({
151150
type: 'table',
151+
id: table.id,
152+
name: table.name,
153+
schema: table.schema,
154+
description: table.description,
152155
}));
153156

154-
const relevantModelsWithFieldsAndType = relevantModelsWithFields.map(model => ({
155-
...model,
157+
const relevantModelsWithFieldsAndType: MetabaseTableOrModel[] = relevantModelsWithFields.map(model => ({
156158
type: 'model',
157-
name: model.modelName || '',
158159
id: model.modelId || 0,
159-
schema: '',
160-
table: undefined,
161-
modelId: undefined,
162-
modelName: undefined,
160+
name: model.name,
161+
description: model.description,
163162
}));
164163

165-
return [...relevantTablesWithFieldsAndType, ...relevantModelsWithFieldsAndType] as FormattedTable[];
164+
return [...relevantTablesWithFieldsAndType, ...relevantModelsWithFieldsAndType];
166165
}
167166

168167
export async function convertDOMtoStateSQLQueryV2() : Promise<MetabaseAppStateSQLEditorV2> {
@@ -178,6 +177,8 @@ export async function convertDOMtoStateSQLQueryV2() : Promise<MetabaseAppStateSQ
178177
const limitedEntities = await getRelevantEntitiesWithFields(
179178
get(currentCard, 'dataset_query.native.query', '') || ''
180179
);
180+
const dbId = await getSelectedDbId();
181+
const selectedDatabaseInfo = dbId ? await getDatabaseInfo(dbId) : undefined;
181182
return {
182183
type: MetabaseAppStateType.SQLEditor,
183184
version: '2',
@@ -188,6 +189,7 @@ export async function convertDOMtoStateSQLQueryV2() : Promise<MetabaseAppStateSQ
188189
currentCard,
189190
outputMarkdown,
190191
parameterValues,
192+
selectedDatabaseInfo
191193
}
192194
}
193195

apps/src/metabase/helpers/analystModeTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { omit, pick } from "lodash";
22
import { DashboardInfo } from "./dashboard/types";
33
import { Card, FormattedTable, ParameterValues } from "./types";
44
import { MetabaseTableOrModel } from "./metabaseAPITypes";
5+
import { ExtractedDataBase } from "./DOMToState";
56

67
export enum MetabaseAppStateType {
78
SQLEditor = 'metabaseSQLEditor',
@@ -17,6 +18,7 @@ interface MetabaseAppStateBase {
1718
metabaseUrl: string;
1819
isEmbedded: boolean;
1920
limitedEntities: MetabaseTableOrModel[];
21+
selectedDatabaseInfo?: ExtractedDataBase
2022
}
2123

2224
export interface MetabaseAppStateSQLEditorV2 extends MetabaseAppStateBase {

0 commit comments

Comments
 (0)