Skip to content

Commit 8c3a29c

Browse files
priya-tikArnei
andauthored
Fix clean metadata (#1235)
* fix metadata payload structure for update request * implement suggested improvements from PR review * Undo unrelated style changes and remove leftover code --------- Co-authored-by: Arnei <arnewilken@yahoo.de>
1 parent 15d8814 commit 8c3a29c

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/utils/resourceUtils.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,28 @@ export const transformListProvider = (collection: { [key: string]: string }) =>
199199
};
200200

201201
// transform metadata catalog for update via post request
202-
export const transformMetadataForUpdate = (catalog: MetadataCatalog, values: { [key: string]: MetadataCatalog["fields"][0]["value"] }) => {
202+
export const transformMetadataForUpdate = (
203+
catalog: MetadataCatalog,
204+
values: { [key: string]: MetadataCatalog["fields"][0]["value"] },
205+
) => {
203206
const fields: MetadataCatalog["fields"] = [];
204-
const updatedFields: MetadataCatalog["fields"] = [];
205-
207+
const updatedFields: { id: string; value: unknown }[] = [];
206208
catalog.fields.forEach(field => {
207-
if (field.value !== values[field.id]) {
208-
const updatedField = {
209-
...field,
210-
value: values[field.id],
211-
};
212-
updatedFields.push(updatedField);
213-
fields.push(updatedField);
214-
} else {
215-
fields.push({ ...field });
209+
const newValue = values[field.id];
210+
211+
// update UI state with full field (optional)
212+
const fullField = { ...field, value: newValue };
213+
fields.push(fullField);
214+
215+
// only include minimal clean data for backend if value changed
216+
if (field.value !== newValue) {
217+
updatedFields.push({
218+
id: field.id,
219+
value: newValue,
220+
});
216221
}
217222
});
223+
218224
const data = new URLSearchParams();
219225
data.append(
220226
"metadata",
@@ -280,7 +286,11 @@ export const prepareMetadataFieldsForPost = (
280286
};
281287

282288
// returns the name for a field value from the collection
283-
export const getMetadataCollectionFieldName = (metadataField: { collection?: { [key: string]: unknown }[] }, field: { value: unknown }, t: TFunction): string => {
289+
export const getMetadataCollectionFieldName = (
290+
metadataField: { collection?: { [key: string]: unknown }[] },
291+
field: { value: unknown },
292+
t: TFunction,
293+
) => {
284294
try {
285295
if (metadataField.collection) {
286296
const collectionField = metadataField.collection.find(
@@ -306,8 +316,8 @@ export const getMetadataCollectionFieldName = (metadataField: { collection?: { [
306316
// Prepare rules of access policies for post of new events or series
307317
export const prepareAccessPolicyRulesForPost = (policies: TransformedAcl[]) => {
308318
// access policies for post request
309-
const access : {
310-
acl : Acl
319+
const access: {
320+
acl: Acl
311321
} = {
312322
acl: {
313323
ace: [],

0 commit comments

Comments
 (0)