From 7ba07f5f921473eda120ffa7d5348a37a43bf0dd Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Tue, 17 Dec 2024 11:48:13 -0500 Subject: [PATCH] Use object over order --- .../MergeDupsStep/MergeDragDrop/DropWord.tsx | 2 +- .../MergeDupsStep/SenseCardContent.tsx | 2 +- .../MergeDupsStep/protectReasonUtils.ts | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/DropWord.tsx b/src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/DropWord.tsx index f79b4c4a2..c6eea5c81 100644 --- a/src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/DropWord.tsx +++ b/src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/DropWord.tsx @@ -168,7 +168,7 @@ export function DropWordCardHeader( const tooltipTexts = [t("mergeDups.helpText.protectedWord")]; const reasons = words[props.wordId]?.protectReasons; if (reasons?.length) { - tooltipTexts.push(protectReasonsText(t, reasons, [])); + tooltipTexts.push(protectReasonsText(t, { word: reasons })); } tooltipTexts.push(t("mergeDups.helpText.protectedWordInfo")); diff --git a/src/goals/MergeDuplicates/MergeDupsStep/SenseCardContent.tsx b/src/goals/MergeDuplicates/MergeDupsStep/SenseCardContent.tsx index 7d402ca99..ea72dcd0a 100644 --- a/src/goals/MergeDuplicates/MergeDupsStep/SenseCardContent.tsx +++ b/src/goals/MergeDuplicates/MergeDupsStep/SenseCardContent.tsx @@ -41,7 +41,7 @@ export default function SenseCardContent( const tooltipTexts = [t("mergeDups.helpText.protectedSense")]; const reasons = sense.protectReasons; if (reasons?.length) { - tooltipTexts.push(protectReasonsText(t, [], reasons)); + tooltipTexts.push(protectReasonsText(t, { sense: reasons })); } tooltipTexts.push(t("mergeDups.helpText.protectedSenseInfo")); diff --git a/src/goals/MergeDuplicates/MergeDupsStep/protectReasonUtils.ts b/src/goals/MergeDuplicates/MergeDupsStep/protectReasonUtils.ts index cd23f0286..8af320038 100644 --- a/src/goals/MergeDuplicates/MergeDupsStep/protectReasonUtils.ts +++ b/src/goals/MergeDuplicates/MergeDupsStep/protectReasonUtils.ts @@ -4,13 +4,17 @@ import { ProtectReason, ReasonType } from "api/models"; const sep = "; "; +interface WordSenseReasons { + sense?: ProtectReason[]; + word?: ProtectReason[]; +} + export function protectReasonsText( t: TFunction<"translation", undefined>, - wordReasons: ProtectReason[] = [], - senseReasons: ProtectReason[] = [] + reasons: WordSenseReasons ): string { - const wordTexts = wordReasons.map((r) => wordReasonText(t, r)); - const senseTexts = senseReasons.map((r) => senseReasonText(t, r)); + const wordTexts = reasons.word?.map((r) => wordReasonText(t, r)) ?? []; + const senseTexts = reasons.sense?.map((r) => senseReasonText(t, r)) ?? []; const val = [...wordTexts, ...senseTexts].join(sep); return t("mergeDups.helpText.protectedData", { val }); }