Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,7 @@ export const FlowRunStateTriggerFields = () => {
const selectedDeploymentIds =
extractDeploymentIdsFromMatchRelated(matchRelated);

const handleFlowToggle = (flowId: string) => {
const currentFlowIds = selectedFlowIds;
const newFlowIds = currentFlowIds.includes(flowId)
? currentFlowIds.filter((id) => id !== flowId)
: [...currentFlowIds, flowId];

const handleFlowIdsChange = (newFlowIds: string[]) => {
// Clear tags when flows are selected (Vue behavior)
const newTags = newFlowIds.length > 0 ? [] : selectedTags;
form.setValue(
Expand Down Expand Up @@ -187,7 +182,7 @@ export const FlowRunStateTriggerFields = () => {
<FormControl>
<FlowMultiSelect
selectedFlowIds={selectedFlowIds}
onToggleFlow={handleFlowToggle}
onSelectFlowIds={handleFlowIdsChange}
emptyMessage="All flows"
/>
</FormControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@ const FlowMultiSelectWithState = ({
const [selectedFlowIds, setSelectedFlowIds] = useState<string[]>(
initialSelectedFlowIds,
);
const handleToggleFlow = (flowId: string) => {
setSelectedFlowIds((prev) =>
prev.includes(flowId)
? prev.filter((id) => id !== flowId)
: [...prev, flowId],
);
};

return (
<FlowMultiSelect
selectedFlowIds={selectedFlowIds}
onToggleFlow={handleToggleFlow}
onSelectFlowIds={setSelectedFlowIds}
emptyMessage={emptyMessage}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@ describe("FlowMultiSelect", () => {
const [selectedFlowIds, setSelectedFlowIds] = useState<string[]>(
initialSelectedFlowIds,
);
const handleToggleFlow = (flowId: string) => {
setSelectedFlowIds((prev) =>
prev.includes(flowId)
? prev.filter((id) => id !== flowId)
: [...prev, flowId],
);
};
return (
<FlowMultiSelect
selectedFlowIds={selectedFlowIds}
onToggleFlow={handleToggleFlow}
onSelectFlowIds={setSelectedFlowIds}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Selection behavior lacks regression coverage

Tests only verify labels and opening the list. Add coverage for selection, deselection, clearing, and checkbox state under the testing standard.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uinstinct Can you add a test or two to satisfy this review comment?

emptyMessage={emptyMessage}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import { useDeferredValue, useMemo, useState } from "react";
import { buildListFlowsQuery, type Flow } from "@/api/flows";
import { Checkbox } from "@/components/ui/checkbox";
import {
Combobox,
ComboboxCommandEmtpy,
Expand All @@ -16,13 +17,13 @@ const MAX_VISIBLE_FLOWS = 2;

type FlowMultiSelectProps = {
selectedFlowIds: string[];
onToggleFlow: (flowId: string) => void;
onSelectFlowIds: (flowIds: string[]) => void;
emptyMessage?: string;
};

export function FlowMultiSelect({
selectedFlowIds,
onToggleFlow,
onSelectFlowIds,
emptyMessage = "Any flow",
}: FlowMultiSelectProps) {
const [search, setSearch] = useState("");
Expand Down Expand Up @@ -70,7 +71,7 @@ export function FlowMultiSelect({

const renderSelectedFlows = () => {
if (selectedFlowIds.length === 0) {
return <span className="text-muted-foreground">{emptyMessage}</span>;
return emptyMessage;
}

const selectedFlowNames = selectedFlowsData
Expand All @@ -94,7 +95,7 @@ export function FlowMultiSelect({

return (
<Combobox>
<ComboboxTrigger selected={selectedFlowIds.length > 0}>
<ComboboxTrigger selected={selectedFlowIds.length === 0}>
{renderSelectedFlows()}
</ComboboxTrigger>
<ComboboxContent>
Expand All @@ -106,17 +107,31 @@ export function FlowMultiSelect({
<ComboboxCommandList>
<ComboboxCommandEmtpy>No flows found</ComboboxCommandEmtpy>
<ComboboxCommandGroup>
<ComboboxCommandItem
aria-label={emptyMessage}
onSelect={() => onSelectFlowIds([])}
closeOnSelect={false}
value="__all__"
>
<Checkbox checked={selectedFlowIds.length === 0} />
{emptyMessage}
</ComboboxCommandItem>
{filteredFlows.map((flow: Flow) => (
<ComboboxCommandItem
key={flow.id}
selected={selectedFlowIds.includes(flow.id)}
aria-label={flow.name}
onSelect={() => {
onToggleFlow(flow.id);
onSelectFlowIds(
selectedFlowIds.includes(flow.id)
? selectedFlowIds.filter((id) => id !== flow.id)
: [...selectedFlowIds, flow.id],
);
setSearch("");
}}
closeOnSelect={false}
value={flow.id}
>
<Checkbox checked={selectedFlowIds.includes(flow.id)} />
{flow.name}
</ComboboxCommandItem>
))}
Expand Down
Loading