Skip to content

Commit

Permalink
fixed - prevent add existed items
Browse files Browse the repository at this point in the history
  • Loading branch information
vitPinchuk committed Feb 8, 2024
1 parent 81fac77 commit 922a3a4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/DatasetEditor/DatasetEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,21 @@ export const DatasetEditor: React.FC<Props> = ({ value, onChange, data }) => {
* Available Field Options
*/
const availableFieldOptions = useMemo(() => {
return data.reduce((acc: SelectableValue[], dataFrame) => {
return acc.concat(
dataFrame.fields.map((field) => ({
value: `${dataFrame.refId}:${field.name}`,
fieldName: field.name,
label: `${dataFrame.refId ? `${dataFrame.refId}:` : ''}${field.name}`,
source: dataFrame.refId,
}))
);
}, []);
}, [data]);
return data
.reduce((acc: SelectableValue[], dataFrame) => {
return acc.concat(
dataFrame.fields.map((field) => ({
value: `${dataFrame.refId}:${field.name}`,
fieldName: field.name,
label: `${dataFrame.refId ? `${dataFrame.refId}:` : ''}${field.name}`,
source: dataFrame.refId,
}))
);
}, [])
.filter((field) => {
return !items.find((item) => item.name === field.fieldName && item.source === field.source);
});
}, [items, data]);

/**
* Add New Item
Expand Down

0 comments on commit 922a3a4

Please sign in to comment.