Skip to content

Commit

Permalink
Fix wrong id applied when constructing a link to the question added t…
Browse files Browse the repository at this point in the history
…o the dashboard

Closes #18547
  • Loading branch information
nemanjaglumac committed Oct 20, 2021
1 parent 2dc34cd commit da11a7c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion frontend/src/metabase/lib/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,39 @@ export function question(card, hash = "", query = "") {
if (hash && typeof hash === "object") {
hash = serializeCardForUrl(hash);
}

if (query && typeof query === "object") {
query = extractQueryParams(query)
.map(kv => kv.map(encodeURIComponent).join("="))
.join("&");
}

if (hash && hash.charAt(0) !== "#") {
hash = "#" + hash;
}

if (query && query.charAt(0) !== "?") {
query = "?" + query;
}

if (!card || !card.id) {
return `/question${query}${hash}`;
}

if (!card.name) {
return `/question/${card.id}${query}${hash}`;
}
const path = appendSlug(`/question/${card.id}`, slugg(card.name));

/**
* 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.
*
* There can be multiple instances of the same question in a dashboard, hence this distinction.
*/
const { card_id, id } = card;

const path = appendSlug(`/question/${card_id || id}`, slugg(card.name));

return `${path}${query}${hash}`;
}

Expand Down

0 comments on commit da11a7c

Please sign in to comment.