Fix DocumentList: clear selection on filter change, update connection ID, fix indentation

Addresses PR review comments: clears selected document IDs when changing
the type filter to prevent bulk actions on hidden rows, updates the Relay
connection ID when the filter changes so mutations target the correct
connection, and fixes eslint indentation violations.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-19 11:58:06 +01:00
parent 4f54241382
commit c3be391e9d
2 changed files with 161 additions and 146 deletions

View File

@@ -6,7 +6,7 @@ import {
IconPlusLarge,
PageHeader,
} from "@probo/ui";
import { useState } from "react";
import { useMemo, useState } from "react";
import {
type PreloadedQuery,
usePreloadedQuery,
@@ -67,7 +67,8 @@ export default function DocumentsPage(props: {
({ node: { canSendSigningNotifications } }) => canSendSigningNotifications,
);
const [documentListConnectionId, setDocumentListConnectionId] = useState(
const unfilteredConnectionId = useMemo(
() =>
ConnectionHandler.getConnectionID(
organizationId,
"DocumentsListQuery_documents",
@@ -76,8 +77,11 @@ export default function DocumentsPage(props: {
filter: { documentTypes: null },
},
),
[organizationId],
);
const [, setDocumentListConnectionId] = useState(unfilteredConnectionId);
const handleSendSigningNotifications = async () => {
await sendSigningNotifications({
variables: {
@@ -104,7 +108,7 @@ export default function DocumentsPage(props: {
)}
{organization.canCreateDocument && (
<CreateDocumentDialog
connection={documentListConnectionId}
connection={unfilteredConnectionId}
trigger={
<Button icon={IconPlusLarge}>{__("New document")}</Button>
}

View File

@@ -86,7 +86,18 @@ export function DocumentList(props: {
const handleDocumentTypeFilterChange = (value: string) => {
const newType = value === "ALL" ? null : (value as DocumentType);
clear();
setDocumentTypeFilter(newType);
onConnectionIdChange(
ConnectionHandler.getConnectionID(
organizationId,
"DocumentsListQuery_documents",
{
orderBy: { direction: "ASC", field: "TITLE" },
filter: { documentTypes: newType ? [newType] : null },
},
),
);
startTransition(() => {
pagination.refetch(
{ documentTypes: newType ? [newType] : null },
@@ -165,7 +176,7 @@ export function DocumentList(props: {
onValueChange={handleDocumentTypeFilterChange}
>
<Option value="ALL">{__("All types")}</Option>
{documentTypes.map((type) => (
{documentTypes.map(type => (
<Option key={type} value={type}>
{getDocumentTypeLabel(__, type) ?? type}
</Option>