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

Merged
merged 74 commits into from
Feb 26, 2025
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
df3da17
include allowedTypes for root field
jikim-msft Jan 16, 2025
fd50e40
add condition
jikim-msft Jan 16, 2025
cf42f7a
Revert "add condition"
jikim-msft Jan 16, 2025
1e29755
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Jan 16, 2025
5e96b73
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Jan 16, 2025
9a6793a
change variable name & remove test
jikim-msft Jan 16, 2025
d4c4901
Co-authored-by: Joshua Smithrud <Josmithr@users.noreply.github.com>
jikim-msft Jan 17, 2025
4990a60
change name
jikim-msft Jan 17, 2025
363ced9
handle undefined
jikim-msft Jan 17, 2025
dbf8f9b
refactor / undefined
jikim-msft Jan 17, 2025
d80f2e2
add allowedtypes
jikim-msft Jan 24, 2025
3159b80
fix schema name / remove console
jikim-msft Jan 25, 2025
b40de03
fix doc
jikim-msft Jan 25, 2025
13ee23d
fix test
jikim-msft Jan 25, 2025
a861e7e
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Jan 25, 2025
0746731
make example schema more concise
jikim-msft Jan 27, 2025
f02d1a3
revertible: adds kind
jikim-msft Jan 28, 2025
a77bf59
add requirement
jikim-msft Jan 28, 2025
9132cbb
change name & schema
jikim-msft Jan 29, 2025
4e86139
change name & schema
jikim-msft Jan 29, 2025
08db65a
fix varaible name / add undefined
jikim-msft Jan 29, 2025
e8c06bf
change test
jikim-msft Jan 29, 2025
96a015b
improve doc
jikim-msft Jan 29, 2025
18fbeac
change
jikim-msft Jan 30, 2025
3bc38fb
change param type
jikim-msft Jan 30, 2025
542d26e
changed to map
jikim-msft Jan 30, 2025
279031d
fix doc
jikim-msft Jan 30, 2025
9219ae1
REVERTIBLE: add undefined case
jikim-msft Jan 30, 2025
2d305c6
omit schema for undefined
jikim-msft Jan 31, 2025
a3978ab
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Jan 31, 2025
a284f3a
change fix
jikim-msft Jan 31, 2025
bffadbe
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 1, 2025
f44bd59
Update packages/tools/devtools/devtools-core/src/data-visualization/D…
jikim-msft Feb 4, 2025
7d389dc
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 4, 2025
89d0365
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 4, 2025
035c070
add doc & couple the parameters & add readonly
jikim-msft Feb 4, 2025
fdfa737
change
jikim-msft Feb 4, 2025
446ba37
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 4, 2025
aeee9a2
change type
jikim-msft Feb 4, 2025
dfc6f00
change param
jikim-msft Feb 4, 2025
0f70aae
Revert "change param"
jikim-msft Feb 4, 2025
3fa33c2
Update packages/tools/devtools/devtools-core/src/data-visualization/V…
jikim-msft Feb 7, 2025
809f3fe
Update packages/tools/devtools/devtools-core/src/data-visualization/D…
jikim-msft Feb 7, 2025
472aa64
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 7, 2025
8a650d1
fix nit
jikim-msft Feb 7, 2025
1aa4c02
Merge branch 'devtools/shared-tree-visualizer' of https://github.com/…
jikim-msft Feb 7, 2025
c6519df
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 7, 2025
8fb3ca9
change tree api
jikim-msft Feb 7, 2025
7413066
change name
jikim-msft Feb 8, 2025
3ff216d
nit changes
jikim-msft Feb 10, 2025
60ecfd3
remove optional
jikim-msft Feb 10, 2025
67c0065
fieldschema
jikim-msft Feb 11, 2025
6a4995f
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 11, 2025
735f1d8
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 11, 2025
c366807
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 11, 2025
701f22b
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 11, 2025
4b3f178
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 11, 2025
cfabb66
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 11, 2025
df84d25
change comment
jikim-msft Feb 11, 2025
a451b28
change param type
jikim-msft Feb 11, 2025
59df510
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 12, 2025
60e7f80
REVERTIBLE: change array / map
jikim-msft Feb 12, 2025
2856505
change name
jikim-msft Feb 13, 2025
af9078e
change example schema
jikim-msft Feb 13, 2025
d9ccdc4
fix example code
jikim-msft Feb 13, 2025
4f0c5ed
concise test case & remove function
jikim-msft Feb 13, 2025
f4f0496
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 24, 2025
ea593f4
Update packages/tools/devtools/devtools-core/src/data-visualization/S…
jikim-msft Feb 24, 2025
0cd81ff
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 24, 2025
96ee13d
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 24, 2025
3c40de5
add doc & todo
jikim-msft Feb 26, 2025
32be645
Merge branch 'devtools/shared-tree-visualizer' of https://github.com/…
jikim-msft Feb 26, 2025
0be4036
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 26, 2025
4952676
Merge branch 'main' into devtools/shared-tree-visualizer
jikim-msft Feb 26, 2025
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
Prev Previous commit
Next Next commit
Co-authored-by: Joshua Smithrud <Josmithr@users.noreply.github.com>
jikim-msft committed Jan 17, 2025
commit d4c49019a9ae7101077bc9f364cbbc97e72506be
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ import {
concatenateTypes,
determineNodeKind,
toVisualTree,
visualizeSharedTreeNodeBySchema,
visualizeSharedTreeBySchema,
} from "./SharedTreeVisualizer.js";
import {
VisualSharedTreeNodeKind,
@@ -290,7 +290,7 @@ export const visualizeSharedTree: VisualizeSharedObject = async (
allowedTypes: concatenateTypes(treeSchema.allowedTypes),
},
fields: {
root: await visualizeSharedTreeNodeBySchema(treeView, treeSchema, visualizeChildData),
root: await visualizeSharedTreeBySchema(treeView, treeSchema, visualizeChildData),
},
kind: VisualSharedTreeNodeKind.InternalNode,
};
Original file line number Diff line number Diff line change
@@ -172,16 +172,14 @@ function getObjectAllowedTypes(schema: SimpleObjectNodeSchema): string {
* Returns the schema & fields of the node.
*/
async function visualizeVerboseNodeFields(
tree: VerboseTreeNode,
treeFields: VerboseTree[] | Record<string, VerboseTree>,
treeSchema: SimpleTreeSchema,
visualizeChildData: VisualizeChildData,
): Promise<Record<string, VisualSharedTreeNode>> {
const treeFields = tree.fields;

const fields: Record<string | number, VisualSharedTreeNode> = {};

for (const [fieldKey, childField] of Object.entries(treeFields)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since you are including information about what is allowed in a field, I think it would make more sense to loop over the schema here so currently empty fields would be included.

Also I believe this function processes ObjectNodes, so renaming visualizeVerboseNodeFields to visualizeObjectNode and having it take in an SimpleObjectNodeSchema seems like it would make more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I guess you already have visualizeVerboseNodeFields, so I'm not sure why this exists.

fields[fieldKey] = await visualizeSharedTreeNodeBySchema(
fields[fieldKey] = await visualizeSharedTreeBySchema(
childField,
treeSchema,
visualizeChildData,
@@ -205,7 +203,7 @@ async function visualizeObjectNode(
schemaName: tree.type,
allowedTypes: getObjectAllowedTypes(nodeSchema),
},
fields: await visualizeVerboseNodeFields(tree, treeSchema, visualizeChildData),
fields: await visualizeVerboseNodeFields(tree.fields, treeSchema, visualizeChildData),
kind: VisualSharedTreeNodeKind.InternalNode,
};
}
@@ -224,36 +222,25 @@ async function visualizeMapNode(
schemaName: tree.type,
allowedTypes: `Record<string, ${concatenateTypes(nodeSchema.allowedTypes)}>`,
},
fields: await visualizeVerboseNodeFields(tree, treeSchema, visualizeChildData),
fields: await visualizeVerboseNodeFields(tree.fields, treeSchema, visualizeChildData),
kind: VisualSharedTreeNodeKind.InternalNode,
};
}

/**
* Main recursive helper function to create the visual representation of the SharedTree.
* Processes tree nodes based on their schema type (e.g., ObjectNodeStoredSchema, MapNodeStoredSchema, LeafNodeStoredSchema), producing the visual representation for each type.
* Helper function to create the visual representation of non-leaf SharedTree nodes.
* Processes internal tree nodes based on their schema type (e.g., ObjectNodeStoredSchema, MapNodeStoredSchema, ArrayNodeStoredSchema),
* producing the visual representation for each type.
*
* @see {@link https://fluidframework.com/docs/data-structures/tree/} for more information on the SharedTree schema.
*
* @remarks
*/
export async function visualizeSharedTreeNodeBySchema(
tree: VerboseTree,
async function visualizeSharedTreeNodeBySchema(
tree: VerboseTreeNode,
treeSchema: SimpleTreeSchema,
visualizeChildData: VisualizeChildData,
): Promise<VisualSharedTreeNode> {
const sf = new SchemaFactory(undefined);
if (Tree.is(tree, [sf.boolean, sf.null, sf.number, sf.handle, sf.string])) {
const nodeSchema = Tree.schema(tree);
return {
schema: {
schemaName: nodeSchema.identifier,
},
value: await visualizeChildData(tree),
kind: VisualSharedTreeNodeKind.LeafNode,
};
}

const schema = treeSchema.definitions.get(tree.type);
if (schema === undefined) {
throw new TypeError("Unrecognized schema type.");
@@ -281,7 +268,7 @@ export async function visualizeSharedTreeNodeBySchema(
}

for (let i = 0; i < children.length; i++) {
fields[i] = await visualizeSharedTreeNodeBySchema(
fields[i] = await visualizeSharedTreeBySchema(
children[i],
treeSchema,
visualizeChildData,
@@ -293,7 +280,7 @@ export async function visualizeSharedTreeNodeBySchema(
schemaName: tree.type,
allowedTypes: concatenateTypes(schema.allowedTypes),
},
fields: await visualizeVerboseNodeFields(tree, treeSchema, visualizeChildData),
fields: await visualizeVerboseNodeFields(tree.fields, treeSchema, visualizeChildData),
kind: VisualSharedTreeNodeKind.InternalNode,
};
}
@@ -302,3 +289,38 @@ export async function visualizeSharedTreeNodeBySchema(
}
}
}

/**
* Creates a visual representation of a SharedTree based on its schema.
* @param tree - The {@link VerboseTree} to visualize
* @param treeSchema - The schema that defines the structure and types of the tree
* @param visualizeChildData - Callback function to visualize child node data
* @returns A visual representation of the tree that includes schema information and node values
*
* @remarks
* This function handles both leaf nodes (primitive values, handles) and internal nodes (objects, maps, arrays).
* For leaf nodes, it creates a visual representation with the node's schema and value.
* For internal nodes, it recursively processes the node's fields using {@link visualizeSharedTreeNodeBySchema}.
*/
export async function visualizeSharedTreeBySchema(
tree: VerboseTree,
treeSchema: SimpleTreeSchema,
visualizeChildData: VisualizeChildData,
): Promise<VisualSharedTreeNode> {
const schemaFactory = new SchemaFactory(undefined);
return Tree.is(tree, [
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double-checking: is there an existing "isLeaf" (or something) helper we could use for this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will double check on this. Thanks for the reminder.

Copy link
Contributor Author

@jikim-msft jikim-msft Jan 31, 2025

Choose a reason for hiding this comment

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

There is a treeValue() utiliy function that is consumed internally in the ST package, but I am not sure if I can expose this to outside package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that function doesn't handle Handle nodes.

@CraigMacomber maybe you can advise on the best publicly available pattern for checking if a node is a leaf using the VerboseTree APIs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since leaves in VerboseTree are the same as leaves in regular trees. you can do something like:

const f = new SchemaFactory(undefined);
const leaf = [f.number, f.string, f.null, f.handle, f.boolean];
Tree.is(node, leaf);
``

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I expect us to add a new leaf type anytime soon, but it seems like it would be nice to have this sort of check encapsulated in a single place so we don't have to update all of these hardcoded lists if/when we do add a new leaf type. Not for this PR. but would it be worthwhile to add a centralized isLeaf function for this?

schemaFactory.boolean,
schemaFactory.null,
schemaFactory.number,
schemaFactory.handle,
schemaFactory.string,
])
? {
schema: {
schemaName: Tree.schema(tree).identifier,
},
value: await visualizeChildData(tree),
kind: VisualSharedTreeNodeKind.LeafNode,
}
: visualizeSharedTreeNodeBySchema(tree, treeSchema, visualizeChildData);
}