Skip to content

fix: Show correct 'no results' message on workspace filters #2103

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 7 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
feat: save workspace filter in url
  • Loading branch information
f0ssel committed Jun 7, 2022
commit 562ea922ea10de20db40e2fa09fdd9201abdf6e5
21 changes: 16 additions & 5 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { useMachine } from "@xstate/react"
import { FC } from "react"
import { FC, useEffect } from "react"
import { Helmet } from "react-helmet"
import { useSearchParams } from "react-router-dom"
import { pageTitle } from "../../util/page"
import { workspaceFilterQuery } from "../../util/workspace"
import { workspacesMachine } from "../../xServices/workspaces/workspacesXService"
import { WorkspacesPageView } from "./WorkspacesPageView"

const WorkspacesPage: FC = () => {
const [workspacesState, send] = useMachine(workspacesMachine)
const [searchParams, setSearchParams] = useSearchParams()

useEffect(() => {
const filter = searchParams.get("filter")
const query = filter ? filter : workspaceFilterQuery.me

send({
type: "SET_FILTER",
query,
})
}, [searchParams, send])

return (
<>
Expand All @@ -19,10 +32,8 @@ const WorkspacesPage: FC = () => {
loading={workspacesState.hasTag("loading")}
workspaces={workspacesState.context.workspaces}
onFilter={(query) => {
send({
type: "SET_FILTER",
query,
})
searchParams.set("filter", query)
setSearchParams(searchParams)
}}
/>
</>
Expand Down
12 changes: 10 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentMeta, Story } from "@storybook/react"
import { ProvisionerJobStatus, Workspace, WorkspaceTransition } from "../../api/typesGenerated"
import { MockWorkspace } from "../../testHelpers/entities"
import { WorkspacesPageView, WorkspacesPageViewProps } from "./WorkspacesPageView"
import { workspaceFilterQuery } from "../../util/workspace"

export default {
title: "pages/WorkspacesPageView",
Expand Down Expand Up @@ -48,7 +49,14 @@ AllStates.args = {
],
}

export const Empty = Template.bind({})
Empty.args = {
export const OwnerHasNoWorkspaces = Template.bind({})
OwnerHasNoWorkspaces.args = {
workspaces: [],
filter: workspaceFilterQuery.me,
}

export const NoResults = Template.bind({})
NoResults.args = {
workspaces: [],
filter: "searchtearmwithnoresults",
}
1 change: 1 addition & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const WorkspacesPageView: FC<WorkspacesPageViewProps> = ({ loading, works
const theme: Theme = useTheme()

const form = useFormik<FilterFormValues>({
enableReinitialize: true,
initialValues: {
query: filter ?? "",
},
Expand Down
5 changes: 1 addition & 4 deletions site/src/xServices/workspaces/workspacesXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export const workspacesMachine = createMachine(
},
},
id: "workspaceState",
context: {
filter: "owner:me",
},
initial: "gettingWorkspaces",
initial: "ready",
states: {
ready: {
on: {
Expand Down