From 2bb0eab63685c0aedbef3ddd8d827df1a5ed1178 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 3 Apr 2026 16:10:41 +0800 Subject: [PATCH] chore(web): mapping row refactor --- .../components/custom-metric-editor/index.tsx | 70 +---------------- .../custom-metric-editor/mapping-row.tsx | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+), 68 deletions(-) create mode 100644 web/app/components/evaluation/components/custom-metric-editor/mapping-row.tsx diff --git a/web/app/components/evaluation/components/custom-metric-editor/index.tsx b/web/app/components/evaluation/components/custom-metric-editor/index.tsx index e8d6b9f507d..04f4d9485d7 100644 --- a/web/app/components/evaluation/components/custom-metric-editor/index.tsx +++ b/web/app/components/evaluation/components/custom-metric-editor/index.tsx @@ -1,40 +1,21 @@ 'use client' -import type { CustomMetricMapping, EvaluationMetric, EvaluationResourceProps, EvaluationResourceType } from '../../types' +import type { EvaluationMetric, EvaluationResourceProps } from '../../types' import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import type { Node } from '@/app/components/workflow/types' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' -import { - Select, - SelectContent, - SelectGroup, - SelectGroupLabel, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/app/components/base/ui/select' import { BlockEnum } from '@/app/components/workflow/types' import { useAppWorkflow } from '@/service/use-workflow' -import { cn } from '@/utils/classnames' -import { getEvaluationMockConfig } from '../../mock' import { isCustomMetricConfigured, useEvaluationStore } from '../../store' -import { groupFieldOptions } from '../../utils' +import MappingRow from './mapping-row' import WorkflowSelector from './workflow-selector' type CustomMetricEditorCardProps = EvaluationResourceProps & { metric: EvaluationMetric } -type MappingRowProps = { - resourceType: EvaluationResourceType - mapping: CustomMetricMapping - targetOptions: Array<{ id: string, label: string }> - onUpdate: (patch: { sourceFieldId?: string | null, targetVariableId?: string | null }) => void - onRemove: () => void -} - const getWorkflowTargetVariables = ( nodes?: Array, ) => { @@ -56,53 +37,6 @@ const getWorkflowName = (workflow: { return workflow.marked_name || workflow.app_name || workflow.id } -function MappingRow({ - resourceType, - mapping, - targetOptions, - onUpdate, - onRemove, -}: MappingRowProps) { - const { t } = useTranslation('evaluation') - const config = getEvaluationMockConfig(resourceType) - - return ( -
- -
-
- - -
- ) -} - const CustomMetricEditorCard = ({ resourceType, resourceId, diff --git a/web/app/components/evaluation/components/custom-metric-editor/mapping-row.tsx b/web/app/components/evaluation/components/custom-metric-editor/mapping-row.tsx new file mode 100644 index 00000000000..782e67e3218 --- /dev/null +++ b/web/app/components/evaluation/components/custom-metric-editor/mapping-row.tsx @@ -0,0 +1,76 @@ +'use client' + +import type { CustomMetricMapping, EvaluationResourceType } from '../../types' +import { useTranslation } from 'react-i18next' +import Button from '@/app/components/base/button' +import { + Select, + SelectContent, + SelectGroup, + SelectGroupLabel, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/app/components/base/ui/select' +import { getEvaluationMockConfig } from '../../mock' +import { groupFieldOptions } from '../../utils' + +type MappingRowProps = { + resourceType: EvaluationResourceType + mapping: CustomMetricMapping + targetOptions: Array<{ id: string, label: string }> + onUpdate: (patch: { sourceFieldId?: string | null, targetVariableId?: string | null }) => void + onRemove: () => void +} + +const MappingRow = ({ + resourceType, + mapping, + targetOptions, + onUpdate, + onRemove, +}: MappingRowProps) => { + const { t } = useTranslation('evaluation') + const config = getEvaluationMockConfig(resourceType) + + return ( +
+ + +
+
+ + + + +
+ ) +} + +export default MappingRow