-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
197 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,6 @@ | ||
import { dashboard } from "./dashboards"; | ||
import { model } from "./models"; | ||
import { pulse } from "./pulses"; | ||
import { question, tableRowsQuery } from "./questions"; | ||
|
||
export const exportFormats = ["csv", "xlsx", "json"]; | ||
export const exportFormatPng = "png"; | ||
|
||
export function accountSettings() { | ||
return "/account/profile"; | ||
} | ||
|
||
function prepareModel(item) { | ||
if (item.model_object) { | ||
return item.model_object; | ||
} | ||
return { | ||
id: item.model_id, | ||
...item.details, | ||
}; | ||
} | ||
|
||
export function modelToUrl(item) { | ||
const modelData = prepareModel(item); | ||
|
||
switch (item.model) { | ||
case "card": | ||
return question(modelData); | ||
case "dataset": | ||
return model(modelData); | ||
case "dashboard": | ||
return dashboard(modelData); | ||
case "pulse": | ||
return pulse(modelData.id); | ||
case "table": | ||
return tableRowsQuery(modelData.db_id, modelData.id); | ||
default: | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { RecentItem } from "metabase-types/api"; | ||
|
||
import { collection } from "./collections"; | ||
import { dashboard } from "./dashboards"; | ||
import { model } from "./models"; | ||
import { question, tableRowsQuery } from "./questions"; | ||
|
||
export function modelToUrl(item: RecentItem) { | ||
switch (item.model) { | ||
case "card": | ||
return question({ | ||
...item, | ||
model: "card", // somehow typescript is not smart enough to infer this | ||
}); | ||
case "dataset": | ||
return model(item); | ||
case "dashboard": | ||
return dashboard(item); | ||
case "table": | ||
if (item?.database) { | ||
return tableRowsQuery(item?.database?.id, item.id); | ||
} | ||
return null; | ||
case "collection": | ||
return collection(item); | ||
default: | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { modelToUrl } from "./modelToUrl"; | ||
describe("urls > modelToUrl", () => { | ||
it("should return null for unknown model", () => { | ||
expect( | ||
modelToUrl({ | ||
// @ts-expect-error - testing the error case | ||
model: "pikachu", | ||
}), | ||
).toBeNull(); | ||
}); | ||
|
||
it("should return a question URL for a card", () => { | ||
expect( | ||
modelToUrl({ | ||
model: "card", | ||
name: "My Cool Question", | ||
id: 101, | ||
parent_collection: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
}, | ||
timestamp: "2021-01-01T00:00:00.000Z", | ||
}), | ||
).toBe("/question/101-my-cool-question"); | ||
}); | ||
|
||
it("should return a model URL for a dataset", () => { | ||
expect( | ||
modelToUrl({ | ||
model: "dataset", | ||
name: "My Cool Dataset", | ||
parent_collection: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
}, | ||
id: 101, | ||
timestamp: "2021-01-01T00:00:00.000Z", | ||
}), | ||
).toBe("/model/101-my-cool-dataset"); | ||
}); | ||
|
||
it("should return a dashboard URL for a dashboard", () => { | ||
expect( | ||
modelToUrl({ | ||
model: "dashboard", | ||
name: "My Cool Dashboard", | ||
parent_collection: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
}, | ||
id: 101, | ||
timestamp: "2021-01-01T00:00:00.000Z", | ||
}), | ||
).toBe("/dashboard/101-my-cool-dashboard"); | ||
}); | ||
|
||
it("should return a collection URL for a collection", () => { | ||
expect( | ||
modelToUrl({ | ||
model: "collection", | ||
name: "My Cool Collection", | ||
id: 1, | ||
parent_collection: { | ||
id: 1, | ||
name: "My Cool Collection", | ||
}, | ||
timestamp: "2021-01-01T00:00:00.000Z", | ||
}), | ||
).toBe("/collection/1-my-cool-collection"); | ||
}); | ||
|
||
it("should return a table URL for a table", () => { | ||
expect( | ||
modelToUrl({ | ||
model: "table", | ||
name: "MY_COOL_TABLE", | ||
display_name: "My Cool Table", | ||
id: 33, | ||
database: { | ||
Check failure on line 79 in frontend/src/metabase/lib/urls/modelToUrl.unit.spec.ts
|
||
id: 22, | ||
name: "My Cool Database", | ||
}, | ||
timestamp: "2021-01-01T00:00:00.000Z", | ||
}), | ||
).toBe("/question/#?db=22&table=33"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.