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 all commits
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
6 changes: 4 additions & 2 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,9 @@ const (
// Template parameters insights
ExperimentTemplateParametersInsights Experiment = "template_parameters_insights"

// Workspaces batch actions
ExperimentWorkspacesBatchActions Experiment = "workspaces_batch_actions"

// Add new experiments here!
// ExperimentExample Experiment = "example"
)
Expand All @@ -1942,6 +1945,7 @@ const (
var ExperimentsAll = Experiments{
ExperimentDeploymentHealthPage,
ExperimentTemplateParametersInsights,
ExperimentWorkspacesBatchActions,
}

// Experiments is a list of experiments that are enabled for the deployment.
Expand Down
1 change: 1 addition & 0 deletions docs/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 0 additions & 45 deletions site/src/components/PaginationStatus/PaginationStatus.tsx

This file was deleted.

48 changes: 48 additions & 0 deletions site/src/components/TableToolbar/TableToolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { styled } from "@mui/material/styles"
import Box from "@mui/material/Box"
import Skeleton from "@mui/material/Skeleton"

export const TableToolbar = styled(Box)(({ theme }) => ({
fontSize: 13,
marginBottom: theme.spacing(1),
marginTop: theme.spacing(0),
height: 36, // The size of a small button
color: theme.palette.text.secondary,
"& strong": { color: theme.palette.text.primary },
display: "flex",
alignItems: "center",
}))

type BasePaginationStatusProps = {
label: string
isLoading: boolean
showing?: number
total?: number
}

type LoadedPaginationStatusProps = BasePaginationStatusProps & {
isLoading: false
showing: number
total: number
}

export const PaginationStatus = ({
isLoading,
showing,
total,
label,
}: BasePaginationStatusProps | LoadedPaginationStatusProps) => {
if (isLoading) {
return (
<Box sx={{ height: 24, display: "flex", alignItems: "center" }}>
<Skeleton variant="text" width={160} height={16} />
</Box>
)
}
return (
<Box>
Showing <strong>{showing}</strong> of{" "}
<strong>{total?.toLocaleString()}</strong> {label}
</Box>
)
}
19 changes: 12 additions & 7 deletions site/src/pages/AuditPage/AuditPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { ComponentProps, FC } from "react"
import { useTranslation } from "react-i18next"
import { AuditPaywall } from "./AuditPaywall"
import { AuditFilter } from "./AuditFilter"
import { PaginationStatus } from "components/PaginationStatus/PaginationStatus"
import {
PaginationStatus,
TableToolbar,
} from "components/TableToolbar/TableToolbar"
import { PaginationWidgetBase } from "components/PaginationWidget/PaginationWidgetBase"

export const Language = {
Expand Down Expand Up @@ -73,12 +76,14 @@ export const AuditPageView: FC<AuditPageViewProps> = ({
<Cond condition={isAuditLogVisible}>
<AuditFilter {...filterProps} />

<PaginationStatus
isLoading={Boolean(isLoading)}
showing={auditLogs?.length ?? 0}
total={count ?? 0}
label="audit logs"
/>
<TableToolbar>
<PaginationStatus
isLoading={Boolean(isLoading)}
showing={auditLogs?.length ?? 0}
total={count ?? 0}
label="audit logs"
/>
</TableToolbar>

<TableContainer>
<Table>
Expand Down
19 changes: 12 additions & 7 deletions site/src/pages/GroupsPage/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import { pageTitle } from "utils/page"
import { groupMachine } from "xServices/groups/groupXService"
import { Maybe } from "components/Conditionals/Maybe"
import { makeStyles } from "@mui/styles"
import { PaginationStatus } from "components/PaginationStatus/PaginationStatus"
import {
PaginationStatus,
TableToolbar,
} from "components/TableToolbar/TableToolbar"
import { UserAvatar } from "components/UserAvatar/UserAvatar"

const AddGroupMember: React.FC<{
Expand Down Expand Up @@ -155,12 +158,14 @@ export const GroupPage: React.FC = () => {
}}
/>
</Maybe>
<PaginationStatus
isLoading={Boolean(isLoading)}
showing={group?.members.length ?? 0}
total={group?.members.length ?? 0}
label="members"
/>
<TableToolbar>
<PaginationStatus
isLoading={Boolean(isLoading)}
showing={group?.members.length ?? 0}
total={group?.members.length ?? 0}
label="members"
/>
</TableToolbar>

<TableContainer>
<Table>
Expand Down
19 changes: 12 additions & 7 deletions site/src/pages/UsersPage/UsersPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { PaginationMachineRef } from "xServices/pagination/paginationXService"
import * as TypesGen from "../../api/typesGenerated"
import { UsersTable } from "../../components/UsersTable/UsersTable"
import { UsersFilter } from "./UsersFilter"
import { PaginationStatus } from "components/PaginationStatus/PaginationStatus"
import {
PaginationStatus,
TableToolbar,
} from "components/TableToolbar/TableToolbar"

export const Language = {
activeUsersFilterName: "Active users",
Expand Down Expand Up @@ -60,12 +63,14 @@ export const UsersPageView: FC<React.PropsWithChildren<UsersPageViewProps>> = ({
<>
<UsersFilter {...filterProps} />

<PaginationStatus
isLoading={Boolean(isLoading)}
showing={users?.length ?? 0}
total={count ?? 0}
label="users"
/>
<TableToolbar>
<PaginationStatus
isLoading={Boolean(isLoading)}
showing={users?.length ?? 0}
total={count ?? 0}
label="users"
/>
</TableToolbar>

<UsersTable
users={users}
Expand Down
43 changes: 41 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { screen } from "@testing-library/react"
import { screen, waitFor, within } from "@testing-library/react"
import { rest } from "msw"
import * as CreateDayString from "utils/createDayString"
import { MockWorkspace, MockWorkspacesResponse } from "testHelpers/entities"
import { renderWithAuth } from "testHelpers/renderHelpers"
import {
renderWithAuth,
waitForLoaderToBeRemoved,
} from "testHelpers/renderHelpers"
import { server } from "testHelpers/server"
import WorkspacesPage from "./WorkspacesPage"
import { i18n } from "i18n"
import userEvent from "@testing-library/user-event"
import * as API from "api/api"
import { Workspace } from "api/typesGenerated"

const { t } = i18n

Expand Down Expand Up @@ -40,4 +46,37 @@ describe("WorkspacesPage", () => {
)
expect(templateDisplayNames).toHaveLength(MockWorkspacesResponse.count)
})

it("deletes only the selected workspaces", async () => {
const workspaces = [
{ ...MockWorkspace, id: "1" },
{ ...MockWorkspace, id: "2" },
{ ...MockWorkspace, id: "3" },
]
jest
.spyOn(API, "getWorkspaces")
.mockResolvedValue({ workspaces, count: workspaces.length })
const deleteWorkspace = jest.spyOn(API, "deleteWorkspace")
const user = userEvent.setup()
renderWithAuth(<WorkspacesPage />)
await waitForLoaderToBeRemoved()

await user.click(getWorkspaceCheckbox(workspaces[0]))
await user.click(getWorkspaceCheckbox(workspaces[1]))
await user.click(screen.getByRole("button", { name: /delete all/i }))
await user.type(screen.getByLabelText(/type delete to confirm/i), "DELETE")
await user.click(screen.getByTestId("confirm-button"))

await waitFor(() => {
expect(deleteWorkspace).toHaveBeenCalledTimes(2)
})
expect(deleteWorkspace).toHaveBeenCalledWith(workspaces[0].id)
expect(deleteWorkspace).toHaveBeenCalledWith(workspaces[1].id)
})
})

const getWorkspaceCheckbox = (workspace: Workspace) => {
return within(screen.getByTestId(`checkbox-${workspace.id}`)).getByRole(
"checkbox",
)
}
Loading