-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): Autosuggestions for step variables
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/dashboard/src/utils/parseJSONSchemaToEditorVariables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
interface JSONSchema { | ||
type: string; | ||
properties?: Record<string, JSONSchema>; | ||
items?: JSONSchema; | ||
description?: string; | ||
} | ||
|
||
interface LiquidVariable { | ||
type: 'variable'; | ||
label: string; | ||
detail: string; | ||
} | ||
|
||
/** | ||
* Parse JSON Schema and extract variables for Liquid autocompletion. | ||
* @param schema - The JSON Schema to parse. | ||
* @returns An array of variable objects suitable for the Liquid language. | ||
*/ | ||
export function parseJSONSchemaToLiquidVariables(schema: JSONSchema): LiquidVariable[] { | ||
const variables: LiquidVariable[] = []; | ||
|
||
function extractProperties(obj: JSONSchema, path = ''): void { | ||
if (!obj || typeof obj !== 'object') return; | ||
|
||
if (obj.type === 'object' && obj.properties) { | ||
for (const [key, value] of Object.entries(obj.properties)) { | ||
const fullPath = path ? `${path}.${key}` : key; | ||
|
||
// Add each property as a variable for autocompletion | ||
variables.push({ | ||
type: 'variable', | ||
label: `${fullPath}`, | ||
detail: value.description || 'JSON Schema variable', | ||
}); | ||
|
||
// Recursively process nested objects | ||
if (value.type === 'object' || value.type === 'array') { | ||
extractProperties(value, fullPath); | ||
} | ||
} | ||
} else if (obj.type === 'array' && obj.items) { | ||
// For arrays, add a placeholder for array indexing | ||
extractProperties(obj.items, `${path}[0]`); | ||
} | ||
} | ||
|
||
extractProperties(schema); | ||
return variables; | ||
} |