Skip to content

Commit

Permalink
Account for null schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmielnik committed Apr 4, 2024
1 parent 8a2fb07 commit 4f5c4e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/metabase-types/api/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface Table {
db_id: DatabaseId;
db?: Database;

schema: SchemaName;
schema: SchemaName | null;

fks?: ForeignKey[];
fields?: Field[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type ModelItem = {
export type TablePickerValue = {
id: TableId;
db_id: DatabaseId;
schema?: SchemaName;
schema: SchemaName;
};

export type NotebookDataPickerFolderItem =
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/metabase/common/components/DataPicker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const tablePickerValueFromTable = (
return {
db_id: table.db_id,
id: table.id,
schema: table.schema,
schema: table.schema ?? "",
};
};

Expand All @@ -47,7 +47,7 @@ const tablePickerValueFromTableEntity = (
return {
db_id: table.db_id,
id: table.id,
schema: table.schema_name ?? table.schema?.name,
schema: table.schema_name ?? table.schema?.name ?? "",
};
};

Expand All @@ -66,15 +66,15 @@ export const getDbItem = (
};

export const getSchemaItem = (
schemaName: SchemaName | undefined,
schemaName: SchemaName | undefined | null,
): NotebookDataPickerFolderItem | null => {
if (typeof schemaName === "undefined") {
return null;
}

const name = getSchemaDisplayName(schemaName);

return { model: "schema", id: schemaName, name };
return { model: "schema", id: schemaName ?? "", name };
};

export const getTableItem = (
Expand All @@ -91,8 +91,10 @@ export const getTableItem = (
return { model: "table", id: tableId, name };
};

export const getSchemaDisplayName = (schemaName: SchemaName | undefined) => {
if (typeof schemaName === "undefined") {
export const getSchemaDisplayName = (
schemaName: SchemaName | undefined | null,
) => {
if (!schemaName) {
return "";
}

Expand Down

0 comments on commit 4f5c4e9

Please sign in to comment.