-
Notifications
You must be signed in to change notification settings - Fork 928
feat: Workspaces filtering #1972
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
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d7c1318
feat: Workspaces filtering
f0ssel 5cb62d5
Remove error handling
f0ssel 09011d9
styling
f0ssel 11836ea
Apply suggestions from code review
f0ssel 568e3a6
pr fixes
f0ssel f1409b2
language
f0ssel f8e09e6
push up what I have
f0ssel 424e933
Add name filter to backend
f0ssel 5dbf5b4
Add name filter
f0ssel 2912d03
add backend
f0ssel 9ea5c14
fix
f0ssel 93a7d3c
Apply suggestions from code review
f0ssel 79e71f1
fmt
f0ssel 5f1ae06
Merge branch 'f0ssel/workspace-filter' of github.com:coder/coder into…
f0ssel 6b2999d
trim query
f0ssel 57fe5db
skip invalid key pairs
f0ssel 0a5d972
fix pq type
f0ssel 4aea7a0
fix tests
f0ssel 0dd5552
make gen
f0ssel 5d0d9bb
fix test
f0ssel 59e7d5e
flicker less
f0ssel 912b65c
some styling ideas (#2010)
Kira-Pilot 30a17e9
fix lower comparison
f0ssel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,169 @@ | ||
import Button from "@material-ui/core/Button" | ||
import Fade from "@material-ui/core/Fade" | ||
import InputAdornment from "@material-ui/core/InputAdornment" | ||
import Link from "@material-ui/core/Link" | ||
import Menu from "@material-ui/core/Menu" | ||
import MenuItem from "@material-ui/core/MenuItem" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import TextField from "@material-ui/core/TextField" | ||
import AddCircleOutline from "@material-ui/icons/AddCircleOutline" | ||
import SearchIcon from "@material-ui/icons/Search" | ||
import { useMachine } from "@xstate/react" | ||
import { FC } from "react" | ||
import { FormikErrors, useFormik } from "formik" | ||
import { FC, useState } from "react" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import { CloseDropdown, OpenDropdown } from "../../components/DropdownArrows/DropdownArrows" | ||
import { Margins } from "../../components/Margins/Margins" | ||
import { Stack } from "../../components/Stack/Stack" | ||
import { getFormHelpers, onChangeTrimmed } from "../../util/formUtils" | ||
import { workspacesMachine } from "../../xServices/workspaces/workspacesXService" | ||
import { WorkspacesPageView } from "./WorkspacesPageView" | ||
|
||
interface FilterFormValues { | ||
query: string | ||
} | ||
|
||
const Language = { | ||
filterName: "Filters", | ||
createWorkspaceButton: "Create workspace", | ||
yourWorkspacesButton: "Your workspaces", | ||
allWorkspacesButton: "All workspaces", | ||
} | ||
|
||
export type FilterFormErrors = FormikErrors<FilterFormValues> | ||
|
||
const WorkspacesPage: FC = () => { | ||
const [workspacesState] = useMachine(workspacesMachine) | ||
const styles = useStyles() | ||
const [workspacesState, send] = useMachine(workspacesMachine) | ||
|
||
const form = useFormik<FilterFormValues>({ | ||
initialValues: { | ||
query: workspacesState.context.filter || "", | ||
}, | ||
onSubmit: (values) => { | ||
send({ | ||
type: "SET_FILTER", | ||
query: values.query, | ||
}) | ||
}, | ||
}) | ||
|
||
const getFieldHelpers = getFormHelpers<FilterFormValues>(form) | ||
|
||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null) | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget) | ||
} | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null) | ||
} | ||
|
||
const setYourWorkspaces = () => { | ||
void form.setFieldValue("query", "owner:me") | ||
void form.submitForm() | ||
handleClose() | ||
} | ||
|
||
const setAllWorkspaces = () => { | ||
void form.setFieldValue("query", "") | ||
void form.submitForm() | ||
handleClose() | ||
} | ||
|
||
return ( | ||
<> | ||
<WorkspacesPageView | ||
loading={workspacesState.hasTag("loading")} | ||
workspaces={workspacesState.context.workspaces} | ||
error={workspacesState.context.getWorkspacesError} | ||
/> | ||
</> | ||
<Margins> | ||
<Stack direction="row" className={styles.workspacesHeaderContainer}> | ||
<Stack direction="column" className={styles.filterColumn}> | ||
<Stack direction="row" spacing={0} className={styles.filterContainer}> | ||
<Button | ||
aria-controls="filter-menu" | ||
aria-haspopup="true" | ||
onClick={handleClick} | ||
className={styles.buttonRoot} | ||
> | ||
{Language.filterName} {anchorEl ? <CloseDropdown /> : <OpenDropdown />} | ||
</Button> | ||
|
||
<form onSubmit={form.handleSubmit} className={styles.filterForm}> | ||
<TextField | ||
{...getFieldHelpers("query")} | ||
className={styles.textFieldRoot} | ||
onChange={onChangeTrimmed(form)} | ||
fullWidth | ||
variant="outlined" | ||
InputProps={{ | ||
startAdornment: ( | ||
<InputAdornment position="start"> | ||
<SearchIcon fontSize="small" /> | ||
</InputAdornment> | ||
), | ||
}} | ||
/> | ||
</form> | ||
|
||
<Menu | ||
id="filter-menu" | ||
anchorEl={anchorEl} | ||
keepMounted | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
TransitionComponent={Fade} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "left", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "left", | ||
}} | ||
> | ||
<MenuItem onClick={setYourWorkspaces}>{Language.yourWorkspacesButton}</MenuItem> | ||
<MenuItem onClick={setAllWorkspaces}>{Language.allWorkspacesButton}</MenuItem> | ||
</Menu> | ||
</Stack> | ||
</Stack> | ||
|
||
<Link underline="none" component={RouterLink} to="/workspaces/new"> | ||
<Button startIcon={<AddCircleOutline />} style={{ height: "44px" }}> | ||
{Language.createWorkspaceButton} | ||
</Button> | ||
</Link> | ||
</Stack> | ||
<WorkspacesPageView loading={workspacesState.hasTag("loading")} workspaces={workspacesState.context.workspaces} /> | ||
</Margins> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
workspacesHeaderContainer: { | ||
marginTop: theme.spacing(3), | ||
marginBottom: theme.spacing(3), | ||
justifyContent: "space-between", | ||
f0ssel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
filterColumn: { | ||
width: "60%", | ||
cursor: "text", | ||
}, | ||
filterContainer: { | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: "6px", | ||
}, | ||
filterForm: { | ||
width: "100%", | ||
}, | ||
buttonRoot: { | ||
border: "none", | ||
borderRight: `1px solid ${theme.palette.divider}`, | ||
borderRadius: "6px 0px 0px 6px", | ||
}, | ||
textFieldRoot: { | ||
margin: "0px", | ||
"& fieldset": { | ||
border: "none", | ||
}, | ||
}, | ||
})) | ||
|
||
export default WorkspacesPage |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.