Skip to content

Commit 4039efc

Browse files
NicolappsConvex, Inc.
authored andcommitted
dash: Link to specific files from the Data page (#40826)
GitOrigin-RevId: 88c8b04d17d4ccbf2f0fcae51871e2c8b64ea5d5
1 parent f037f3e commit 4039efc

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

npm-packages/dashboard-common/src/features/data/components/Table/DataCell/DataCell.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ describe("DataCell", () => {
371371
await user.keyboard("{Meta>}g");
372372
expect(window.open).toHaveBeenCalledTimes(1);
373373
expect(window.open).toHaveBeenCalledWith(
374-
"http://localhost/files",
374+
"http://localhost/files?id=kg267e113cftx1jpeepypezsa57q9wvp",
375375
"_blank",
376376
);
377377
});

npm-packages/dashboard-common/src/features/data/components/Table/TableContextMenu.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe("TableContextMenu", () => {
222222
expect(link).toHaveAttribute("target", "_blank");
223223
});
224224

225-
it("should link to the files page", async () => {
225+
it("should link to the a specific file on the Files page", async () => {
226226
const { getByTestId } = renderWithProvider({
227227
state: {
228228
target: { x: 0, y: 0 },
@@ -238,15 +238,21 @@ describe("TableContextMenu", () => {
238238
editDoc: jest.fn(),
239239
view: jest.fn(),
240240
viewDoc: jest.fn(),
241-
docRefLink: { pathname: "/files" },
241+
docRefLink: {
242+
pathname: "/files",
243+
query: { id: "kg267e113cftx1jpeepypezsa57q9wvp" },
244+
},
242245
},
243246
},
244247
},
245248
});
246249

247250
const link = getByTestId("table-context-menu").children[0];
248-
expect(link).toHaveTextContent("Go to Files");
249-
expect(link).toHaveAttribute("href", "/files");
251+
expect(link).toHaveTextContent("Go to File");
252+
expect(link).toHaveAttribute(
253+
"href",
254+
"/files?id=kg267e113cftx1jpeepypezsa57q9wvp",
255+
);
250256
expect(link).toHaveAttribute("target", "_blank");
251257
});
252258

npm-packages/dashboard-common/src/features/data/components/Table/TableContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function CellActions({
326326
<ExternalLinkIcon aria-hidden="true" />
327327
),
328328
label: isFileRef
329-
? "Go to Files"
329+
? "Go to File"
330330
: isScheduledFunctionRef
331331
? "Go to Scheduled Functions"
332332
: "Go to Reference",

npm-packages/dashboard-common/src/features/files/components/FileStorageView.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UploadIcon } from "@radix-ui/react-icons";
22
import { useQuery } from "convex/react";
3-
import React, { useRef, useState } from "react";
3+
import React, { useCallback, useRef, useState } from "react";
4+
import { useRouter } from "next/router";
45
import udfs from "@common/udfs";
56
import { Id } from "system-udfs/convex/_generated/dataModel";
67
import { toast } from "@common/lib/utils";
@@ -38,7 +39,28 @@ export function FileStorageView() {
3839
setFilters,
3940
} = usePaginatedFileMetadata();
4041

41-
const [fileId, setFileId] = useState("");
42+
const router = useRouter();
43+
const fileId =
44+
!router.isReady || !router.query.id
45+
? ""
46+
: Array.isArray(router.query.id)
47+
? router.query.id[0]
48+
: router.query.id;
49+
const setFileId = useCallback(
50+
(newFileId: string) => {
51+
const query = { ...router.query };
52+
if (newFileId) {
53+
query.id = newFileId;
54+
} else {
55+
delete query.id;
56+
}
57+
58+
void router.replace({ pathname: router.pathname, query }, undefined, {
59+
shallow: true,
60+
});
61+
},
62+
[router],
63+
);
4264

4365
const totalNumFiles = useQuery(udfs.fileStorageV2.numFiles, {
4466
componentId: useNents().selectedNent?.id ?? null,

npm-packages/dashboard-common/src/lib/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ export function documentHref({
124124
if (tableName === "_file_storage") {
125125
return {
126126
pathname: `${deploymentsURI}/files`,
127-
query: {
128-
// FIXME: This could include query parameters one day to link to a specific file
129-
},
127+
query: { id },
130128
};
131129
}
132130

0 commit comments

Comments
 (0)