Skip to content

Commit

Permalink
Merge pull request #887 from JulianKniephoff/fix-bulk-editing-rendering
Browse files Browse the repository at this point in the history
Fix rendering of selection fields in metadata bulk editing
  • Loading branch information
Arnei authored Sep 5, 2024
2 parents f056769 + d696c72 commit b137dd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 45 deletions.
5 changes: 3 additions & 2 deletions src/slices/eventSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
prepareExtendedMetadataFieldsForPost,
prepareMetadataFieldsForPost,
transformMetadataCollection,
transformMetadataCollectionFields,
transformMetadataFields,
} from "../utils/resourceUtils";
import { makeTwoDigits } from "../utils/utils";
import { sourceMetadata } from "../configs/sourceConfig";
Expand Down Expand Up @@ -324,7 +324,8 @@ export const postEditMetadata = createAppAsyncThunk('events/postEditMetadata', a
let response = await data.data;

// transform response
const metadata = transformMetadataCollectionFields(response.metadata);
let metadata = transformMetadataFields(response.metadata)
.map(field => ({ ...field, selected: false }));
return {
mergedMetadata: metadata,
notFound: response.notFound,
Expand Down
67 changes: 24 additions & 43 deletions src/utils/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Recording } from "../slices/recordingSlice";
import { UserInfoState } from "../slices/userInfoSlice";
import { hasAccess, isJson } from "./utils";
import { RootState } from "../store";
import { MetadataCatalog, MetadataField, MetadataFieldSelected } from "../slices/eventSlice";
import { MetadataCatalog, MetadataField } from "../slices/eventSlice";
import { initialFormValuesNewGroup } from '../configs/modalConfig';
import { UpdateUser } from '../slices/userDetailsSlice';
import { TFunction } from 'i18next';
Expand Down Expand Up @@ -149,52 +149,33 @@ export const getInitialMetadataFieldValues = (

// transform collection of metadata into object with name and value
export const transformMetadataCollection = (metadata: MetadataCatalog) => {
for (const [i, field] of metadata.fields.entries()) {
if (!!field.collection) {
metadata.fields[i].collection = Object.entries(
field.collection
).map(([key, value]) => {
if (isJson(key)) {
let collectionParsed = JSON.parse(key);
return {
name: collectionParsed.label ? collectionParsed.label : key,
value: value,
...collectionParsed,
};
} else {
return {
name: key,
value: value,
};
}
});
}
}

transformMetadataFields(metadata.fields);
return metadata;
}

// Same as above, but different!
export const transformMetadataCollectionFields = (metadata: MetadataFieldSelected[]) => {
for (const [i, field] of metadata.entries()) {
if (!!field) {
metadata[i].collection = Object.entries(field).map(
([key, value]) => {
return {
name: key,
value: value,
};
}
);
};

export const transformMetadataFields = (metadata: MetadataField[]) => {
for (const field of metadata) {
if (field.collection) {
field.collection = Object.entries(field.collection)
.map(([key, value]) => {
if (isJson(key)) {
let collectionParsed = JSON.parse(key);
return {
name: collectionParsed.label || key,
value,
...collectionParsed,
};
} else {
return {
name: key,
value: value,
};
}
});
}
metadata[i] = {
...metadata[i],
selected: false,
};
}

return metadata;
}
};

// transform metadata catalog for update via post request
export const transformMetadataForUpdate = (catalog: MetadataCatalog, values: { [key: string]: MetadataCatalog["fields"][0]["value"] }) => {
Expand Down

0 comments on commit b137dd1

Please sign in to comment.