Skip to content
Snippets Groups Projects
Unverified Commit 17813df1 authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

Fix permissions breadcrumbs for schemaless dbs (#37733)

* fix breadcrumbs for schemaless dbs

* fix types
parent 56c70724
No related branches found
No related tags found
No related merge requests found
import {
createMockDatabase,
createMockSchema,
createMockTable,
} from "metabase-types/api/mocks";
import { createMockMetadata } from "__support__/metadata";
import { getGroupsDataEditorBreadcrumbs } from "./breadcrumbs";
describe("admin > permissions > data > breadcrumbs", () => {
describe("getGroupsDataEditorBreadcrumbs", () => {
const schema = createMockSchema({
id: "100:myschema",
name: "myschema",
});
const schema2 = createMockSchema({
id: "100:myschema2",
name: "myschema2",
});
const metadata = createMockMetadata({
databases: [
createMockDatabase({
id: 100,
name: "myDatabase",
// @ts-expect-error - we have to set this manually for this test to work due to circular object nonsense
schemas: [schema, schema2],
}),
createMockDatabase({
id: 101,
name: "mySchemalessDatabase",
engine: "mysql",
}),
],
schemas: [schema, schema2],
tables: [
createMockTable({ id: 300, db_id: 100, display_name: "myTable" }),
createMockTable({
id: 301,
db_id: 101,
display_name: "mySchemalessTable",
}),
],
});
it("should return breadcrumbs for a database with schema", () => {
const breadcrumbs = getGroupsDataEditorBreadcrumbs(
{
databaseId: 100,
schemaName: "public",
tableId: 300,
},
metadata,
);
expect(breadcrumbs).toEqual([
{
text: "myDatabase",
id: 100,
url: "/admin/permissions/data/database/100",
},
{
text: "public",
id: "100:public",
url: "/admin/permissions/data/database/100/schema/public",
},
{
text: "myTable",
id: 300,
},
]);
});
// from metabase's metadata perspective, there's no such thing as a schemaless database
// even mysql has a single unnamed schema
it("should return breadcrumbs for a database with only 1 schema", () => {
const breadcrumbs = getGroupsDataEditorBreadcrumbs(
{
databaseId: 101,
schemaName: "public",
tableId: 301,
},
metadata,
);
expect(breadcrumbs).toEqual([
{
text: "mySchemalessDatabase",
id: 101,
url: "/admin/permissions/data/database/101",
},
{
text: "mySchemalessTable",
id: 301,
},
]);
});
});
});
......@@ -3,9 +3,9 @@ export const isNotNull = <T>(value: T | null | undefined): value is T => {
};
export const isNotFalsy = <T>(
value: T | null | undefined | false,
value: T | null | undefined | false | "",
): value is T => {
return value != null;
return value != null && value !== false && value !== "";
};
export const isNumber = (value: unknown): value is number => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment