Skip to content
Snippets Groups Projects
Unverified Commit 691281c2 authored by Uladzimir Havenchyk's avatar Uladzimir Havenchyk Committed by GitHub
Browse files

Fix download full results link for embedded and public questions (#34659)

parent 43d9be7d
Branches
Tags
No related merge requests found
......@@ -146,7 +146,9 @@ export const PublicLinksQuestionListing = () => (
revoke={CardApi.deletePublicLink}
type={t`Public Card Listing`}
getUrl={question => Urls.question(question)}
getPublicUrl={({ public_uuid }) => Urls.publicQuestion(public_uuid)}
getPublicUrl={({ public_uuid }) =>
Urls.publicQuestion({ uuid: public_uuid })
}
noLinksMessage={t`No questions have been publicly shared yet.`}
/>
);
......
......@@ -121,12 +121,18 @@ export function newQuestion({
}
}
export function publicQuestion(
uuid: string,
type: string | null = null,
query?: string,
) {
const siteUrl = MetabaseSettings.get("site-url");
export function publicQuestion({
uuid,
type = null,
query,
includeSiteUrl = true,
}: {
uuid: string;
type: string | null;
query?: string;
includeSiteUrl?: boolean;
}) {
const siteUrl = includeSiteUrl ? MetabaseSettings.get("site-url") : "";
const searchQuery = query ? `?${query}` : "";
return (
`${siteUrl}/public/question/${uuid}` +
......@@ -136,8 +142,7 @@ export function publicQuestion(
}
export function embedCard(token: string, type: string | null = null) {
const siteUrl = MetabaseSettings.get("site-url");
return `${siteUrl}/embed/question/${token}` + (type ? `.${type}` : ``);
return `/embed/question/${token}` + (type ? `.${type}` : ``);
}
export function tableRowsQuery(
......
......@@ -89,7 +89,7 @@ const getDatasetParams = ({
if (isPublicQuestion) {
return {
method: "GET",
url: Urls.publicQuestion(uuid, type),
url: Urls.publicQuestion({ uuid, type, includeSiteUrl: false }),
params: new URLSearchParams({
parameters: JSON.stringify(result?.json_query?.parameters ?? []),
}),
......@@ -128,17 +128,25 @@ const getDatasetParams = ({
};
};
export function getDatasetDownloadUrl(url: string) {
// make url relative if it's not
url = url.replace(api.basename, "");
const requestUrl = new URL(api.basename + url, location.origin);
return requestUrl.href;
}
const getDatasetResponse = ({
url,
method,
params,
}: DownloadQueryResultsParams) => {
const requestUrl = new URL(api.basename + url, location.origin);
const requestUrl = getDatasetDownloadUrl(url);
if (method === "POST") {
return fetch(requestUrl.href, { method, body: params });
return fetch(requestUrl, { method, body: params });
} else {
return fetch(`${requestUrl.href}?${params}`);
return fetch(`${requestUrl}?${params}`);
}
};
......
import api from "metabase/lib/api";
import * as downloading from "./downloading";
describe("getDatasetResponse", () => {
describe("normal deployment", () => {
const origin = location.origin; // http://localhost
it("should handle absolute URLs", () => {
const url = `${origin}/embed/question/123.xlsx`;
expect(downloading.getDatasetDownloadUrl(url)).toBe(
`${origin}/embed/question/123.xlsx`,
);
});
it("should handle relative URLs", () => {
const url = "/embed/question/123.xlsx";
expect(downloading.getDatasetDownloadUrl(url)).toBe(
`${origin}/embed/question/123.xlsx`,
);
});
});
describe("subpath deployment", () => {
const origin = "http://localhost";
const subpath = "/mb";
const originalBasename = api.basename;
beforeEach(() => {
api.basename = `${origin}${subpath}`;
});
afterEach(() => {
api.basename = originalBasename;
});
it("should handle absolute URLs", () => {
const url = `${origin}${subpath}/embed/question/123.xlsx`;
expect(downloading.getDatasetDownloadUrl(url)).toBe(
`${origin}${subpath}/embed/question/123.xlsx`,
);
});
it("should handle relative URLs", () => {
const url = "/embed/question/123.xlsx";
expect(downloading.getDatasetDownloadUrl(url)).toBe(
`${origin}${subpath}/embed/question/123.xlsx`,
);
});
});
});
......@@ -73,7 +73,7 @@ class QuestionEmbedWidget extends Component {
updateEmbeddingParams(card, embeddingParams)
}
getPublicUrl={({ public_uuid }, extension) =>
Urls.publicQuestion(public_uuid, extension)
Urls.publicQuestion({ uuid: public_uuid, type: extension })
}
extensions={Urls.exportFormats}
/>
......
......@@ -49,12 +49,13 @@ const LegacyChoropleth = ({
onMouseLeave={() => onHoverFeature(null)}
className={cx({ "cursor-pointer": !!onClickFeature })}
onClick={
onClickFeature &&
(e =>
onClickFeature({
feature: feature,
event: e.nativeEvent,
}))
onClickFeature
? e =>
onClickFeature({
feature: feature,
event: e.nativeEvent,
})
: undefined
}
/>
))}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment