RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
feat(ui): add locked option support to MultiSelect component (#19658)
chanxe4f239a48399
diff --git a/web/src/components/ui/__tests__/multi-select.test.tsx b/web/src/components/ui/__tests__/multi-select.test.tsxindex 437bf372d0..0ea984464a 100644--- a/web/src/components/ui/__tests__/multi-select.test.tsx+++ b/web/src/components/ui/__tests__/multi-select.test.tsx@@ -118,3 +118,80 @@ describe('MultiSelect disabled options', () => {expect(onValueChange).toHaveBeenCalledWith(['b']);});});++describe('MultiSelect locked options', () => {+ const options = [+ { label: 'Alpha', value: 'a', locked: true },+ { label: 'Beta', value: 'b' },+ { label: 'Gamma', value: 'c' },+ ];++ it('select all includes locked options', () => {+ const onValueChange = jest.fn();+ render(+ <MultiSelect+ options={options}+ defaultValue={[]}+ onValueChange={onValueChange}+ />,+ );++ fireEvent.click(screen.getByRole('button'));+ fireEvent.click(document.querySelector('[cmdk-item]')!);+ expect(onValueChange).toHaveBeenCalledWith(['a', 'b', 'c']);+ });++ it('locked options cannot be deselected by clicking', () => {+ const onValueChange = jest.fn();+ render(+ <MultiSelect+ options={options}+ defaultValue={['a', 'b']}+ onValueChange={onValueChange}+ />,+ );++ fireEvent.click(screen.getByRole('button'));+ // Click on the locked option 'a'+ const lockedOption = Array.from(+ document.querySelectorAll('[role="option"]'),+ ).find((el) => el.textContent?.includes('Alpha'));+ fireEvent.click(lockedOption!);+ // Should still be ['a', 'b'] because 'a' is locked+ expect(onValueChange).not.toHaveBeenCalled();+ });++ it('locked options cannot be removed via badge remove icon', () => {+ const onValueChange = jest.fn();+ render(+ <MultiSelect+ options={options}+ defaultValue={['a', 'b']}+ onValueChange={onValueChange}+ />,+ );++ const badgeRow = screen.getByText('Alpha').parentElement!;+ const removeIcon = badgeRow.querySelector('svg.lucide-circle-x');+ expect(removeIcon).toBeTruthy();++ fireEvent.click(removeIcon!);+ // Should not be called because 'a' is locked+ expect(onValueChange).not.toHaveBeenCalled();+ });++ it('clear keeps locked options', () => {+ const onValueChange = jest.fn();+ const { container } = render(+ <MultiSelect+ options={options}+ defaultValue={['a', 'b', 'c']}+ onValueChange={onValueChange}+ />,+ );++ fireEvent.click(container.querySelector('svg.lucide-x')!);+ // Only locked option 'a' should remain+ expect(onValueChange).toHaveBeenCalledWith(['a']);+ });+});diff --git a/web/src/components/ui/multi-select.tsx b/web/src/components/ui/multi-select.tsxindex b3b8554f47..3440344f43 100644--- a/web/src/components/ui/multi-select.tsx+++ b/web/src/components/ui/multi-select.tsx@@ -37,6 +37,12 @@ export type MultiSelectOptionType = {label: React.ReactNode;value: string;disabled?: boolean;+ /**+ * When true, the option is always selected and cannot be deselected.+ * Unlike `disabled`, locked options are included in "Select All" and+ * preserved when clearing.+ */+ locked?: boolean;suffix?: React.ReactNode;icon?: React.ComponentType<{ className?: string }>;};@@ -288,9 +294,17 @@ export const MultiSelect = React.forwardRef<);}, [flatOptions]);+ const lockedValueSet = React.useMemo(() => {+ return new Set(+ flatOptions+ .filter((option) => option.locked)+ .map((option) => option.value),+ );+ }, [flatOptions]);+const selectableValues = React.useMemo(() => {return flatOptions- .filter((option) => !option.disabled)+ .filter((option) => !option.disabled || option.locked).map((option) => option.value);}, [flatOptions]);@@ -301,7 +315,11 @@ export const MultiSelect = React.forwardRef<// A disabled option can't be picked in the dropdown, but a value that is// already selected must stay removable — e.g. a knowledge base that had// chunks when it was picked may have been emptied since.+ // Locked options cannot be removed.const removeValue = (value: string) => {+ if (lockedValueSet.has(value)) {+ return;+ }const newSelectedValues = selectedValues.filter((v) => v !== value);setSelectedValues(newSelectedValues);onValueChange(newSelectedValues);@@ -324,6 +342,10 @@ export const MultiSelect = React.forwardRef<if (disabledValueSet.has(option)) {return;}+ // Locked options cannot be deselected+ if (lockedValueSet.has(option) && selectedValues.includes(option)) {+ return;+ }const newSelectedValues = selectedValues.includes(option)? selectedValues.filter((value) => value !== option)@@ -333,8 +355,12 @@ export const MultiSelect = React.forwardRef<};const handleClear = () => {- setSelectedValues([]);- onValueChange([]);+ // Keep locked options that are currently selected+ const lockedSelectedValues = selectedValues.filter((value) =>+ lockedValueSet.has(value),+ );+ setSelectedValues(lockedSelectedValues);+ onValueChange(lockedSelectedValues);};const handleTogglePopover = () => {diff --git a/web/src/pages/memories/constants/index.tsx b/web/src/pages/memories/constants/index.tsxindex 64ceeac5d0..797274d549 100644--- a/web/src/pages/memories/constants/index.tsx+++ b/web/src/pages/memories/constants/index.tsx@@ -11,7 +11,7 @@ export enum MemoryType {Procedural = 'procedural',}export const MemoryOptions = (t: TFunction) => [- { label: t('memories.raw'), value: MemoryType.Raw, disabled: true },+ { label: t('memories.raw'), value: MemoryType.Raw, locked: true },{ label: t('memories.semantic'), value: MemoryType.Semantic },{ label: t('memories.episodic'), value: MemoryType.Episodic },{ label: t('memories.procedural'), value: MemoryType.Procedural },