Skip to content

Commit 759ad2b

Browse files
committed
Allow empty payloads in test runs
1 parent 64ca9dc commit 759ad2b

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

apps/webapp/app/components/code/codeMirrorSetup.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,41 @@ import { closeBrackets } from "@codemirror/autocomplete";
22
import { indentWithTab } from "@codemirror/commands";
33
import { jsonParseLinter } from "@codemirror/lang-json";
44
import { bracketMatching } from "@codemirror/language";
5-
import { lintGutter, lintKeymap, linter } from "@codemirror/lint";
5+
import { type Diagnostic, linter, lintGutter, lintKeymap } from "@codemirror/lint";
66
import { highlightSelectionMatches } from "@codemirror/search";
77
import { Prec, type Extension } from "@codemirror/state";
88
import {
99
drawSelection,
1010
dropCursor,
11+
type EditorView,
1112
highlightActiveLine,
1213
highlightActiveLineGutter,
1314
highlightSpecialChars,
1415
keymap,
1516
lineNumbers,
1617
} from "@codemirror/view";
1718

19+
function emptyAwareJsonLinter() {
20+
return (view: EditorView): Diagnostic[] => {
21+
const content = view.state.doc.toString().trim();
22+
23+
// return no errors if content is empty
24+
if (!content) {
25+
return [];
26+
}
27+
28+
return jsonParseLinter()(view);
29+
};
30+
}
31+
1832
export function getEditorSetup(showLineNumbers = true, showHighlights = true): Array<Extension> {
1933
const options = [
2034
drawSelection(),
2135
dropCursor(),
2236
bracketMatching(),
2337
closeBrackets(),
2438
lintGutter(),
25-
linter(jsonParseLinter()),
39+
linter(emptyAwareJsonLinter()),
2640
Prec.highest(
2741
keymap.of([
2842
{

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.test.tasks.$taskParam/route.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ function StandardTaskForm({ task, runs }: { task: TestTask["task"]; runs: Standa
291291
}}
292292
height="100%"
293293
autoFocus={!tab || tab === "payload"}
294-
placeholder="{ }"
295294
className={cn("h-full overflow-auto", tab === "metadata" && "hidden")}
296295
/>
297296
<JSONEditor

apps/webapp/app/v3/testTask.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,42 @@ export const TestTaskData = z
44
.discriminatedUnion("triggerSource", [
55
z.object({
66
triggerSource: z.literal("STANDARD"),
7-
payload: z.string().transform((payload, ctx) => {
8-
try {
9-
const data = JSON.parse(payload);
10-
return data as any;
11-
} catch (e) {
12-
console.log("parsing error", e);
7+
payload: z
8+
.string()
9+
.optional()
10+
.transform((val, ctx) => {
11+
if (!val) {
12+
return {};
13+
}
1314

14-
if (e instanceof Error) {
15-
ctx.addIssue({
16-
code: z.ZodIssueCode.custom,
17-
message: e.message,
18-
});
19-
} else {
15+
try {
16+
return JSON.parse(val);
17+
} catch {
2018
ctx.addIssue({
2119
code: z.ZodIssueCode.custom,
22-
message: "This is invalid JSON",
20+
message: "Payload must be a valid JSON string",
2321
});
22+
return z.NEVER;
23+
}
24+
}),
25+
metadata: z
26+
.string()
27+
.optional()
28+
.transform((val, ctx) => {
29+
if (!val) {
30+
return {};
2431
}
25-
}
26-
}),
27-
metadata: z.string().transform((metadata, ctx) => {
28-
try {
29-
const data = JSON.parse(metadata);
30-
return data as any;
31-
} catch (e) {
32-
console.log("parsing error", e);
3332

34-
if (e instanceof Error) {
35-
ctx.addIssue({
36-
code: z.ZodIssueCode.custom,
37-
message: e.message,
38-
});
39-
} else {
33+
try {
34+
return JSON.parse(val);
35+
} catch {
4036
ctx.addIssue({
4137
code: z.ZodIssueCode.custom,
42-
message: "This is invalid JSON",
38+
message: "Metadata must be a valid JSON string",
4339
});
40+
return z.NEVER;
4441
}
45-
}
46-
}),
42+
}),
4743
}),
4844
z.object({
4945
triggerSource: z.literal("SCHEDULED"),

0 commit comments

Comments
 (0)