Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/dark-parrots-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@accounter/client': patch
---

- Extracted `missingInfoSuggestions` into a dedicated `ChargesTableSuggestionsFields` fragment.
- Applied `@defer` to the suggestions fragment spread inside `ChargeForChargesTableFields`.
- Updated `convertChargeFragmentToTableRow` to read suggestions via `getFragmentData` and handle the
deferred (initially-absent) fields safely.
39 changes: 27 additions & 12 deletions packages/client/src/components/charges/charges-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {
AccountantStatus,
ChargeForChargesTableFieldsFragmentDoc,
ChargesTableSuggestionsFieldsFragmentDoc,
MissingChargeInfo,
type ChargeForChargesTableFieldsFragment,
} from '../../gql/graphql.js';
Expand All @@ -37,6 +38,21 @@ import { columns } from './columns.js';
import { DownloadChargesCsv } from './download-charges-csv.js';
import { shouldHaveCounterparty, shouldHaveTaxCategory, shouldHaveVat } from './utils.js';

// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- used by codegen
/* GraphQL */ `
fragment ChargesTableSuggestionsFields on Charge {
id
missingInfoSuggestions {
description
tags {
id
name
namePath
}
}
}
`;

// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- used by codegen
/* GraphQL */ `
fragment ChargeForChargesTableFields on Charge {
Expand Down Expand Up @@ -93,16 +109,7 @@ import { shouldHaveCounterparty, shouldHaveTaxCategory, shouldHaveVat } from './
missingInfo
}
}
... on Charge {
missingInfoSuggestions {
description
tags {
id
name
namePath
}
}
}
...ChargesTableSuggestionsFields @defer
}
`;

Expand All @@ -125,6 +132,14 @@ export interface ChargeRow {
export function convertChargeFragmentToTableRow(
fragmentData: ChargeForChargesTableFieldsFragment,
): ChargeRow {
// The suggestions fragment is deferred — its fields are absent from the
// payload until the patch arrives, so unwrap defensively.
const missingInfoSuggestions = getFragmentData(
ChargesTableSuggestionsFieldsFragmentDoc,
// each charge subtype carries its own variant ref, which the overloads
// can't distribute over — the runtime is an identity unwrap either way
fragmentData as FragmentType<typeof ChargesTableSuggestionsFieldsFragmentDoc>,
)?.missingInfoSuggestions;
return {
id: fragmentData.id,
onChange: () => {},
Expand Down Expand Up @@ -174,7 +189,7 @@ export function convertChargeFragmentToTableRow(
chargeId: fragmentData.id,
value: fragmentData.userDescription?.trim() ?? undefined,
isMissing: fragmentData.validationData?.missingInfo.includes(MissingChargeInfo.Description),
suggestedDescription: fragmentData.missingInfoSuggestions?.description?.trim() ?? undefined,
suggestedDescription: missingInfoSuggestions?.description?.trim() ?? undefined,
},
tags: {
chargeId: fragmentData.id,
Expand All @@ -184,7 +199,7 @@ export function convertChargeFragmentToTableRow(
namePath: tag.namePath ?? undefined,
})),
suggestedTags:
fragmentData.missingInfoSuggestions?.tags.map(tag => ({
missingInfoSuggestions?.tags.map(tag => ({
id: tag.id,
name: tag.name,
namePath: tag.namePath ?? undefined,
Expand Down
Loading