Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions web/src/pages/agent/form/categorize-form/dynamic-categorize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { PlusOutlined } from '@ant-design/icons';
import { useUpdateNodeInternals } from '@xyflow/react';
import humanId from 'human-id';
import trim from 'lodash/trim';
import { ChevronsUpDown, X } from 'lucide-react';
import { ChevronsUpDown, ChevronDown, ChevronUp, X } from 'lucide-react';
import {
ChangeEventHandler,
FocusEventHandler,
Expand Down Expand Up @@ -181,7 +181,7 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
);
const form = useFormContext<z.infer<typeof FormSchema>>();
const { t } = useTranslate('flow');
const { fields, remove, append } = useFieldArray({
const { fields, remove, append, move} = useFieldArray({
name: 'items',
control: form.control,
});
Expand All @@ -206,6 +206,14 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
},
[deleteCategorizeCaseEdges, fields, nodeId, remove],
);
const handleMove = useCallback(
(from: number, to: number) => () => {
if (to < 0 || to >= fields.length) return;
move(from, to);
if (nodeId) updateNodeInternals(nodeId);
},
[fields.length, move, nodeId, updateNodeInternals],
);

return (
<div className="flex flex-col gap-4 ">
Expand All @@ -217,6 +225,26 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
</h4>
<CollapsibleTrigger asChild>
<div className="flex gap-4">
<Button
variant="ghost"
size="sm"
className="w-9 p-0"
onClick={handleMove(index, index - 1)}
disabled={index === 0}
title="Move up"
>
<ChevronUp className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
className="w-9 p-0"
onClick={handleMove(index, index + 1)}
disabled={index === fields.length - 1}
title="Move down"
>
<ChevronDown className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
Expand Down