GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): preserve newer project action drafts when imports fail (#39… · pingdotgg/t3code@916fcdc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src
    • components
      • ProjectScriptsControl.browser.test.tsx
      • ProjectScriptsControl.tsx
    • i18n/translations
      • de.json
      • en.json
      • es.json
      • fr.json
      • ja.json
      • ko.json
      • pt-BR.json
      • ru.json
      • sv.json
      • zh.json
  • scripts/scenarios
    • project-action-draft-survives-failed-import.e2e.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ProjectScriptsControl.browser.test.tsx‎

Copy file name to clipboard
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { EnvironmentId } from "@t3tools/contracts";
2+
import * as Cause from "effect/Cause";
3+
import { AsyncResult } from "effect/reactivity";
4+
import { expect, it } from "vite-plus/test";
5+
import { page, userEvent } from "vite-plus/test/browser";
6+
7+
import { act, render } from "../../test/render";
8+
import ProjectScriptsControl, { type ProjectScriptActionResult } from "./ProjectScriptsControl";
9+
10+
it.each(["edit", "dismiss", "newer import fails first"] as const)(
11+
"keeps a failed import from replacing a newer action after %s",
12+
async (nextAction) => {
13+
const older = Promise.withResolvers<ProjectScriptActionResult>();
14+
const newer = Promise.withResolvers<ProjectScriptActionResult>();
15+
await using screen = await render(
16+
<ProjectScriptsControl
17+
environmentId={EnvironmentId.make("test")}
18+
displayMode="panel"
19+
scripts={[
20+
{
21+
id: "local-check",
22+
name: "Local check",
23+
command: "echo local",
24+
icon: "play",
25+
runOnWorktreeCreate: false,
26+
},
27+
]}
28+
fileScripts={[
29+
{ name: "Shared build", command: "echo build" },
30+
{ name: "Shared lint", command: "echo lint" },
31+
]}
32+
onRunScript={() => {}}
33+
onAddScript={({ name }) => (name === "Shared build" ? older.promise : newer.promise)}
34+
onUpdateScript={async () => AsyncResult.success(undefined)}
35+
onDeleteScript={async () => AsyncResult.success(undefined)}
36+
/>,
37+
);
38+
39+
const actions = screen.getByRole("button", { name: "Script actions" });
40+
const dialog = page.getByRole("dialog");
41+
const name = dialog.getByRole("textbox", { name: "Name" });
42+
const failure = AsyncResult.failure<void, unknown>(
43+
Cause.fail(new Error("Settings write failed")),
44+
);
45+
46+
await actions.click();
47+
await page.getByRole("menuitem", { name: /Shared build/ }).click();
48+
await actions.click();
49+
50+
switch (nextAction) {
51+
case "edit":
52+
await page.getByRole("button", { name: "Edit Local check" }).click();
53+
await act(async () => older.resolve(failure));
54+
expect(name.query()).toHaveProperty("value", "Local check");
55+
break;
56+
case "dismiss":
57+
await page.getByRole("menuitem", { name: "Add project script" }).click();
58+
await expect.element(dialog).toBeVisible();
59+
await userEvent.keyboard("{Escape}");
60+
await expect.element(dialog).not.toBeInTheDocument();
61+
await act(async () => older.resolve(failure));
62+
expect(dialog.query() === null).toBe(true);
63+
break;
64+
case "newer import fails first":
65+
await page.getByRole("menuitem", { name: /Shared lint/ }).click();
66+
await act(async () => newer.resolve(failure));
67+
await act(async () => older.resolve(failure));
68+
expect(name.query()).toHaveProperty("value", "Shared lint");
69+
break;
70+
}
71+
},
72+
);
Collapse file

‎apps/web/src/components/ProjectScriptsControl.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ProjectScriptsControl.tsx
+22-7Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
MenuSubTrigger,
4848
MenuSubPopup,
4949
} from "./ui/menu";
50+
import { stackedThreadToast, toastManager } from "./ui/toast";
5051
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
5152
import { cn } from "~/lib/utils";
5253
import {
@@ -108,6 +109,7 @@ export default function ProjectScriptsControl({
108109
setActionsMenuOpen({ presentation, scripts: false, imports: false });
109110
}
110111
const [editorRequest, setEditorRequest] = useState<ProjectScriptEditorRequest | null>(null);
112+
const editorRequestIdRef = React.useRef(0);
111113

112114
const primaryScript =
113115
(preferredScriptId ? scripts.find((script) => script.id === preferredScriptId) : undefined) ??
@@ -122,10 +124,12 @@ export default function ProjectScriptsControl({
122124
);
123125

124126
const openAddDialog = () => {
127+
editorRequestIdRef.current += 1;
125128
setEditorRequest({ scriptId: null, initial: EMPTY_PROJECT_SCRIPT_INPUT });
126129
};
127130

128131
const openEditDialog = (script: ProjectScript) => {
132+
editorRequestIdRef.current += 1;
129133
onRequestMenuClose?.();
130134
setActionsMenuOpen({ presentation, scripts: false, imports: false });
131135
setEditorRequest(editorRequestForScript(script, keybindings));
@@ -135,6 +139,7 @@ export default function ProjectScriptsControl({
135139
scriptId === null ? onAddScript(input) : onUpdateScript(scriptId, input);
136140

137141
const importFileScript = async (fileScript: T3ProjectFileScript) => {
142+
const requestId = ++editorRequestIdRef.current;
138143
const payload: NewProjectScriptInput = {
139144
name: fileScript.name,
140145
command: fileScript.command,
@@ -148,14 +153,24 @@ export default function ProjectScriptsControl({
148153
autoOpenPreview: fileScript.previewUrl ? (fileScript.autoOpenPreview ?? false) : false,
149154
};
150155
const result = await onAddScript(payload);
151-
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
152-
const error = squashAtomCommandFailure(result);
153-
setEditorRequest({
154-
scriptId: null,
155-
initial: payload,
156-
error: thrownErrorMessage(error, m) ?? gt("Failed to import action."),
157-
});
156+
if (result._tag !== "Failure" || isAtomCommandInterrupted(result)) return;
157+
158+
const message = thrownErrorMessage(squashAtomCommandFailure(result), m);
159+
if (requestId !== editorRequestIdRef.current) {
160+
toastManager.add(
161+
stackedThreadToast({
162+
type: "error",
163+
title: gt("Failed to import {name}.", { name: fileScript.name }),
164+
...(message ? { description: message } : {}),
165+
}),
166+
);
167+
return;
158168
}
169+
setEditorRequest({
170+
scriptId: null,
171+
initial: payload,
172+
error: message ?? gt("Failed to import action."),
173+
});
159174
};
160175

161176
const importMenuItems = importableScripts.length > 0 && (
Collapse file

‎apps/web/src/i18n/translations/de.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/de.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "{name} loslösen",
21952195
"c4c2d240ffe55dec": "{name} anheften",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "{name} konnte nicht importiert werden.",
21972198
"924d4b8e011c9127": "Aktion konnte nicht importiert werden.",
21982199
"0421f870f82997bc": "Importieren",
21992200
"06690d4ce0d19c30": "{name} bearbeiten",
Collapse file

‎apps/web/src/i18n/translations/en.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/en.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "Unpin {name}",
21952195
"c4c2d240ffe55dec": "Pin {name}",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "Failed to import {name}.",
21972198
"924d4b8e011c9127": "Failed to import action.",
21982199
"0421f870f82997bc": "Import",
21992200
"06690d4ce0d19c30": "Edit {name}",
Collapse file

‎apps/web/src/i18n/translations/es.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/es.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "Desfijar {name}",
21952195
"c4c2d240ffe55dec": "Fijar {name}",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "No se pudo importar {name}.",
21972198
"924d4b8e011c9127": "No se pudo importar la acción.",
21982199
"0421f870f82997bc": "Importar",
21992200
"06690d4ce0d19c30": "Editar {name}",
Collapse file

‎apps/web/src/i18n/translations/fr.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/fr.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "Désépingler {name}",
21952195
"c4c2d240ffe55dec": "Épingler {name}",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "Échec de l’import de « {name} ».",
21972198
"924d4b8e011c9127": "Échec de l’import de l’action.",
21982199
"0421f870f82997bc": "Importer",
21992200
"06690d4ce0d19c30": "Modifier {name}",
Collapse file

‎apps/web/src/i18n/translations/ja.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/ja.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,7 @@
21922192
"63977cd5e4535393": "{name} のピン留めを解除",
21932193
"c4c2d240ffe55dec": "{name} をピン留め",
21942194
"a1190e56375f2032": "{action} ({shortcut})",
2195+
"f16b6d8ef68bab61": "「{name}」をインポートできませんでした。",
21952196
"924d4b8e011c9127": "アクションをインポートできませんでした。",
21962197
"0421f870f82997bc": "インポート",
21972198
"06690d4ce0d19c30": "{name} を編集",
Collapse file

‎apps/web/src/i18n/translations/ko.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/ko.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,7 @@
21932193
"63977cd5e4535393": "{name} 고정 해제",
21942194
"c4c2d240ffe55dec": "{name} 고정",
21952195
"a1190e56375f2032": "{action}({shortcut})",
2196+
"f16b6d8ef68bab61": "‘{name}’을(를) 가져오지 못했습니다.",
21962197
"924d4b8e011c9127": "작업을 가져오지 못했습니다.",
21972198
"0421f870f82997bc": "가져오기",
21982199
"06690d4ce0d19c30": "{name} 편집",
Collapse file

‎apps/web/src/i18n/translations/pt-BR.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/pt-BR.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "Desafixar {name}",
21952195
"c4c2d240ffe55dec": "Fixar {name}",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "Não foi possível importar {name}.",
21972198
"924d4b8e011c9127": "Falha ao importar a ação.",
21982199
"0421f870f82997bc": "Importar",
21992200
"06690d4ce0d19c30": "Editar {name}",
Collapse file

‎apps/web/src/i18n/translations/ru.json‎

Copy file name to clipboardExpand all lines: apps/web/src/i18n/translations/ru.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,7 @@
21942194
"63977cd5e4535393": "Открепить {name}",
21952195
"c4c2d240ffe55dec": "Закрепить {name}",
21962196
"a1190e56375f2032": "{action} ({shortcut})",
2197+
"f16b6d8ef68bab61": "Не удалось импортировать «{name}».",
21972198
"924d4b8e011c9127": "Не удалось импортировать действие.",
21982199
"0421f870f82997bc": "Импортировать",
21992200
"06690d4ce0d19c30": "Изменить {name}",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.