From 6e2fe6ccb2d6271c862d497a32610c60e2b01533 Mon Sep 17 00:00:00 2001 From: Arnei Date: Wed, 5 Jun 2024 14:00:46 +0200 Subject: [PATCH] Fix license strings not being translated in metadata dropdown For example, "ALLRIGHTS" would be shown instead of "All rights reservered". This is fixed now, by hopefully properly parsing listproviders that put JSON arrays as their values instead of strings. --- src/components/shared/DropDown.tsx | 2 +- src/components/shared/wizard/RenderField.tsx | 2 +- src/utils/dropDownUtils.ts | 2 +- src/utils/resourceUtils.ts | 22 +++++++++++++------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/shared/DropDown.tsx b/src/components/shared/DropDown.tsx index d3086b4afd..394b47f69d 100644 --- a/src/components/shared/DropDown.tsx +++ b/src/components/shared/DropDown.tsx @@ -17,7 +17,7 @@ import Select from "react-select"; * - Creating typescript types for each "type" is moot atm, as a lot of them (i.e. capture agents) are not properly typed yet * I would suggest waiting with typing options until all of its inputs are properly typed */ -export type DropDownType = "language" | "isPartOf" | "captureAgent" | "aclRole" | "workflow" | "aclTemplate" | "newTheme" | "comment" | "theme" | "time"; +export type DropDownType = "language" | "isPartOf" | "license" | "captureAgent" | "aclRole" | "workflow" | "aclTemplate" | "newTheme" | "comment" | "theme" | "time"; // type DPTime = { // index: number, diff --git a/src/components/shared/wizard/RenderField.tsx b/src/components/shared/wizard/RenderField.tsx index 7780f36342..09e6cfaf7e 100644 --- a/src/components/shared/wizard/RenderField.tsx +++ b/src/components/shared/wizard/RenderField.tsx @@ -86,7 +86,7 @@ const RenderField = ({ metadataField={metadataField} field={field} form={form} - text={field.value} + text={t(getMetadataCollectionFieldName(metadataField, field))} editMode={editMode} setEditMode={setEditMode} showCheck={showCheck} diff --git a/src/utils/dropDownUtils.ts b/src/utils/dropDownUtils.ts index 978fb00217..e0c5fdc781 100644 --- a/src/utils/dropDownUtils.ts +++ b/src/utils/dropDownUtils.ts @@ -53,7 +53,7 @@ export const formatDropDownOptions = ( label: `-- ${t("SELECT_NO_OPTION_SELECTED")} --`, }); } - if (type === "language") { + if (type === "language" || type === "license") { for (const item of unformattedOptions) { formattedOptions.push({ value: item.value, diff --git a/src/utils/resourceUtils.ts b/src/utils/resourceUtils.ts index 09720f59a0..d16c350986 100644 --- a/src/utils/resourceUtils.ts +++ b/src/utils/resourceUtils.ts @@ -10,7 +10,7 @@ import { Acl } from "../slices/aclSlice"; import { NewUser } from "../slices/userSlice"; import { Recording } from "../slices/recordingSlice"; import { UserInfoState } from "../slices/userInfoSlice"; -import { hasAccess } from "./utils"; +import { hasAccess, isJson } from "./utils"; import { RootState } from "../store"; import { MetadataCatalog } from "../slices/eventSlice"; @@ -141,8 +141,7 @@ export const getInitialMetadataFieldValues = ( }; // transform collection of metadata into object with name and value -// @ts-expect-error TS(7006): Parameter 'metadata' implicitly has an 'any' type. -export const transformMetadataCollection = (metadata, noField) => { +export const transformMetadataCollection = (metadata: any, noField: boolean) => { if (noField) { for (let i = 0; metadata.length > i; i++) { if (!!metadata[i].collection) { @@ -166,10 +165,19 @@ export const transformMetadataCollection = (metadata, noField) => { metadata.fields[i].collection = Object.keys( metadata.fields[i].collection ).map((key) => { - return { - name: key, - value: metadata.fields[i].collection[key], - }; + if (isJson(key)) { + let collectionParsed = JSON.parse(key); + return { + name: collectionParsed.label ? collectionParsed.label : key, + value: metadata.fields[i].collection[key], + ...collectionParsed, + }; + } else { + return { + name: key, + value: metadata.fields[i].collection[key], + }; + } }); } }