Skip to content

Commit

Permalink
Fix license strings not being translated in metadata dropdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Arnei committed Jun 5, 2024
1 parent d01c96b commit 6e2fe6c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/shared/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/wizard/RenderField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dropDownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 15 additions & 7 deletions src/utils/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand All @@ -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],
};
}
});
}
}
Expand Down

0 comments on commit 6e2fe6c

Please sign in to comment.