Skip to content

Commit 26bd8a0

Browse files
authored
Merge pull request #256 from konard/issue-255-0f74bc3da840
fix(app): confirm before applying project from terminal
2 parents 052ea00 + 0ce4010 commit 26bd8a0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

packages/app/src/web/actions-projects.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,19 @@ export const connectProjectById = (
258258
})
259259
}
260260

261+
const applyProjectConfirmMessage = (label: string): string =>
262+
`Apply docker-git config to ${label}? This restarts the container and ends active SSH sessions and in-container browsers.`
263+
261264
export const applyProjectById = (
262265
projectId: string,
263266
context: BrowserActionContext
264267
) => {
268+
const label = context.selectedProjectId === projectId
269+
? projectActionLabel(context)
270+
: projectId
271+
if (!confirmAction(applyProjectConfirmMessage(label))) {
272+
return
273+
}
265274
context.setSelectedProjectId(projectId)
266275
withBusy({
267276
context,

packages/app/tests/docker-git/actions-projects.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,50 @@ describe("web project actions", () => {
243243

244244
it.effect("applies a selected project through the project apply endpoint", () =>
245245
Effect.gen(function*(_) {
246+
const confirmMock = vi.fn(() => true)
247+
vi.stubGlobal("confirm", confirmMock)
246248
applyProjectMock.mockImplementation(() => Effect.succeed(project))
247-
const { context, reloadDashboard, setMessage } = makeBrowserActionContext()
249+
const { context, reloadDashboard, setMessage } = makeBrowserActionContext({
250+
selectedProjectId: "project-1",
251+
selectedProjectName: "octocat/hello-world"
252+
})
248253

249254
applyProjectById("project-1", context)
250255

251256
yield* _(waitForAssertion(() => {
252257
expect(applyProjectMock).toHaveBeenCalledWith("project-1")
253258
}))
254259

260+
expect(confirmMock).toHaveBeenCalledWith(
261+
"Apply docker-git config to octocat/hello-world? "
262+
+ "This restarts the container and ends active SSH sessions and in-container browsers."
263+
)
255264
expect(context.setSelectedProjectId).toHaveBeenCalledWith("project-1")
256265
expect(context.setSelectedProject).toHaveBeenCalledWith(project)
257266
expect(reloadDashboard).toHaveBeenCalledTimes(1)
258267
expect(setMessage).toHaveBeenLastCalledWith("Applied octocat/hello-world.")
259268
}))
260269

270+
it("does not apply a project when the user declines confirmation", () => {
271+
const confirmMock = vi.fn(() => false)
272+
vi.stubGlobal("confirm", confirmMock)
273+
applyProjectMock.mockImplementation(() => Effect.succeed(project))
274+
const { context, reloadDashboard } = makeBrowserActionContext({
275+
selectedProjectId: "project-1",
276+
selectedProjectName: "octocat/hello-world"
277+
})
278+
279+
applyProjectById("project-1", context)
280+
281+
expect(confirmMock).toHaveBeenCalledWith(
282+
"Apply docker-git config to octocat/hello-world? "
283+
+ "This restarts the container and ends active SSH sessions and in-container browsers."
284+
)
285+
expect(applyProjectMock).not.toHaveBeenCalled()
286+
expect(context.setSelectedProjectId).not.toHaveBeenCalled()
287+
expect(reloadDashboard).not.toHaveBeenCalled()
288+
})
289+
261290
it.effect("confirms and applies all projects", () =>
262291
Effect.gen(function*(_) {
263292
const confirmMock = vi.fn(() => true)

0 commit comments

Comments
 (0)