Skip to content

Commit a6a6032

Browse files
committed
Only persist rootOnly when no tasks are filtered
1 parent 2ff11f1 commit a6a6032

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

  • apps/webapp/app
    • components/runs/v3
    • routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs._index

apps/webapp/app/components/runs/v3/RunFilters.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,6 @@ export function RunsFilters(props: RunFiltersProps) {
370370
<FilterMenu {...props} />
371371
{hasFilters && (
372372
<Form className="-ml-1 h-6">
373-
{searchParams.has("rootOnly") && (
374-
<input type="hidden" name="rootOnly" value={searchParams.get("rootOnly") as string} />
375-
)}
376373
<Button
377374
variant="minimal/small"
378375
LeadingIcon={XMarkIcon}
@@ -677,14 +674,17 @@ function TasksDropdown({
677674
const previousTasks = values("tasks");
678675
const wasEmpty = previousTasks.length === 0 || previousTasks.every((v) => v === "");
679676
const isEmpty = newValues.length === 0 || newValues.every((v) => v === "");
680-
// When transitioning from no tasks to tasks, force rootOnly off so users
681-
// see the runs of the task they just selected (root or otherwise).
677+
// empty -> tasks: temporarily force rootOnly off so child runs of the selected
678+
// task are visible. tasks -> empty: drop rootOnly so the toggle reverts to the
679+
// user's saved session preference. Neither writes to the cookie (see loader).
682680
const transitioningToTasks = wasEmpty && !isEmpty;
681+
const transitioningToNoTasks = !wasEmpty && isEmpty;
683682
replace({
684683
tasks: newValues,
685684
cursor: undefined,
686685
direction: undefined,
687686
...(transitioningToTasks ? { rootOnly: "false" } : {}),
687+
...(transitioningToNoTasks ? { rootOnly: undefined } : {}),
688688
});
689689
};
690690

@@ -770,7 +770,7 @@ function PermanentTasksFilter({ possibleTasks }: Pick<RunFiltersProps, "possible
770770
return task ? task.slug : v;
771771
})
772772
)}
773-
onRemove={() => del(["tasks", "cursor", "direction"])}
773+
onRemove={() => del(["tasks", "cursor", "direction", "rootOnly"])}
774774
variant="secondary/small"
775775
className="pl-1"
776776
/>

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs._index/route.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,26 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
9494
...filters,
9595
});
9696

97-
const session = await setRootOnlyFilterPreference(filters.rootOnly, request);
98-
const cookieValue = await uiPreferencesStorage.commitSession(session);
97+
// Only persist rootOnly when no tasks are filtered. While a task filter is active,
98+
// the toggle's URL value can be a temporary auto-flip (or a user override scoped to
99+
// the current task filter), and we don't want either bleeding into the saved
100+
// session preference. Clearing the task filter restores the saved preference.
101+
const shouldPersistRootOnly = !filters.tasks || filters.tasks.length === 0;
102+
const headers = shouldPersistRootOnly
103+
? {
104+
"Set-Cookie": await uiPreferencesStorage.commitSession(
105+
await setRootOnlyFilterPreference(filters.rootOnly, request)
106+
),
107+
}
108+
: undefined;
99109

100110
return typeddefer(
101111
{
102112
data: list,
103113
rootOnlyDefault: filters.rootOnly,
104114
filters,
105115
},
106-
{
107-
headers: {
108-
"Set-Cookie": cookieValue,
109-
},
110-
}
116+
headers ? { headers } : undefined
111117
);
112118
};
113119

0 commit comments

Comments
 (0)