Skip to content
Snippets Groups Projects
Unverified Commit dde61e1b authored by Dalton's avatar Dalton Committed by GitHub
Browse files

Update routing/url logic to support unsaved Models (#25720)

parent 868979f6
Branches
Tags
No related merge requests found
......@@ -53,14 +53,13 @@ export function question(
query = "?" + query;
}
const isModel = card?.dataset || card?.model === "dataset";
let path = isModel ? "model" : "question";
if (!card || !card.id) {
return `/question${query}${hash}`;
return `/${path}${query}${hash}`;
}
const { card_id, id, name } = card;
const isModel = card?.dataset || card?.model === "dataset";
let path = isModel ? "model" : "question";
/**
* If the question has been added to the dashboard we're reading the dashCard's properties.
* In that case `card_id` is the actual question's id, while `id` corresponds with the dashCard itself.
......@@ -105,12 +104,14 @@ export function newQuestion({
objectId,
...options
}: NewQuestionUrlBuilderParams = {}) {
const url = Question.create(options).getUrl({
const question = Question.create(options);
const url = question.getUrl({
creationType,
query: objectId ? { objectId } : undefined,
});
if (mode) {
return url.replace(/^\/question/, `/question\/${mode}`);
const entity = question.isDataset() ? "model" : "question";
return url.replace(/^\/(question|model)/, `/${entity}\/${mode}`);
} else {
return url;
}
......
......@@ -291,6 +291,8 @@ export const getRoutes = store => (
<Route path=":slug/query" component={QueryBuilder} />
<Route path=":slug/metadata" component={QueryBuilder} />
<Route path=":slug/:objectId" component={QueryBuilder} />
<Route path="query" component={QueryBuilder} />
<Route path="metadata" component={QueryBuilder} />
</Route>
<Route path="browse" component={BrowseApp}>
......
......@@ -19,7 +19,12 @@ export interface RouterProps {
}
const HOMEPAGE_PATH = /^\/$/;
const PATHS_WITHOUT_NAVBAR = [/\/model\/.*\/query/, /\/model\/.*\/metadata/];
const PATHS_WITHOUT_NAVBAR = [
/\/model\/.*\/query/,
/\/model\/.*\/metadata/,
/\/model\/query/,
/\/model\/metadata/,
];
const EMBEDDED_PATHS_WITH_NAVBAR = [
HOMEPAGE_PATH,
/^\/collection\/.*/,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment