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 @@ -369,19 +369,20 @@ describe("ChatsSidebar filters", () => {
});
});

it("keeps one chat status and one source selected", async () => {
it("resets a filter subset when its last option is cleared", async () => {
const user = userEvent.setup();
const onSidebarFiltersChange = vi.fn();
const sidebarFilters: AgentSidebarFilters = {
...defaultSidebarFilters,
chatStatuses: ["running"],
sources: ["shared_with_me"],
};

render(
<Wrapper>
<ChatsSidebar
{...defaultProps}
sidebarFilters={{
...defaultSidebarFilters,
chatStatuses: ["running"],
sources: ["shared_with_me"],
}}
sidebarFilters={sidebarFilters}
onSidebarFiltersChange={onSidebarFiltersChange}
/>
</Wrapper>,
Expand All @@ -392,7 +393,14 @@ describe("ChatsSidebar filters", () => {
await openFilterSubmenu(user, /Source/);
await chooseFilterOption("menuitemcheckbox", "Shared with me");

expect(onSidebarFiltersChange).not.toHaveBeenCalled();
expect(onSidebarFiltersChange).toHaveBeenNthCalledWith(1, {
...sidebarFilters,
chatStatuses: defaultSidebarFilters.chatStatuses,
});
expect(onSidebarFiltersChange).toHaveBeenNthCalledWith(2, {
...sidebarFilters,
sources: defaultSidebarFilters.sources,
});
});

it("applies the unread checkbox", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,12 @@ export const FilterPopover: FC<FilterPopoverProps> = ({
} else {
selected.delete(status);
}
if (selected.size === 0) {
return;
}
onFiltersChange({
...filters,
chatStatuses: AGENT_CHAT_STATUS_ORDER.filter((value) =>
selected.has(value),
),
chatStatuses:
selected.size === 0
? DEFAULT_AGENT_SIDEBAR_FILTERS.chatStatuses
: AGENT_CHAT_STATUS_ORDER.filter((value) => selected.has(value)),
});
};

Expand All @@ -206,11 +204,13 @@ export const FilterPopover: FC<FilterPopoverProps> = ({
)
: filters.sources.filter((value) => value !== source);

if (nextSources.length === 0) {
return;
}

onFiltersChange({ ...filters, sources: nextSources });
onFiltersChange({
...filters,
sources:
nextSources.length === 0
? DEFAULT_AGENT_SIDEBAR_FILTERS.sources
: nextSources,
});
};

const prSummary = !haveSameSelections(
Expand Down
Loading