Skip to content

Commit c4150d9

Browse files
Copilothotlong
andcommitted
refactor: address code review feedback - derive TARGET_REQUIRED_TYPES from ActionType, add docs for skip behavior
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 23969c6 commit c4150d9

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/spec/src/stack.zod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ function validateCrossReferences(config: ObjectStackDefinition): string[] {
401401
}
402402

403403
// Validate action → flow/target cross-references
404+
// Note: When no flows are defined (flowNames.size === 0), flow-type action targets
405+
// are not validated because the referenced flow may be provided by a plugin.
406+
// This is consistent with dashboard/page/report validation in navigation.
404407
if (config.actions) {
405408
const flowNames = new Set<string>();
406409
if (config.flows) {

packages/spec/src/ui/action.zod.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ export const ActionType = z.enum(['script', 'url', 'modal', 'flow', 'api']);
2424

2525
/**
2626
* Action types that require a `target` field.
27+
* Derived from ActionType, excluding 'script' which allows inline handlers.
2728
* These types reference an external resource (URL, flow, modal, or API endpoint)
2829
* and cannot function without a target binding.
2930
*/
30-
const TARGET_REQUIRED_TYPES: readonly string[] = ['url', 'flow', 'modal', 'api'];
31+
const TARGET_REQUIRED_TYPES = new Set(
32+
ActionType.options.filter((t): t is Exclude<typeof t, 'script'> => t !== 'script'),
33+
);
3134

3235
/**
3336
* Action Schema
@@ -138,7 +141,7 @@ export const ActionSchema = z.object({
138141
return data;
139142
}).refine((data) => {
140143
// Require `target` for types that reference an external resource
141-
if (TARGET_REQUIRED_TYPES.includes(data.type) && !data.target) {
144+
if (TARGET_REQUIRED_TYPES.has(data.type) && !data.target) {
142145
return false;
143146
}
144147
return true;

0 commit comments

Comments
 (0)