From 922a3a43db246ae8d793d0bdedef5f619841710d Mon Sep 17 00:00:00 2001 From: Vitali Pinchuk Date: Thu, 8 Feb 2024 13:04:32 +0300 Subject: [PATCH] fixed - prevent add existed items --- .../DatasetEditor/DatasetEditor.tsx | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/DatasetEditor/DatasetEditor.tsx b/src/components/DatasetEditor/DatasetEditor.tsx index 0602c4a..71b5777 100644 --- a/src/components/DatasetEditor/DatasetEditor.tsx +++ b/src/components/DatasetEditor/DatasetEditor.tsx @@ -99,17 +99,21 @@ export const DatasetEditor: React.FC = ({ 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