Skip to content

Commit 2c6eb75

Browse files
committed
fix(results-page): fix viewer links on job results
1 parent 06aa263 commit 2c6eb75

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

components/results/details/JobDetails/JobLink.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const getPath = (contains: string) => {
1818
.split("/")
1919
.filter((part) => part !== ".")
2020
// Filter empty parts
21-
.filter((part) => Boolean(part));
21+
.filter((part) => !!part);
2222

2323
return path;
2424
};
@@ -58,7 +58,6 @@ const getFilePathAndName = (path: string[]) => {
5858
*/
5959
export const JobLink = ({ projectId, path: originalPath, type }: JobLinkProps) => {
6060
const { query } = useRouter();
61-
6261
const path = getPath(originalPath);
6362
const { resolvedPath, containsGlob } = getResolvedPath(path);
6463
const displayPath = path.join("/");

constants/routes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ type Proxy = "/api/dm-api" | "/api/viewer-proxy" | "";
55

66
export const API_ROUTES = {
77
projectFile: (projectId: string, path: string, fileName: string, proxy: Proxy = "") =>
8-
`${proxy}/project/${projectId}/file?path=${path}&file=${fileName}`,
8+
`${proxy}/project/${projectId}/file?path=${encodeURIComponent(path)}&file=${encodeURIComponent(
9+
fileName,
10+
)}`,
911
datasetVersion: (datasetId: string, version: number, proxy: Proxy = "") =>
1012
`${proxy}/dataset/${datasetId}/${version}`,
1113
};

pages/project/file.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export const getServerSideProps: GetServerSideProps<FileProps> = async ({ req, r
2121
let { path } = query;
2222
const { file, project } = query;
2323

24-
if (path === undefined || typeof file !== "string" || typeof project !== "string") {
25-
return createErrorProps(res, 500, "File, path or project are not valid");
24+
if (typeof file !== "string" || typeof project !== "string") {
25+
return createErrorProps(res, 500, "File or project are not valid");
2626
}
2727

2828
path = pathFromQuery(path);
@@ -42,10 +42,14 @@ export const File = (props: FileProps) => {
4242

4343
const { query } = useRouter();
4444

45-
const { file, project, path } = query;
45+
const { file, project } = query;
46+
let { path = [] } = query;
4647

47-
if (typeof path !== "string" || typeof file !== "string" || typeof project !== "string") {
48-
return <NextError statusCode={400} />;
48+
if (Array.isArray(path)) {
49+
path = path.join("/");
50+
}
51+
if (typeof file !== "string" || typeof project !== "string") {
52+
return <NextError statusCode={400} statusMessage="File or project are invalid" />;
4953
}
5054

5155
const title = (path.endsWith("/") ? path : path + "/") + file;

utils/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const pathFromQuery = (query: string | string[]) => {
1+
export const pathFromQuery = (query: string | string[] | undefined = "") => {
22
if (query.length === 0) {
33
return "/";
44
} else if (typeof query === "string") {

0 commit comments

Comments
 (0)