feat: Refactor tag and correspondent management to use canonical types and dedicated managers.

This commit is contained in:
2025-12-09 18:56:11 +01:00
parent ce821c1817
commit 3ccc1f6698
34 changed files with 790 additions and 427 deletions
@@ -63,6 +63,7 @@ interface SelectionFloatingActionsProps {
tags?: TagOption[] | null;
tagLookupById?: Map<DocumentId, TagOption> | null;
correspondents?: CorrespondentOption[] | null;
correspondentLookupById?: Map<DocumentId, CorrespondentOption> | null;
onBulkTagAdd?: (args: BulkTagMutationArgs) => Promise<void> | void;
onBulkTagRemove?: (args: BulkTagMutationArgs) => Promise<void> | void;
onBulkCorrespondentAdd?: (args: BulkCorrespondentAddArgs) => Promise<void> | void;
@@ -114,9 +115,12 @@ const buildTagAssignments = (
};
selectedDocuments.forEach((doc) => {
(doc?.tags || []).forEach((tag) => {
const lookupColor = tag?.id && tagLookupById instanceof Map ? tagLookupById.get(tag.id)?.color : null;
const entry = ensureEntry(tag?.id, tag?.label, tag?.color ?? lookupColor ?? null);
(doc?.tags || []).forEach((tagId) => {
const tag = tagLookupById instanceof Map ? tagLookupById.get(tagId) : null;
const lookupColor = tag?.color ?? null;
const label = tag?.label;
const entry = ensureEntry(tagId, label, lookupColor);
if (entry) {
entry.count += 1;
}
@@ -146,6 +150,7 @@ const buildTagAssignments = (
const buildCorrespondentAssignments = (
selectedDocuments: Document[],
correspondents: CorrespondentOption[] | null,
correspondentLookupById: Map<DocumentId, CorrespondentOption> | null,
total: number,
): SelectionAssignmentMenuItem[] => {
if (!total) {
@@ -176,8 +181,11 @@ const buildCorrespondentAssignments = (
};
selectedDocuments.forEach((doc) => {
(doc?.correspondents || []).forEach((entry) => {
const target = ensureEntry(entry?.id, entry?.name);
(doc?.correspondents || []).forEach((correspondentId) => {
const resolved = correspondentLookupById instanceof Map ? correspondentLookupById.get(correspondentId) : null;
const name = resolved?.name;
const target = ensureEntry(correspondentId, name);
if (target) {
target.count += 1;
}
@@ -210,6 +218,7 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
tags = [],
tagLookupById,
correspondents = [],
correspondentLookupById,
onBulkTagAdd,
onBulkTagRemove,
onBulkCorrespondentAdd,
@@ -303,8 +312,8 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
);
const correspondentAssignments = useMemo(
() => buildCorrespondentAssignments(selectedDocuments, correspondents, selectedDocCount),
[selectedDocuments, correspondents, selectedDocCount],
() => buildCorrespondentAssignments(selectedDocuments, correspondents, correspondentLookupById, selectedDocCount),
[selectedDocuments, correspondents, correspondentLookupById, selectedDocCount],
);
const handleToggleTagAssignment = useCallback(