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
Regreats and improvements
  • Loading branch information
BrunoQuaresma committed May 23, 2023
commit 1341444cadbe86a484b62ec4bf3b6522959f42e7
22 changes: 20 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ import { workspaceFilterQuery } from "utils/filters"
import { pageTitle } from "utils/page"
import { useWorkspacesData, useWorkspaceUpdate } from "./data"
import { WorkspacesPageView } from "./WorkspacesPageView"
import { useQuery } from "@tanstack/react-query"
import { getTemplates, getUsers } from "api/api"
import { useOrganizationId } from "hooks"

const WorkspacesPage: FC = () => {
const filter = useFilter(workspaceFilterQuery.me)
const pagination = usePagination()
const orgId = useOrganizationId()

const { data, error, queryKey } = useWorkspacesData({
...pagination,
...filter,
})
const updateWorkspace = useWorkspaceUpdate(queryKey)
const { data: users } = useQuery({
queryKey: ["users"],
queryFn: () => getUsers({ limit: 100 }).then((res) => res.users),
})
const { data: templates } = useQuery({
queryKey: ["templates"],
queryFn: () => getTemplates(orgId),
})

return (
<>
Expand All @@ -26,15 +38,21 @@ const WorkspacesPage: FC = () => {
<WorkspacesPageView
workspaces={data?.workspaces}
error={error}
filterQuery={filter.query}
onFilterQueryChange={filter.setFilter}
count={data?.count}
page={pagination.page}
limit={pagination.limit}
onPageChange={pagination.goToPage}
onUpdateWorkspace={(workspace) => {
updateWorkspace.mutate(workspace)
}}
filterProps={{
query: filter.query,
onQueryChange: filter.setFilter,
onLoadTemplates: () => {},
onLoadUsers: () => {},
users,
templates,
}}
/>
</>
)
Expand Down
19 changes: 17 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
WorkspacesPageViewProps,
} from "./WorkspacesPageView"
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider"
import { action } from "@storybook/addon-actions"

const createWorkspace = (
status: WorkspaceStatus,
Expand Down Expand Up @@ -69,12 +70,24 @@ const MockedAppearance = {
save: () => null,
}

const defaultFilterProps = {
query: workspaceFilterQuery.me,
templates: undefined,
users: undefined,
onLoadTemplates: action("onLoadTemplates"),
onLoadUsers: action("onLoadUsers"),
onQueryChange: action("onQueryChange"),
}

export default {
title: "pages/WorkspacesPageView",
component: WorkspacesPageView,
args: {
limit: DEFAULT_RECORDS_PER_PAGE,
},
parameters: {
filterProps: defaultFilterProps,
},
} as ComponentMeta<typeof WorkspacesPageView>

const Template: Story<WorkspacesPageViewProps> = (args) => (
Expand All @@ -99,13 +112,15 @@ AllStates.args = {
export const OwnerHasNoWorkspaces = Template.bind({})
OwnerHasNoWorkspaces.args = {
workspaces: [],
filterQuery: workspaceFilterQuery.me,
count: 0,
}

export const NoSearchResults = Template.bind({})
NoSearchResults.args = {
workspaces: [],
filterQuery: "searchtearmwithnoresults",
filterProps: {
...defaultFilterProps,
query: "searchwithnoresults",
},
count: 0,
}
Loading