Skip to content

chore(site): refactor filters #13394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d7a4be0
Add base structure for the new filter component
BrunoQuaresma May 15, 2024
f6df4fa
Add error state
BrunoQuaresma May 15, 2024
d41d307
Simplify component
BrunoQuaresma May 15, 2024
47fd44b
Make it accessible
BrunoQuaresma May 15, 2024
d28e9b4
Add simple dropdown button component
BrunoQuaresma May 15, 2024
16bbf5a
Refactor search and add preset filter menu
BrunoQuaresma May 15, 2024
5d8829e
Add status menu
BrunoQuaresma May 15, 2024
c89cf8c
Add status menu to workspaces search
BrunoQuaresma May 15, 2024
0c501e5
WIP: Create base UserMenu
BrunoQuaresma May 17, 2024
c38cd7b
Finish user menu
BrunoQuaresma May 24, 2024
38b10a5
Add search
BrunoQuaresma May 24, 2024
3797ae9
Refactor search field to be more extensible
BrunoQuaresma May 24, 2024
b552828
Extract reusable menu elements
BrunoQuaresma May 24, 2024
498f6cd
Simplify usage
BrunoQuaresma May 24, 2024
de83eda
Improve MenuSearch component
BrunoQuaresma May 24, 2024
c2aa478
Keep search fixed on top
BrunoQuaresma May 24, 2024
30a8373
Add more tests
BrunoQuaresma May 24, 2024
542c377
Merge branch 'main' of https://github.com/coder/coder into bq/improve…
BrunoQuaresma May 28, 2024
01a6616
Handle filtering
BrunoQuaresma May 28, 2024
e97ce00
Add focus on arrow down
BrunoQuaresma May 28, 2024
7638595
Add template menu
BrunoQuaresma May 28, 2024
76224c3
Merge branch 'main' of https://github.com/coder/coder into bq/improve…
BrunoQuaresma May 29, 2024
6d1ce99
Use users paginated request
BrunoQuaresma May 29, 2024
d3c9ef5
Remove forgotten debuggers
BrunoQuaresma May 29, 2024
3250b48
Merge branch 'main' of https://github.com/coder/coder into bq/improve…
BrunoQuaresma Jun 7, 2024
d1b71b1
Remove unecessary prop
BrunoQuaresma Jun 7, 2024
a804a40
Apply michaels review
BrunoQuaresma Jun 7, 2024
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
Prev Previous commit
Next Next commit
Add status menu to workspaces search
  • Loading branch information
BrunoQuaresma committed May 15, 2024
commit c89cf8cb0c455d2f821cde2a919ef0420905ef09
2 changes: 1 addition & 1 deletion site/src/components/Search/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SearchField: FC<SearchFieldProps> = (props) => {
}}
fullWidth
placeholder="Search..."
css={{ fontSize: 14, height: "100%" }}
css={{ fontSize: 14, height: "100%", flex: 1 }}
value={value}
onChange={(e) => {
onChange(e.currentTarget.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ export const SelectPresetFilter: Story = {
await expect(input).toHaveValue("failed:true");
},
};

export const SelectStatus: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole("button", { name: /Select status/i });
await userEvent.click(button);
const option = canvas.getByText("Running");
await userEvent.click(option);
const input = canvas.getByLabelText("Search workspace");
await expect(input).toHaveValue("status:failed");
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FC } from "react";
import { SearchField } from "components/Search/SearchField";
import { Stack } from "components/Stack/Stack";
import { PresetFiltersMenu } from "./PresetFiltersMenu";
import { StatusMenu } from "./StatusMenu";

type WorkspaceSearchProps = {
query: string;
Expand All @@ -12,8 +13,19 @@ export const WorkspaceSearch: FC<WorkspaceSearchProps> = ({
query,
setQuery,
}) => {
const status = findTagValue(query, "status");

return (
<Stack alignItems="center" direction="row" spacing={1}>
<Stack
alignItems="center"
direction="row"
spacing={1}
css={{
"& > *": {
flexShrink: 0,
},
}}
>
<PresetFiltersMenu onSelect={setQuery} />

<SearchField
Expand All @@ -22,6 +34,40 @@ export const WorkspaceSearch: FC<WorkspaceSearchProps> = ({
value={query}
onChange={setQuery}
/>

<StatusMenu
placeholder="All statuses"
selected={status}
onSelect={(status) => {
setQuery(replaceOrAddTagValue(query, "status", status));
}}
/>
</Stack>
);
};

function findTagValue(query: string, tag: string): string | undefined {
const blocks = query.split(" ");
const block = blocks.find((block) => block.startsWith(`${tag}:`));

if (!block) {
return;
}

return block.split(":")[1];
}

function replaceOrAddTagValue(
query: string,
tag: string,
value: string,
): string {
const blocks = query.split(" ");
const block = blocks.find((block) => block.startsWith(`${tag}:`));

if (block) {
return query.replace(block, `${tag}:${value}`);
}

return `${query} ${tag}:${value}`;
}