Skip to content

feat(site): add batch actions to the workspaces page #9091

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 15 commits into from
Aug 15, 2023
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
Add experiment in the FE side
  • Loading branch information
BrunoQuaresma committed Aug 14, 2023
commit e8a4f18c369846b54b9fb49e6b6fb1ee4135c870
10 changes: 9 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { usePagination } from "hooks/usePagination"
import { Workspace } from "api/typesGenerated"
import { useIsWorkspaceActionsEnabled } from "components/Dashboard/DashboardProvider"
import {
useDashboard,
useIsWorkspaceActionsEnabled,
} from "components/Dashboard/DashboardProvider"
import { FC, useEffect, useState } from "react"
import { Helmet } from "react-helmet-async"
import { pageTitle } from "utils/page"
Expand Down Expand Up @@ -65,6 +68,10 @@ const WorkspacesPage: FC = () => {
const [checkedWorkspaces, setCheckedWorkspaces] = useState<Workspace[]>([])
const [isDeletingAll, setIsDeletingAll] = useState(false)
const [urlSearchParams] = searchParamsResult
const dashboard = useDashboard()
const isWorkspaceBatchActionsEnabled =
dashboard.experiments.includes("workspaces_batch_actions") ||
process.env.NODE_ENV === "development"

// We want to uncheck the selected workspaces always when the url changes
// because of filtering or pagination
Expand All @@ -79,6 +86,7 @@ const WorkspacesPage: FC = () => {
</Helmet>

<WorkspacesPageView
isWorkspaceBatchActionsEnabled={isWorkspaceBatchActionsEnabled}
checkedWorkspaces={checkedWorkspaces}
onCheckChange={setCheckedWorkspaces}
workspaces={data?.workspaces}
Expand Down
5 changes: 4 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface WorkspacesPageViewProps {
filterProps: ComponentProps<typeof WorkspacesFilter>
page: number
limit: number
isWorkspaceBatchActionsEnabled?: boolean
onPageChange: (page: number) => void
onUpdateWorkspace: (workspace: Workspace) => void
onCheckChange: (checkedWorkspaces: Workspace[]) => void
Expand All @@ -63,6 +64,7 @@ export const WorkspacesPageView: FC<
onUpdateWorkspace,
page,
checkedWorkspaces,
isWorkspaceBatchActionsEnabled,
onCheckChange,
onDeleteAll,
}) => {
Expand Down Expand Up @@ -115,7 +117,7 @@ export const WorkspacesPageView: FC<
</Stack>

<TableToolbar>
{checkedWorkspaces.length > 0 ? (
{checkedWorkspaces.length > 0 && isWorkspaceBatchActionsEnabled ? (
<>
<Box>
Selected <strong>{checkedWorkspaces.length}</strong> of{" "}
Expand Down Expand Up @@ -149,6 +151,7 @@ export const WorkspacesPageView: FC<
onUpdateWorkspace={onUpdateWorkspace}
checkedWorkspaces={checkedWorkspaces}
onCheckChange={onCheckChange}
isWorkspaceBatchActionsEnabled={isWorkspaceBatchActionsEnabled}
/>
{count !== undefined && (
<PaginationWidgetBase
Expand Down
102 changes: 57 additions & 45 deletions site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface WorkspacesTableProps {
checkedWorkspaces: Workspace[]
error?: unknown
isUsingFilter: boolean
isWorkspaceBatchActionsEnabled?: boolean
onUpdateWorkspace: (workspace: Workspace) => void
onCheckChange: (checkedWorkspaces: Workspace[]) => void
}
Expand All @@ -46,6 +47,7 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
workspaces,
checkedWorkspaces,
isUsingFilter,
isWorkspaceBatchActionsEnabled,
onUpdateWorkspace,
onCheckChange,
}) => {
Expand All @@ -57,31 +59,36 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
<Table>
<TableHead>
<TableRow>
<TableCell
width="40%"
sx={{
paddingLeft: (theme) => `${theme.spacing(1.5)} !important`,
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Checkbox
checked={checkedWorkspaces.length === workspaces?.length}
size="small"
onChange={(_, checked) => {
if (!workspaces) {
return
}
{isWorkspaceBatchActionsEnabled ? (
<TableCell
width="40%"
sx={{
paddingLeft: (theme) => `${theme.spacing(1.5)} !important`,
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Checkbox
checked={checkedWorkspaces.length === workspaces?.length}
size="small"
onChange={(_, checked) => {
if (!workspaces) {
return
}

if (!checked) {
onCheckChange([])
} else {
onCheckChange(workspaces)
}
}}
/>
Name
</Box>
</TableCell>
) : (
<TableCell width="40%">Name</TableCell>
)}

if (!checked) {
onCheckChange([])
} else {
onCheckChange(workspaces)
}
}}
/>
Name
</Box>
</TableCell>
<TableCell width="25%">Template</TableCell>
<TableCell width="20%">Last used</TableCell>
<TableCell width="15%">Status</TableCell>
Expand Down Expand Up @@ -125,30 +132,35 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
<WorkspacesRow workspace={workspace} key={workspace.id}>
<TableCell
sx={{
paddingLeft: (theme) => `${theme.spacing(1.5)} !important`,
paddingLeft: (theme) =>
isWorkspaceBatchActionsEnabled
? `${theme.spacing(1.5)} !important`
: undefined,
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
<Checkbox
size="small"
checked={checkedWorkspaces.some(
(w) => w.id === workspace.id,
)}
onClick={(e) => {
e.stopPropagation()
}}
onChange={(e) => {
if (e.currentTarget.checked) {
onCheckChange([...checkedWorkspaces, workspace])
} else {
onCheckChange(
checkedWorkspaces.filter(
(w) => w.id !== workspace.id,
),
)
}
}}
/>
{isWorkspaceBatchActionsEnabled && (
<Checkbox
size="small"
checked={checkedWorkspaces.some(
(w) => w.id === workspace.id,
)}
onClick={(e) => {
e.stopPropagation()
}}
onChange={(e) => {
if (e.currentTarget.checked) {
onCheckChange([...checkedWorkspaces, workspace])
} else {
onCheckChange(
checkedWorkspaces.filter(
(w) => w.id !== workspace.id,
),
)
}
}}
/>
)}
<AvatarData
title={
<Stack direction="row" spacing={0} alignItems="center">
Expand Down