Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(site): show "update and start" button when update is forced#13334

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 3 commits intomainfrombq/enable-start-button
May 21, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
24 changes: 15 additions & 9 deletionssite/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,10 +117,8 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
handleAction,
loading,
workspace,
disabled,
tooltipText,
}) => {
const buttonContent = (
return (
<ButtonGroup
variant="outlined"
css={{
Expand All@@ -129,13 +127,12 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
borderLeft: "1px solid #FFF",
},
}}
disabled={disabled}
>
<TopbarButton
startIcon={<ReplayIcon />}
onClick={() => handleAction()}
data-testid="workspace-restart-button"
disabled={disabled ||loading}
disabled={loading}
>
{loading ? <>Restarting&hellip;</> : <>Restart&hellip;</>}
</TopbarButton>
Expand All@@ -147,11 +144,20 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
/>
</ButtonGroup>
);
};

return tooltipText ? (
<Tooltip title={tooltipText}>{buttonContent}</Tooltip>
) : (
buttonContent
export const UpdateAndStartButton: FC<ActionButtonProps> = ({
handleAction,
}) => {
return (
<Tooltip title="This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.">
<TopbarButton
startIcon={<PlayCircleOutlineIcon />}
onClick={() => handleAction()}
>
Update and start&hellip;
</TopbarButton>
</Tooltip>
);
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,6 +24,7 @@ import {
UpdateButton,
ActivateButton,
FavoriteButton,
UpdateAndStartButton,
} from "./Buttons";
import { type ActionType, abilitiesByWorkspaceStatus } from "./constants";
import { DebugButton } from "./DebugButton";
Expand DownExpand Up@@ -89,6 +90,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
// A mapping of button type to the corresponding React component
const buttonMapping: Record<ActionType, ReactNode> = {
update: <UpdateButton handleAction={handleUpdate} />,
updateAndStart: <UpdateAndStartButton handleAction={handleUpdate} />,
updating: <UpdateButton loading handleAction={handleUpdate} />,
start: (
<StartButton
Expand DownExpand Up@@ -161,7 +163,13 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
data-testid="workspace-actions"
>
{canBeUpdated && (
<>{isUpdating ? buttonMapping.updating : buttonMapping.update}</>
<>
{isUpdating
? buttonMapping.updating
: workspace.template_require_active_version
? buttonMapping.updateAndStart
: buttonMapping.update}
</>
)}

{isRestarting
Expand DownExpand Up@@ -236,10 +244,6 @@ function getTooltipText(
return "This template requires automatic updates on workspace startup, but template administrators can ignore this policy.";
}

if (workspace.template_require_active_version) {
return "This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.";
}

if (workspace.automatic_updates === "always") {
return "Automatic updates are enabled for this workspace. Modify the update policy in workspace settings if you want to preserve the template version.";
}
Expand Down
156 changes: 99 additions & 57 deletionssite/src/pages/WorkspacePage/WorkspaceActions/constants.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import type { Workspace, WorkspaceStatus } from "api/typesGenerated";
import type { Workspace } from "api/typesGenerated";

/**
* An iterable of all action types supported by the workspace UI
Expand All@@ -23,6 +23,10 @@ export const actionTypes = [
"retry",
"debug",

// When a template requires updates, we aim to display a distinct update
// button that clearly indicates a mandatory update.
"updateAndStart",

// These are buttons that should be used with disabled UI elements
"canceling",
"deleted",
Expand DownExpand Up@@ -52,67 +56,105 @@ export const abilitiesByWorkspaceStatus = (
const status = workspace.latest_build.status;
if (status === "failed" && canDebug) {
return {
...statusToAbility.failed,
actions: ["retry", "debug"],
canCancel: false,
canAcceptJobs: true,
};
}

return statusToAbility[status];
};
switch (status) {
case "starting": {
return {
actions: ["starting"],
canCancel: true,
canAcceptJobs: false,
};
}
case "running": {
const actions: ActionType[] = ["stop"];

const statusToAbility: Record<WorkspaceStatus, WorkspaceAbilities> = {
starting: {
actions: ["starting"],
canCancel: true,
canAcceptJobs: false,
},
running: {
actions: ["stop", "restart"],
canCancel: false,
canAcceptJobs: true,
},
stopping: {
actions: ["stopping"],
canCancel: true,
canAcceptJobs: false,
},
stopped: {
actions: ["start"],
canCancel: false,
canAcceptJobs: true,
},
canceled: {
actions: ["start", "stop"],
canCancel: false,
canAcceptJobs: true,
},
// If the template requires the latest version, we prevent the user from
// restarting the workspace without updating it first. In the Buttons
// component, we display an UpdateAndStart component to facilitate this.
if (!workspace.template_require_active_version) {
actions.push("restart");
}

// in the case of an error
failed: {
actions: ["retry"],
canCancel: false,
canAcceptJobs: true,
},
return {
actions,
canCancel: false,
canAcceptJobs: true,
};
}
case "stopping": {
return {
actions: ["stopping"],
canCancel: true,
canAcceptJobs: false,
};
}
case "stopped": {
const actions: ActionType[] = [];

// Disabled states
canceling: {
actions: ["canceling"],
canCancel: false,
canAcceptJobs: false,
},
deleting: {
actions: ["deleting"],
canCancel: true,
canAcceptJobs: false,
},
deleted: {
actions: ["deleted"],
canCancel: false,
canAcceptJobs: false,
},
pending: {
actions: ["pending"],
canCancel: false,
canAcceptJobs: false,
},
// If the template requires the latest version, we prevent the user from
// starting the workspace without updating it first. In the Buttons
// component, we display an UpdateAndStart component to facilitate this.
if (!workspace.template_require_active_version) {
actions.push("start");
}

return {
actions,
canCancel: false,
canAcceptJobs: true,
};
}
case "canceled": {
return {
actions: ["start", "stop"],
canCancel: false,
canAcceptJobs: true,
};
}
case "failed": {
return {
actions: ["retry"],
canCancel: false,
canAcceptJobs: true,
};
}

// Disabled states
case "canceling": {
return {
actions: ["canceling"],
canCancel: false,
canAcceptJobs: false,
};
}
case "deleting": {
return {
actions: ["deleting"],
canCancel: true,
canAcceptJobs: false,
};
}
case "deleted": {
return {
actions: ["deleted"],
canCancel: false,
canAcceptJobs: false,
};
}
case "pending": {
return {
actions: ["pending"],
canCancel: false,
canAcceptJobs: false,
};
}
default: {
throw new Error(`Unknown workspace status: ${status}`);
}
}
};
Loading

[8]ページ先頭

©2009-2025 Movatter.jp