Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
f0ssel wants to merge2 commits intomainfromf0ssel/workspace-query-filter
Closed
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
fix query update
  • Loading branch information
@f0ssel
f0ssel committedMay 31, 2022
commit139e30637edfcaadbc956644fb66e28fe7b2bc56
11 changes: 9 additions & 2 deletionssite/src/pages/WorkspacesPage/WorkspacesPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
import { useMachine } from "@xstate/react"
import React from "react"
import { useMachine, useActor} from "@xstate/react"
import React, { useContext } from "react"
import { workspacesMachine } from "../../xServices/workspaces/workspacesXService"
import { WorkspacesPageView } from "./WorkspacesPageView"
import { XServiceContext } from "../../xServices/StateContext"

const WorkspacesPage: React.FC = () => {
const xServices = useContext(XServiceContext)
const [authState] = useActor(xServices.authXService)
const { me } = authState.context
Copy link
Contributor

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 touseSelector.


const [workspacesState] = useMachine(workspacesMachine)


return (
<>
<WorkspacesPageView
loading={workspacesState.hasTag("loading")}
workspaces={workspacesState.context.workspaces}
me={me}
error={workspacesState.context.getWorkspacesError}
/>
</>
Expand Down
54 changes: 33 additions & 21 deletionssite/src/pages/WorkspacesPage/WorkspacesPageView.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,46 +30,58 @@ export const Language = {
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:f0ssel")
const handleQueryChange = useCallback(() => {
setQuery((query) => query)
const [query, setQuery] = useState<string>("owner:me")
const updateQuery = (e: React.ChangeEvent<HTMLInputElement>) => {
const input = e.target.value
setQuery(input)

if (query.length && filteredWorkspaces?.length) {
const owners: string[] = []
const newWorkspacers: TypesGen.Workspace[] = []
const phrases = query.split(" ")
for (const p of phrases) {
if (p.startsWith("owner:")) {
owners.push(p.slice("owner:".length))
if (input.length && props.workspaces?.length) {
const owners: string[] = []
const newWorkspaces: TypesGen.Workspace[] = []
const phrases = input.split(" ")
for (const p of phrases) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We usually use things likemap andfilter instead of loops, and we're trying to avoidlet.

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 filteredWorkspaces) {
for (const o of owners) {
if (o === w.owner_name) {
newWorkspacers.push(w)
}
for (const w of props.workspaces) {
for (const o of owners) {
if (o === w.owner_name) {
newWorkspaces.push(w)
}
}
setFilteredWorkspaces(newWorkspacers)
}
}, [query, filteredWorkspaces])
setFilteredWorkspaces(newWorkspaces)
}
}
const handleQueryChange = useCallback(updateQuery, [props.workspaces, props.me])

return (
<Stack spacing={4}>
<Margins>
<div className={styles.actions}>
<TextField
onChange={handleQueryChange}
value={query}
/>
<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>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp