From 9e085677b159be5263e6c168fbc007e0e680e618 Mon Sep 17 00:00:00 2001 From: ashrafchowdury Date: Tue, 3 Dec 2024 20:11:15 +0600 Subject: [PATCH] fix(frontend): show mappings after selecting testsets --- .../observability/drawer/TestsetDrawer.tsx | 195 +++++++++--------- 1 file changed, 102 insertions(+), 93 deletions(-) diff --git a/agenta-web/src/components/pages/observability/drawer/TestsetDrawer.tsx b/agenta-web/src/components/pages/observability/drawer/TestsetDrawer.tsx index 02d489dae7..68d4777167 100644 --- a/agenta-web/src/components/pages/observability/drawer/TestsetDrawer.tsx +++ b/agenta-web/src/components/pages/observability/drawer/TestsetDrawer.tsx @@ -117,6 +117,15 @@ const TestsetDrawer = ({onClose, data, ...props}: Props) => { setTableRows(data.csvdata) } } + + if (mappingOptions.length > 0 && value) { + setMappingData((prevMappingData) => + mappingOptions.map((item, index) => ({ + ...prevMappingData[index], + data: item.value, + })), + ) + } } catch (error) { message.error("Failed to laod Test sets!") } @@ -169,18 +178,6 @@ const TestsetDrawer = ({onClose, data, ...props}: Props) => { return Array.from(uniquePaths).map((item) => ({value: item})) }, [data]) - useEffect(() => { - // auto render mapping component with data - if (mappingOptions.length > 0) { - setMappingData((prevMappingData) => - mappingOptions.map((item, index) => ({ - ...prevMappingData[index], - data: item.value, - })), - ) - } - }, [mappingOptions]) - const columnOptions = useMemo(() => { const selectedColumns = mappingData .map((item) => item.column) @@ -435,99 +432,111 @@ const TestsetDrawer = ({onClose, data, ...props}: Props) => {
Mapping -
- {mappingData.map((data, idx) => ( -
- onMappingOptionChange({ - pathName: "column", + pathName: "data", value, idx, }) } - options={[ - ...(testset.id ? customSelectOptions : []), - ...columnOptions?.map((column) => ({ - value: column, - lable: column, - })), - ]} + options={mappingOptions} /> - )} - - {data.column === "create" || isNewTestset ? ( -
- - onMappingOptionChange({ - pathName: "newColumn", - value: e.target.value, - idx, - }) - } - placeholder="Column name" - /> - + +
+ {!isNewTestset && ( + + onMappingOptionChange({ + pathName: "newColumn", + value: e.target.value, + idx, + }) + } + placeholder="Column name" + /> + +
+ ) : null}
- ) : null} -
-
+ ))}
- ))} - - + + + ) : ( + + Please select a test set to create mappings + + )}