-
Notifications
You must be signed in to change notification settings - Fork 928
feat: Workspaces Page Query Filter #1936
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -6,38 +6,82 @@ import TableBody from "@material-ui/core/TableBody" | |
import TableCell from "@material-ui/core/TableCell" | ||
import TableHead from "@material-ui/core/TableHead" | ||
import TableRow from "@material-ui/core/TableRow" | ||
import TextField from "@material-ui/core/TextField/TextField" | ||
import AddCircleOutline from "@material-ui/icons/AddCircleOutline" | ||
import useTheme from "@material-ui/styles/useTheme" | ||
import dayjs from "dayjs" | ||
import relativeTime from "dayjs/plugin/relativeTime" | ||
import React from "react" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { AvatarData } from "../../components/AvatarData/AvatarData" | ||
import { Margins } from "../../components/Margins/Margins" | ||
import { Stack } from "../../components/Stack/Stack" | ||
import { getDisplayStatus } from "../../util/workspace" | ||
import React, { useCallback, useState } from "react" | ||
|
||
dayjs.extend(relativeTime) | ||
|
||
export const Language = { | ||
filterLabel: "Filter", | ||
createButton: "Create workspace", | ||
emptyView: "so you can check out your repositories, edit your source code, and build and test your software.", | ||
} | ||
|
||
export interface WorkspacesPageViewProps { | ||
loading?: boolean | ||
workspaces?: TypesGen.Workspace[] | ||
me?: TypesGen.User | ||
error?: unknown | ||
} | ||
|
||
export const WorkspacesPageView: React.FC<WorkspacesPageViewProps> = (props) => { | ||
const styles = useStyles() | ||
const theme: Theme = useTheme() | ||
const [filteredWorkspaces, setFilteredWorkspaces] = useState<TypesGen.Workspace[] | undefined>(props.workspaces) | ||
const [query, setQuery] = useState<string>("owner:me") | ||
const updateQuery = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const input = e.target.value | ||
setQuery(input) | ||
|
||
if (input.length && props.workspaces?.length) { | ||
const owners: string[] = [] | ||
const newWorkspaces: TypesGen.Workspace[] = [] | ||
const phrases = input.split(" ") | ||
for (const p of phrases) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually use things like |
||
if (p.startsWith("owner:")) { | ||
let v = p.slice("owner:".length) | ||
if (v === "me" && props.me) { | ||
v = props.me.username | ||
} | ||
owners.push(v) | ||
} | ||
} | ||
|
||
for (const w of props.workspaces) { | ||
for (const o of owners) { | ||
if (o === w.owner_name) { | ||
newWorkspaces.push(w) | ||
} | ||
} | ||
} | ||
setFilteredWorkspaces(newWorkspaces) | ||
} | ||
} | ||
const handleQueryChange = useCallback(updateQuery, [props.workspaces, props.me]) | ||
|
||
return ( | ||
<Stack spacing={4}> | ||
<Margins> | ||
<div className={styles.actions}> | ||
<form> | ||
<TextField | ||
onChange={handleQueryChange} | ||
value={query} | ||
fullWidth | ||
label="Filter" | ||
variant="outlined" | ||
/> | ||
</form> | ||
<Link underline="none" component={RouterLink} to="/workspaces/new"> | ||
<Button startIcon={<AddCircleOutline />}>{Language.createButton}</Button> | ||
</Link> | ||
|
@@ -53,7 +97,7 @@ export const WorkspacesPageView: React.FC<WorkspacesPageViewProps> = (props) => | |
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{!props.loading && !props.workspaces?.length && ( | ||
{!props.loading && !filteredWorkspaces?.length && ( | ||
<TableRow> | ||
<TableCell colSpan={999}> | ||
<div className={styles.welcome}> | ||
|
@@ -67,7 +111,7 @@ export const WorkspacesPageView: React.FC<WorkspacesPageViewProps> = (props) => | |
</TableCell> | ||
</TableRow> | ||
)} | ||
{props.workspaces?.map((workspace) => { | ||
{filteredWorkspaces?.map((workspace) => { | ||
const status = getDisplayStatus(theme, workspace.latest_build) | ||
return ( | ||
<TableRow key={workspace.id}> | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you only need one thing out of an xservice, it's better to
useSelector
.