Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(ui): select all for vault import secret path Combobox (#7878)

claude[bot]21a8841267b4
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
index f4646e220c..185fd13b72 100644
--- a/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.stories.tsx
@@ -218,6 +218,39 @@ export const Multiple: Story = {
render: () => <MultipleRender />
};
+const SelectAllRender = () => {
+ const [value, setValue] = useState<(typeof PROJECTS)[number][]>([]);
+
+ return (
+ <Field>
+ <FieldLabel htmlFor="combobox-select-all-projects">Projects</FieldLabel>
+ <StoryCombobox
+ id="combobox-select-all-projects"
+ multiple
+ isSelectAll
+ options={PROJECTS}
+ value={value}
+ onValueChange={(options) => setValue(options)}
+ getOptionValue={(option) => option.id}
+ getOptionLabel={(option) => option.name}
+ placeholder="Select projects..."
+ searchPlaceholder="Search projects..."
+ searchAriaLabel="Search projects"
+ clearAriaLabel="Clear all projects"
+ />
+ </Field>
+ );
+};
+
+/**
+ * `isSelectAll` adds a toggle above the option list that selects every option
+ * matching the current search, then clears that same set once all are selected.
+ */
+export const SelectAll: Story = {
+ name: "Multiple: Select All",
+ render: () => <SelectAllRender />
+};
+
const SingleLineRender = () => {
const [value, setValue] = useState<(typeof PROJECTS)[number][]>(PROJECTS.slice(0, 12));
diff --git a/frontend/src/components/v3/generic/Combobox/Combobox.tsx b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
index a38578965d..0466ee1492 100644
--- a/frontend/src/components/v3/generic/Combobox/Combobox.tsx
+++ b/frontend/src/components/v3/generic/Combobox/Combobox.tsx
@@ -51,6 +51,7 @@ type ComboboxMultipleProps<TOption> = ComboboxSharedProps<TOption> &
> & {
multiple: true;
singleLine?: boolean;
+ isSelectAll?: boolean;
value?: readonly TOption[];
onValueChange: (options: TOption[]) => void;
onClear?: () => void;
@@ -61,6 +62,11 @@ type ComboboxProps<TOption> = ComboboxSingleProps<TOption> | ComboboxMultiplePro
const SINGLE_LIST_MAX_HEIGHT = "min(18.75rem, var(--available-height, 50dvh))";
const MULTIPLE_LIST_MAX_HEIGHT = "min(18.75rem, var(--available-height, 50dvh))";
+// Geometry and typography shared by every popup row, so the select-all action cannot
+// drift from the option rows it sits above.
+const COMBOBOX_ROW_CLASS =
+ "flex min-h-8 cursor-default items-center gap-2 rounded-sm py-1.5 text-sm text-foreground outline-hidden select-none";
+
const normalizeSearchText = (value: string) =>
value
.normalize("NFD")
@@ -139,7 +145,8 @@ const ComboboxList = <TOption,>({
value={option}
disabled={isOptionDisabled?.(option)}
className={cn(
- "relative flex min-h-8 cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm text-foreground outline-hidden select-none",
+ COMBOBOX_ROW_CLASS,
+ "relative pr-8 pl-2",
"data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[highlighted]:bg-foreground/5 data-[highlighted]:text-foreground"
)}
>
@@ -162,6 +169,33 @@ const ComboboxList = <TOption,>({
</>
);
+type ComboboxSelectAllProps = {
+ areAllSelected: boolean;
+ optionCount: number;
+ onToggle: () => void;
+};
+
+const ComboboxSelectAll = ({ areAllSelected, optionCount, onToggle }: ComboboxSelectAllProps) => (
+ <div className="border-b border-border p-1">
+ <button
+ type="button"
+ // Keep focus on the search input so the popup stays open after toggling.
+ onMouseDown={(event) => event.preventDefault()}
+ onClick={onToggle}
+ className={cn(
+ COMBOBOX_ROW_CLASS,
+ "w-full justify-between px-2",
+ "hover:bg-foreground/5 focus-visible:ring-2 focus-visible:ring-ring"
+ )}
+ >
+ <span className="truncate">
+ {areAllSelected ? "Clear Selection" : `Select All (${optionCount})`}
+ </span>
+ {areAllSelected && <CheckIcon className="size-4 shrink-0" />}
+ </button>
+ </div>
+);
+
type ComboboxPopupProps = {
anchor?: React.RefObject<HTMLElement | null>;
ariaLabel?: string;
@@ -384,6 +418,7 @@ const MultipleCombobox = <TOption,>({
onClear,
clearAriaLabel = "Clear all selections",
singleLine = false,
+ isSelectAll = false,
placeholder = "Select options...",
searchPlaceholder = "Search...",
searchAriaLabel = searchPlaceholder,
@@ -414,6 +449,31 @@ const MultipleCombobox = <TOption,>({
() => new Set(value.map(getOptionValue)),
[getOptionValue, value]
);
+ // Select all only covers the options matching the current search, so a filtered
+ // list toggles what is on screen instead of the entire option set.
+ const selectAllOptions = React.useMemo(
+ () =>
+ isSelectAll
+ ? items.filter((option) => !isOptionDisabled?.(option) && filter(option, search))
+ : [],
+ [filter, isOptionDisabled, isSelectAll, items, search]
+ );
+ const areAllOptionsSelected =
+ selectAllOptions.length > 0 &&
+ selectAllOptions.every((option) => selectedValues.has(getOptionValue(option)));
+
+ const handleSelectAllToggle = () => {
+ const selectAllValues = new Set(selectAllOptions.map(getOptionValue));
+
+ onValueChange(
+ areAllOptionsSelected
+ ? selectedOptions.filter((option) => !selectAllValues.has(getOptionValue(option)))
+ : [
+ ...selectedOptions,
+ ...selectAllOptions.filter((option) => !selectedValues.has(getOptionValue(option)))
+ ]
+ );
+ };
return (
<ComboboxPrimitive.Root<TOption, true>
@@ -547,6 +607,13 @@ const MultipleCombobox = <TOption,>({
className={contentClassName}
portalContainer={portalContainerProp}
>
+ {selectAllOptions.length > 0 && (
+ <ComboboxSelectAll
+ areAllSelected={areAllOptionsSelected}
+ optionCount={selectAllOptions.length}
+ onToggle={handleSelectAllToggle}
+ />
+ )}
<ComboboxList
emptyMessage={emptyMessage}
loadingMessage={loadingMessage}
diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
index 649c3c836b..4419a525d4 100644
--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/VaultSecretImportModal.tsx
@@ -204,6 +204,7 @@ const Content = ({ onClose, appConnections, onImport }: ContentProps) => {
<Combobox
id="vault-secret-import-paths"
multiple
+ isSelectAll
value={selectedPathOptions}
onValueChange={(options) =>
dispatch({ type: "selection", value: options.map(({ path }) => path) })