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

fix(site): send build parameters over the confirmation dialog on restart#8660

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 2 commits intomainfrombq/fix-build-form
Jul 21, 2023
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,7 @@ export const BuildParametersPopover = ({
return (
<>
<Button
data-testid="build-parameters-button"
disabled={disabled}
color="neutral"
sx={{ px: 0 }}
Expand DownExpand Up@@ -159,7 +160,7 @@ const Form = ({
const getFieldHelpers = getFormHelpers(form)

return (
<form onSubmit={form.handleSubmit}>
<form onSubmit={form.handleSubmit} data-testid="build-parameters-form">
<FormFields>
{ephemeralParameters.map((parameter, index) => {
return (
Expand All@@ -182,6 +183,7 @@ const Form = ({
</FormFields>
<Box sx={{ py: 3, pb: 1 }}>
<Button
data-testid="build-parameters-submit"
type="submit"
variant="contained"
color="primary"
Expand Down
76 changes: 76 additions & 0 deletionssite/src/pages/WorkspacePage/WorkspacePage.test.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -411,4 +411,80 @@ describe("WorkspacePage", () => {
await renderWorkspacePage()
await screen.findByTestId("error-unsupported-workspaces")
})

it("restart the workspace with one time parameters when having the confirmation dialog", async () => {
window.localStorage.removeItem(`${MockUser.id}_ignoredWarnings`)
jest.spyOn(api, "getWorkspaceParameters").mockResolvedValue({
templateVersionRichParameters: [
{
...MockTemplateVersionParameter1,
ephemeral: true,
name: "rebuild",
description: "Rebuild",
required: false,
},
],
buildParameters: [{ name: "rebuild", value: "false" }],
})
const restartWorkspaceSpy = jest.spyOn(api, "restartWorkspace")
const user = userEvent.setup()
await renderWorkspacePage()
await user.click(screen.getByTestId("build-parameters-button"))
const buildParametersForm = await screen.findByTestId(
"build-parameters-form",
)
const rebuildField = within(buildParametersForm).getByLabelText("Rebuild", {
exact: false,
})
await user.clear(rebuildField)
await user.type(rebuildField, "true")
await user.click(screen.getByTestId("build-parameters-submit"))
await user.click(screen.getByTestId("confirm-button"))
await waitFor(() => {
expect(restartWorkspaceSpy).toBeCalledWith({
workspace: MockWorkspace,
buildParameters: [{ name: "rebuild", value: "true" }],
})
})
})

it("restart the workspace with one time parameters without the confirmation dialog", async () => {
window.localStorage.setItem(
`${MockUser.id}_ignoredWarnings`,
JSON.stringify({
restart: new Date().toISOString(),
}),
)
jest.spyOn(api, "getWorkspaceParameters").mockResolvedValue({
templateVersionRichParameters: [
{
...MockTemplateVersionParameter1,
ephemeral: true,
name: "rebuild",
description: "Rebuild",
required: false,
},
],
buildParameters: [{ name: "rebuild", value: "false" }],
})
const restartWorkspaceSpy = jest.spyOn(api, "restartWorkspace")
const user = userEvent.setup()
await renderWorkspacePage()
await user.click(screen.getByTestId("build-parameters-button"))
const buildParametersForm = await screen.findByTestId(
"build-parameters-form",
)
const rebuildField = within(buildParametersForm).getByLabelText("Rebuild", {
exact: false,
})
await user.clear(rebuildField)
await user.type(rebuildField, "true")
await user.click(screen.getByTestId("build-parameters-submit"))
await waitFor(() => {
expect(restartWorkspaceSpy).toBeCalledWith({
workspace: MockWorkspace,
buildParameters: [{ name: "rebuild", value: "true" }],
})
})
})
})
31 changes: 19 additions & 12 deletionssite/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,9 +27,8 @@ import {
} from "../../xServices/workspace/workspaceXService"
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog"
import { ChangeVersionDialog } from "./ChangeVersionDialog"
import { useQuery } from "@tanstack/react-query"
import { getTemplateVersions } from "api/api"
import { useRestartWorkspace } from "./hooks"
import { useMutation, useQuery } from "@tanstack/react-query"
import { getTemplateVersions, restartWorkspace } from "api/api"
import {
ConfirmDialog,
ConfirmDialogProps,
Expand DownExpand Up@@ -89,7 +88,10 @@ export const WorkspaceReadyPage = ({
enabled: changeVersionDialogOpen,
})
const [isConfirmingUpdate, setIsConfirmingUpdate] = useState(false)
const [isConfirmingRestart, setIsConfirmingRestart] = useState(false)
const [confirmingRestart, setConfirmingRestart] = useState<{
open: boolean
buildParameters?: TypesGen.WorkspaceBuildParameter[]
}>({ open: false })
const user = useMe()
const { isWarningIgnored, ignoreWarning } = useIgnoreWarnings(user.id)
const buildLogs = useBuildLogs(workspace)
Expand All@@ -99,10 +101,12 @@ export const WorkspaceReadyPage = ({
workspace.latest_build.status,
)
const {
mutate:restartWorkspace,
mutate:mutateRestartWorkspace,
error: restartBuildError,
isLoading: isRestarting,
} = useRestartWorkspace()
} = useMutation({
mutationFn: restartWorkspace,
})
// keep banner machine in sync with workspace
useEffect(() => {
bannerSend({ type: "REFRESH_WORKSPACE", workspace })
Expand DownExpand Up@@ -154,9 +158,9 @@ export const WorkspaceReadyPage = ({
handleDelete={() => workspaceSend({ type: "ASK_DELETE" })}
handleRestart={(buildParameters) => {
if (isWarningIgnored("restart")) {
restartWorkspace({ workspace, buildParameters })
mutateRestartWorkspace({ workspace, buildParameters })
} else {
setIsConfirmingRestart(true)
setConfirmingRestart({ open:true, buildParameters })
}
}}
handleUpdate={() => {
Expand DownExpand Up@@ -253,15 +257,18 @@ export const WorkspaceReadyPage = ({
/>

<WarningDialog
open={isConfirmingRestart}
open={confirmingRestart.open}
onConfirm={(shouldIgnore) => {
if (shouldIgnore) {
ignoreWarning("restart")
}
restartWorkspace({ workspace })
setIsConfirmingRestart(false)
mutateRestartWorkspace({
workspace,
buildParameters: confirmingRestart.buildParameters,
})
setConfirmingRestart({ open: false })
}}
onClose={() =>setIsConfirmingRestart(false)}
onClose={() =>setConfirmingRestart({ open:false })}
title="Confirm restart"
confirmText="Restart"
description="Are you sure you want to restart your workspace? Updating your workspace will stop all running processes and delete non-persistent data."
Expand Down
8 changes: 0 additions & 8 deletionssite/src/pages/WorkspacePage/hooks.ts
View file
Open in desktop

This file was deleted.


[8]ページ先頭

©2009-2025 Movatter.jp