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(devtools-core): Render ST's Visualizer to Include Root Field's Allowed Types #23573

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

jikim-msft
Copy link
Contributor

@jikim-msft jikim-msft commented Jan 16, 2025

Description

26472

The current visualization generation logic in DefaultVisualizers.ts treats the root of the shared tree as a node and thus omits information that should be included in the root of the ST visualizer. Since the root field is allowed to have multiple types (i.e., different schema or primitive types), this information should be rendered in the tooltip of the visualizer.

This PR changes how the visualizer renders the allowed types in the tooltip

Example Schema

const config = new TreeViewConfiguration({
			schema: [RootNodeOne, RootNodeTwo, builder.string, builder.number],
		});

Before
Screenshot 2025-01-15 at 16 38 24

After
Defined
Screenshot 2025-01-29 at 19 48 01

Undefined
Screenshot 2025-01-29 at 19 43 32

@github-actions github-actions bot added the base: main PRs targeted against main branch label Jan 16, 2025
@jikim-msft jikim-msft requested a review from Josmithr January 17, 2025 23:36
@jikim-msft jikim-msft marked this pull request as ready for review January 25, 2025 02:14
@jikim-msft jikim-msft requested a review from a team as a code owner January 25, 2025 02:14
Copy link
Contributor

@Josmithr Josmithr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a handful more comments, but overall this is looking really great! I suspect it will be ready for approval after you address these few comment.

treeSchema: SimpleTreeSchema,
treeFields: readonly VerboseTree[] | Record<string, VerboseTree>,
treeDefinitions: ReadonlyMap<string, SimpleNodeSchema>,
allowedTypes: Record<string, ReadonlySet<string>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Josmithr

Unlike coupling the allowedTypes and isRequired in visualizeSharedTreeBySchema(), I decided to leave these two parameters separately, since it isn't the entry point for the ST visualizer and I thought the doc describes when the requirements can be undefined.

Interested in your thought.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you could combine the properties differently in this case, which might be a bit cleaner. E.g.,

fieldSchemaProperties: Record<string, FieldSchemaProperties>

Where you have a single record, instead of 2, that maps the field key to both of the relevant properties.

* Set of type names that are valid for this specific node position in the tree.
* This is a subset of the types defined in treeDefinitions.
*/
allowedTypes?: ReadonlySet<string>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the properties here need to be optional?

Copy link
Contributor Author

@jikim-msft jikim-msft Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted it to align with the optionality of VisualSharedTreeTypes.ts (SharedTreeSchemaNode). Hence, marked it optional since non-ST VisualNodes do not need allowed types at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants