Skip to content

feat: add extra workspace actions in the workspaces table #17775

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
May 13, 2025
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
Move components and fix build errors
  • Loading branch information
BrunoQuaresma committed May 12, 2025
commit a3c4908c51bf84b0582bdaa6dd8176f66996d156
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { withDesktopViewport } from "testHelpers/storybook";
import { DownloadLogsDialog } from "./DownloadLogsDialog";

const meta: Meta<typeof DownloadLogsDialog> = {
title: "pages/WorkspacePage/DownloadLogsDialog",
title: "modules/workspaces/DownloadLogsDialog",
component: DownloadLogsDialog,
args: {
open: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ const DownloadingItem: FC<DownloadingItemProps> = ({ file, giveUpTimeMs }) => {
function humanBlobSize(size: number) {
const BLOB_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"] as const;
let i = 0;
while (size > 1024 && i < BLOB_SIZE_UNITS.length) {
size /= 1024;
let sizeIterator = size;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch

Copy link
Member

@Parkreiner Parkreiner May 13, 2025

Choose a reason for hiding this comment

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

I'm not the biggest fan of changing parameters either, but in this case, this would never be a bug, since numbers are primitive values

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have to say it was a Biome catch haha.

while (sizeIterator > 1024 && i < BLOB_SIZE_UNITS.length) {
sizeIterator /= 1024;
Comment on lines +224 to +226
Copy link
Member

Choose a reason for hiding this comment

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

There's nothing wrong with the changes you made here, but if we're dealing with numbers that are big enough that we're expecting to need to divide it by 1024 multiple times, do we want to update anything to involve Number.MAX_SAFE_INTEGER or the big int data type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is only to humanize the number, so it is a fixed value of 1024

i++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
CopyIcon,
DownloadIcon,
} from "lucide-react";
import { UpdateBuildParametersDialog } from "pages/WorkspacePage/UpdateBuildParametersDialog";
import { DownloadLogsDialog } from "pages/WorkspacePage/WorkspaceActions/DownloadLogsDialog";
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
import { DownloadLogsDialog } from "./DownloadLogsDialog";
import { useState, type FC } from "react";
import { useMutation, useQueryClient } from "react-query";
import { Link as RouterLink } from "react-router-dom";
import { ChangeWorkspaceVersionDialog } from "./ChangeWorkspaceVersionDialog";
import { WorkspaceDeleteDialog } from "./WorkspaceDeleteDialog";
import type { WorkspacePermissions } from "../permissions";
import { useWorkspaceDuplication } from "pages/CreateWorkspacePage/useWorkspaceDuplication";
import { useWorkspaceDuplication } from "./useWorkspaceDuplication";

type WorkspaceMoreActionsProps = {
workspace: Workspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type GetLocationSnapshot,
renderHookWithAuth,
} from "testHelpers/hooks";
import CreateWorkspacePage from "./CreateWorkspacePage";
import CreateWorkspacePage from "../../../pages/CreateWorkspacePage/CreateWorkspacePage";
import { useWorkspaceDuplication } from "./useWorkspaceDuplication";

function render(workspace?: Workspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { linkToTemplate, useLinks } from "modules/navigation";
import { useCallback } from "react";
import { useQuery } from "react-query";
import { useNavigate } from "react-router-dom";
import type { CreateWorkspaceMode } from "./CreateWorkspacePage";
import type { CreateWorkspaceMode } from "../../../pages/CreateWorkspacePage/CreateWorkspacePage";

function getDuplicationUrlParams(
workspaceParams: readonly WorkspaceBuildParameter[],
Expand Down
2 changes: 1 addition & 1 deletion site/src/modules/workspaces/WorkspaceUpdateDialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from "api/typesGenerated";
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog";
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
import { UpdateBuildParametersDialog } from "pages/WorkspacePage/UpdateBuildParametersDialog";
import { UpdateBuildParametersDialog } from "modules/workspaces/WorkspaceMoreActions/UpdateBuildParametersDialog";
import { type FC, useState } from "react";
import { useMutation, useQueryClient } from "react-query";

Expand Down
5 changes: 3 additions & 2 deletions site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const createTimestamp = (
const permissions: WorkspacePermissions = {
readWorkspace: true,
updateWorkspace: true,
updateTemplate: true,
viewDeploymentConfig: true,
updateWorkspaceVersion: true,
deploymentConfig: true,
deleteFailedWorkspace: true,
};

const meta: Meta<typeof Workspace> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ export const Failed: Story = {
export const FailedWithDebug: Story = {
args: {
workspace: Mocks.MockFailedWorkspace,
canDebug: true,
permissions: {
deploymentConfig: true,
deleteFailedWorkspace: true,
readWorkspace: true,
updateWorkspace: true,
updateWorkspaceVersion: true,
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
} from "testHelpers/entities";
import { withDashboardProvider } from "testHelpers/storybook";
import { WorkspaceNotifications } from "./WorkspaceNotifications";
import type { WorkspacePermissions } from "modules/workspaces/permissions";

const defaultPermissions = {
const defaultPermissions: WorkspacePermissions = {
readWorkspace: true,
updateTemplate: true,
updateWorkspaceVersion: true,
updateWorkspace: true,
viewDeploymentConfig: true,
deploymentConfig: true,
deleteFailedWorkspace: true,
};

const meta: Meta<typeof WorkspaceNotifications> = {
Expand Down
8 changes: 7 additions & 1 deletion site/src/pages/WorkspacePage/WorkspaceTopbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ const meta: Meta<typeof WorkspaceTopbar> = {
workspace: baseWorkspace,
template: MockTemplate,
latestVersion: MockTemplateVersion,
canUpdateWorkspace: true,
permissions: {
readWorkspace: true,
updateWorkspaceVersion: true,
updateWorkspace: true,
deploymentConfig: true,
deleteFailedWorkspace: true,
},
},
parameters: {
layout: "fullscreen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ const WorkspaceParametersPage: FC = () => {
const template = templateQuery.data;

// Permissions
const checks =
workspace && template ? workspaceChecks(workspace, template) : {};
const checks = workspace && template ? workspaceChecks(workspace) : {};
Copy link
Member

Choose a reason for hiding this comment

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

If we're only using the workspace to define the checks, do we still need template to be part of the ternary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not at all!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One less query 👏

const permissionsQuery = useQuery({
...checkAuthorization({ checks }),
enabled: workspace !== undefined && template !== undefined,
});
const permissions = permissionsQuery.data as WorkspacePermissions | undefined;
const canChangeVersions = Boolean(permissions?.updateTemplate);
const canChangeVersions = Boolean(permissions?.updateWorkspaceVersion);

return (
<>
Expand Down