From 147ea0f08fc0c17a60682e76987efd028d786fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Tue, 27 Jan 2026 16:04:01 +0400 Subject: [PATCH] Make sure page reloads when version is selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- ...cumentVersionsDropdownMenuQuery.graphql.ts | 151 +++++++++++++++++- .../documents/DocumentLayout.tsx | 2 +- .../documents/DocumentLayoutLoader.tsx | 4 +- .../_components/DocumentVersionsDropdown.tsx | 14 +- .../DocumentVersionsDropdownMenu.tsx | 29 +++- 5 files changed, 177 insertions(+), 23 deletions(-) diff --git a/apps/console/src/__generated__/core/DocumentVersionsDropdownMenuQuery.graphql.ts b/apps/console/src/__generated__/core/DocumentVersionsDropdownMenuQuery.graphql.ts index 121a547c7..34bde8a8c 100644 --- a/apps/console/src/__generated__/core/DocumentVersionsDropdownMenuQuery.graphql.ts +++ b/apps/console/src/__generated__/core/DocumentVersionsDropdownMenuQuery.graphql.ts @@ -1,5 +1,5 @@ /** - * @generated SignedSource<> + * @generated SignedSource<<369fa1f3218710cdc3fedb7e161f4e13>> * @lightSyntaxTransform * @nogrep */ @@ -12,10 +12,19 @@ import { ConcreteRequest } from 'relay-runtime'; import { FragmentRefs } from "relay-runtime"; export type DocumentVersionsDropdownMenuQuery$variables = { documentId: string; + versionId: string; + versionSpecified: boolean; }; export type DocumentVersionsDropdownMenuQuery$data = { readonly document: { readonly __typename: "Document"; + readonly lastVersion?: { + readonly edges: ReadonlyArray<{ + readonly node: { + readonly id: string; + }; + }>; + }; readonly versions: { readonly edges: ReadonlyArray<{ readonly node: { @@ -29,6 +38,14 @@ export type DocumentVersionsDropdownMenuQuery$data = { // value in case none of the concrete values match. readonly __typename: "%other"; }; + readonly version?: { + readonly __typename: "DocumentVersion"; + readonly id: string; + } | { + // This will never be '%other', but we need some + // value in case none of the concrete values match. + readonly __typename: "%other"; + }; }; export type DocumentVersionsDropdownMenuQuery = { response: DocumentVersionsDropdownMenuQuery$data; @@ -41,6 +58,16 @@ var v0 = [ "defaultValue": null, "kind": "LocalArgument", "name": "documentId" + }, + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "versionId" + }, + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "versionSpecified" } ], v1 = [ @@ -70,7 +97,70 @@ v4 = { "kind": "ScalarField", "name": "id", "storageKey": null -}; +}, +v5 = [ + (v4/*: any*/) +], +v6 = { + "condition": "versionSpecified", + "kind": "Condition", + "passingValue": false, + "selections": [ + { + "alias": "lastVersion", + "args": [ + { + "kind": "Literal", + "name": "first", + "value": 1 + }, + { + "kind": "Literal", + "name": "orderBy", + "value": { + "direction": "DESC", + "field": "CREATED_AT" + } + } + ], + "concreteType": "DocumentVersionConnection", + "kind": "LinkedField", + "name": "versions", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionEdge", + "kind": "LinkedField", + "name": "edges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersion", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": (v5/*: any*/), + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": "versions(first:1,orderBy:{\"direction\":\"DESC\",\"field\":\"CREATED_AT\"})" + } + ] +}, +v7 = [ + { + "kind": "Variable", + "name": "id", + "variableName": "versionId" + } +]; return { "fragment": { "argumentDefinitions": (v0/*: any*/), @@ -128,13 +218,39 @@ return { } ], "storageKey": "versions(first:20)" - } + }, + (v6/*: any*/) ], "type": "Document", "abstractKey": null } ], "storageKey": null + }, + { + "condition": "versionSpecified", + "kind": "Condition", + "passingValue": true, + "selections": [ + { + "alias": "version", + "args": (v7/*: any*/), + "concreteType": null, + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "kind": "InlineFragment", + "selections": (v5/*: any*/), + "type": "DocumentVersion", + "abstractKey": null + } + ], + "storageKey": null + } + ] } ], "type": "Query", @@ -219,7 +335,8 @@ return { } ], "storageKey": "versions(first:20)" - } + }, + (v6/*: any*/) ], "type": "Document", "abstractKey": null @@ -227,20 +344,40 @@ return { (v4/*: any*/) ], "storageKey": null + }, + { + "condition": "versionSpecified", + "kind": "Condition", + "passingValue": true, + "selections": [ + { + "alias": "version", + "args": (v7/*: any*/), + "concreteType": null, + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v2/*: any*/), + (v4/*: any*/) + ], + "storageKey": null + } + ] } ] }, "params": { - "cacheID": "914f2c11640879dfb202ba668fb0bff0", + "cacheID": "f940f62593d1a96d898b128a11e8cf3b", "id": null, "metadata": {}, "name": "DocumentVersionsDropdownMenuQuery", "operationKind": "query", - "text": "query DocumentVersionsDropdownMenuQuery(\n $documentId: ID!\n) {\n document: node(id: $documentId) {\n __typename\n ... on Document {\n versions(first: 20) {\n edges {\n node {\n id\n ...DocumentVersionsDropdownItemFragment\n }\n }\n }\n }\n id\n }\n}\n\nfragment DocumentVersionsDropdownItemFragment on DocumentVersion {\n id\n version\n status\n publishedAt\n updatedAt\n}\n" + "text": "query DocumentVersionsDropdownMenuQuery(\n $documentId: ID!\n $versionId: ID!\n $versionSpecified: Boolean!\n) {\n document: node(id: $documentId) {\n __typename\n ... on Document {\n versions(first: 20) {\n edges {\n node {\n id\n ...DocumentVersionsDropdownItemFragment\n }\n }\n }\n lastVersion: versions(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) @skip(if: $versionSpecified) {\n edges {\n node {\n id\n }\n }\n }\n }\n id\n }\n version: node(id: $versionId) @include(if: $versionSpecified) {\n __typename\n ... on DocumentVersion {\n id\n }\n id\n }\n}\n\nfragment DocumentVersionsDropdownItemFragment on DocumentVersion {\n id\n version\n status\n publishedAt\n updatedAt\n}\n" } }; })(); -(node as any).hash = "4cc270e68cee032d619dc7a348715d83"; +(node as any).hash = "33baa920362db3aef46644b80477d78a"; export default node; diff --git a/apps/console/src/pages/organizations/documents/DocumentLayout.tsx b/apps/console/src/pages/organizations/documents/DocumentLayout.tsx index 4ac09c857..8adcc0c0c 100644 --- a/apps/console/src/pages/organizations/documents/DocumentLayout.tsx +++ b/apps/console/src/pages/organizations/documents/DocumentLayout.tsx @@ -149,7 +149,7 @@ export function DocumentLayout(props: { queryRef: PreloadedQuery )} - + diff --git a/apps/console/src/pages/organizations/documents/DocumentLayoutLoader.tsx b/apps/console/src/pages/organizations/documents/DocumentLayoutLoader.tsx index 55e03899a..1a7468034 100644 --- a/apps/console/src/pages/organizations/documents/DocumentLayoutLoader.tsx +++ b/apps/console/src/pages/organizations/documents/DocumentLayoutLoader.tsx @@ -31,9 +31,11 @@ function DocumentLayoutQueryLoader() { } export default function DocumentLayoutLoader() { + const { documentId, versionId } = useParams(); + return ( - }> + }> diff --git a/apps/console/src/pages/organizations/documents/_components/DocumentVersionsDropdown.tsx b/apps/console/src/pages/organizations/documents/_components/DocumentVersionsDropdown.tsx index 20a8b522b..26719c489 100644 --- a/apps/console/src/pages/organizations/documents/_components/DocumentVersionsDropdown.tsx +++ b/apps/console/src/pages/organizations/documents/_components/DocumentVersionsDropdown.tsx @@ -8,12 +8,8 @@ import type { DocumentVersionsDropdownMenuQuery } from "#/__generated__/core/Doc import { DocumentVersionsDropdownMenu, documentVersionsDropdownMenuQuery } from "./DocumentVersionsDropdownMenu"; -export function DocumentVersionsDropdown(props: { - currentVersionId: string; -}) { - const { currentVersionId } = props; - - const { documentId } = useParams(); +export function DocumentVersionsDropdown() { + const { documentId, versionId } = useParams(); if (!documentId) { throw new Error(":documentId missing in route params"); } @@ -23,7 +19,7 @@ export function DocumentVersionsDropdown(props: { return ( open && !queryRef && loadQuery({ documentId })} + onOpenChange={open => open && !queryRef && loadQuery({ documentId, versionId: versionId ?? "", versionSpecified: !!versionId })} toggle={(