From e954a57bce8400a2e27ad041030199e07c72679c Mon Sep 17 00:00:00 2001 From: nileshgulia1 Date: Fri, 3 Jun 2022 13:16:20 +0530 Subject: [PATCH] fix drag and drop --- .../theme/Widgets/DataProvenance.jsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/theme/Widgets/DataProvenance.jsx b/src/components/theme/Widgets/DataProvenance.jsx index ec149c1..4a9346f 100644 --- a/src/components/theme/Widgets/DataProvenance.jsx +++ b/src/components/theme/Widgets/DataProvenance.jsx @@ -16,7 +16,7 @@ import Schema from './schema'; import './style.css'; export const DataProvenance = (props) => { - const { id, value = {}, onChange, defaultData = {} } = props; + const { id, value = {}, onChange } = props; const predefinedSchema = Schema(props); const flatListValue = isArray(value) ? value : Object.values(value); return ( @@ -27,13 +27,13 @@ export const DataProvenance = (props) => { compact type="button" onClick={(e) => { - onChange(id, [ - ...flatListValue, - { - '@id': uuid(), - ...defaultData, + const newId = uuid(); + onChange(id, { + ...value, + [newId]: { + '@id': newId, }, - ]); + }); e.stopPropagation(); }} > @@ -55,7 +55,15 @@ export const DataProvenance = (props) => { flatListValue[destination.index] = first; flatListValue[source.index] = second; - onChange(id, flatListValue); + const obj = {}; + flatListValue.forEach( + (item) => (obj[item?.['@id'].toString()] = item), + ); + + onChange( + id, + flatListValue.reduce((a, v) => ({ ...a, [v['@id']]: v }), {}), + ); return true; }} >