Skip to content

Commit

Permalink
fix drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Jun 3, 2022
1 parent 2dff857 commit e954a57
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/components/theme/Widgets/DataProvenance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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();
}}
>
Expand All @@ -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;
}}
>
Expand Down

0 comments on commit e954a57

Please sign in to comment.