Skip to content

refactor(site): Improve workspaces filtering #7681

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

Merged
merged 25 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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 debounce
  • Loading branch information
BrunoQuaresma committed May 25, 2023
commit 92c628cdd9f44b13c09df65461527b0a5a15ad9a
3 changes: 3 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable eslint-comments/disable-enable-pair -- ignore */
/* eslint-disable @typescript-eslint/no-explicit-any -- We don't care about any here */
import { ComponentMeta, Story } from "@storybook/react"
import { DEFAULT_RECORDS_PER_PAGE } from "components/PaginationWidget/utils"
import dayjs from "dayjs"
Expand Down Expand Up @@ -86,6 +88,7 @@ const defaultFilterProps = {
filter: {
query: `owner:${MockUser.username}`,
update: () => action("update"),
debounceUpdate: action("debounce") as any,
values: {
owner: MockUser.username,
template: undefined,
Expand Down
106 changes: 53 additions & 53 deletions site/src/pages/WorkspacesPage/filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
StatusOption,
BaseOption,
} from "./options"
import debounce from "just-debounce-it"

export type FilterValues = {
owner?: string // User["username"]
Expand Down Expand Up @@ -64,9 +65,15 @@ export const useFilter = ({
}
}

const debounceUpdate = debounce(
(values: string | FilterValues) => update(values),
500,
)

return {
query,
update,
debounceUpdate,
values,
}
}
Expand Down Expand Up @@ -160,61 +167,54 @@ export const Filter = ({

return (
<Box display="flex" sx={{ gap: 1, mb: 2 }}>
<Box
component="form"
sx={{ width: "100%" }}
onSubmit={(e) => {
e.preventDefault()
const formData = new FormData(e.currentTarget)
const query = formData.get("query") as string
filter.update(query)
}}
>
<TextField
fullWidth
error={shouldDisplayError}
helperText={
shouldDisplayError ? getValidationErrorMessage(error) : undefined
}
size="small"
InputProps={{
name: "query",
placeholder: "Search...",
value: searchQuery,
onChange: (e) => setSearchQuery(e.target.value),
sx: {
borderRadius: "6px",
"& input::placeholder": {
color: (theme) => theme.palette.text.secondary,
},
<TextField
fullWidth
error={shouldDisplayError}
helperText={
shouldDisplayError ? getValidationErrorMessage(error) : undefined
}
size="small"
InputProps={{
name: "query",
placeholder: "Search...",
value: searchQuery,
onChange: (e) => {
setSearchQuery(e.target.value)
filter.debounceUpdate(e.target.value)
},
sx: {
borderRadius: "6px",
"& input::placeholder": {
color: (theme) => theme.palette.text.secondary,
},
startAdornment: (
<InputAdornment position="start">
<SearchOutlined
sx={{
fontSize: 14,
color: (theme) => theme.palette.text.secondary,
},
startAdornment: (
<InputAdornment position="start">
<SearchOutlined
sx={{
fontSize: 14,
color: (theme) => theme.palette.text.secondary,
}}
/>
</InputAdornment>
),
endAdornment: hasFilterQuery && (
<InputAdornment position="end">
<Tooltip title="Clear filter">
<IconButton
size="small"
onClick={() => {
filter.update("")
}}
/>
</InputAdornment>
),
endAdornment: hasFilterQuery && (
<InputAdornment position="end">
<Tooltip title="Clear filter">
<IconButton
size="small"
onClick={() => {
filter.update("")
}}
>
<CloseOutlined sx={{ fontSize: 14 }} />
</IconButton>
</Tooltip>
</InputAdornment>
),
}}
/>
</Box>
>
<CloseOutlined sx={{ fontSize: 14 }} />
</IconButton>
</Tooltip>
</InputAdornment>
),
}}
/>

{autocomplete.users && <OwnerFilter autocomplete={autocomplete.users} />}
<TemplatesFilter autocomplete={autocomplete.templates} />
<StatusFilter autocomplete={autocomplete.status} />
Expand Down