Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console): resources can inherit UI components of children #7123

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/@winglang/sdk/src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export interface ConstructTreeNode {
*/
readonly children?: { [key: string]: ConstructTreeNode };

/**
* The default child node path, if any.
*/
readonly defaultChild?: string;

/**
* The node attributes.
*/
Expand Down Expand Up @@ -216,6 +221,7 @@ export function synthesizeTree(app: App, outdir: string) {
id: construct.node.id || "App",
path: construct.node.path,
children: Object.keys(childrenMap).length === 0 ? undefined : childrenMap,
defaultChild: construct.node.defaultChild?.node.path,
constructInfo: constructInfoFromConstruct(construct),
display: synthDisplay(construct),
};
Expand Down
15 changes: 13 additions & 2 deletions packages/@winglang/sdk/src/simulator/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { resolveTokens } from "./tokens";
import { Tree } from "./tree";
import { exists } from "./util";
import { SDK_VERSION } from "../constants";
import { TREE_FILE_PATH } from "../core";
import { TREE_FILE_PATH, UIComponent } from "../core/tree";
import { readJsonSync } from "../shared/misc";
import { CONNECTIONS_FILE_PATH, LogLevel, Trace, TraceType } from "../std";
import { POLICY_FQN } from "../target-sim";
Expand Down Expand Up @@ -679,11 +679,22 @@ export class Simulator {
* @returns An array of UIComponent objects
*/
public getResourceUI(path: string): any {
let components: UIComponent[] = [];
let treeData = this.tree().rawDataForNode(path);
if (!treeData) {
throw new Error(`Resource "${path}" not found.`);
}
return treeData.display?.ui ?? [];
components = [...components, ...(treeData.display?.ui ?? [])];

// Inherit the default child's UI components
if (treeData.defaultChild) {
let defaultChild = this.tree().rawDataForNode(treeData.defaultChild);
if (defaultChild) {
components = [...components, ...(defaultChild.display?.ui ?? [])];
}
}

return components;
}

private typeInfo(fqn: string): TypeSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ exports[`removing a key will call onDelete method 1`] = `
"Sending message (message=unknown.txt, subscriber=sim-3).",
"InvokeAsync (payload="unknown.txt").",
"Publish (messages=unknown.txt).",
"Delete (key=unknown.txt).",
"Received unknown.txt",
"Delete (key=unknown.txt).",
"root/my_bucket/Policy stopped",
"root/my_bucket stopped",
"root/my_bucket/OnDelete/Policy stopped",
Expand All @@ -834,8 +834,8 @@ exports[`update an object in bucket 1`] = `
"InvokeAsync (payload="1.txt").",
"Publish (messages=1.txt).",
"Put (key=1.txt).",
"Put (key=1.txt).",
"I am done",
"Put (key=1.txt).",
"root/my_bucket/Policy stopped",
"root/my_bucket stopped",
"root/my_bucket/OnCreate/Policy stopped",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ exports[`create a counter 1`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -472,6 +473,7 @@ exports[`dec 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -724,6 +726,7 @@ exports[`inc 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -976,6 +979,7 @@ exports[`key dec 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -1228,6 +1232,7 @@ exports[`key inc 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -1478,6 +1483,7 @@ exports[`key set to new value 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down Expand Up @@ -1728,6 +1734,7 @@ exports[`set to new value 2`] = `
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/my_counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ async rename(...args) { return this.backend.rename(...args); }
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/HelloWorld/Counter/Resource",
"display": {
"description": "A distributed atomic counter",
"title": "Counter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ exports.handler = async function(event) {
"fqn": "constructs.Construct",
"version": "10.3.0",
},
"defaultChild": "root/Default",
"display": {},
"id": "root",
"path": "root",
Expand Down
Loading
Loading