fix(web): remove node

This commit is contained in:
JzoNg 2026-04-29 16:17:31 +08:00
parent 35bfe26a3a
commit 9af2c1252c
2 changed files with 28 additions and 6 deletions

View File

@ -131,6 +131,23 @@ describe('MetricSection', () => {
expect(screen.getByText('Answer Node')).toBeInTheDocument()
})
it('should remove the builtin metric when removing its last selected node', () => {
// Arrange
act(() => {
useEvaluationStore.getState().addBuiltinMetric(resourceType, resourceId, 'answer-correctness', [
{ node_id: 'node-answer', title: 'Answer Node', type: 'llm' },
])
})
// Act
renderMetricSection()
fireEvent.click(screen.getByRole('button', { name: 'Answer Node' }))
// Assert
expect(screen.queryByText('Answer Correctness')).not.toBeInTheDocument()
expect(useEvaluationStore.getState().resources[`${resourceType}:${resourceId}`]!.metrics).toHaveLength(0)
})
it('should show only unselected nodes in the add-node dropdown and append the selected node', () => {
// Arrange
mockUseDefaultEvaluationMetrics.mockReturnValue({

View File

@ -39,6 +39,16 @@ const BuiltinMetricCard = ({
? availableNodeInfoList.filter(nodeInfo => !selectedNodeIdSet.has(nodeInfo.node_id))
: []
const shouldShowAddNode = selectableNodeInfoList.length > 0
const handleRemoveNode = (nodeId: string) => {
const nextSelectedNodeInfoList = selectedNodeInfoList.filter(item => item.node_id !== nodeId)
if (nextSelectedNodeInfoList.length === 0) {
removeMetric(resourceType, resourceId, metric.id)
return
}
updateBuiltinMetric(resourceType, resourceId, metric.optionId, nextSelectedNodeInfoList)
}
return (
<div className="group overflow-hidden rounded-xl border border-components-panel-border hover:bg-background-section">
@ -92,12 +102,7 @@ const BuiltinMetricCard = ({
type="button"
className="flex h-4 w-4 items-center justify-center rounded-sm text-text-quaternary transition-colors hover:text-text-secondary"
aria-label={nodeInfo.title}
onClick={() => updateBuiltinMetric(
resourceType,
resourceId,
metric.optionId,
selectedNodeInfoList.filter(item => item.node_id !== nodeInfo.node_id),
)}
onClick={() => handleRemoveNode(nodeInfo.node_id)}
>
<span aria-hidden="true" className="i-custom-vender-solid-general-x-circle h-3.5 w-3.5" />
</button>