-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): add Shape discriminated union and render() #76
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
base: p3-13/ui/create-tokens
Are you sure you want to change the base?
Conversation
27be2c9 to
d8d284f
Compare
bfe50a5 to
62ebc0c
Compare
d8d284f to
5c5a02c
Compare
62ebc0c to
0693864
Compare
0693864 to
885a6aa
Compare
Greptile Summary
|
| Filename | Overview |
|---|---|
| packages/ui/src/tests/shapes.test.ts | New comprehensive test file defining API contracts for Shape union types, type guards, unified render function, and format dispatching - requires implementation to pass |
Confidence score: 4/5
- This PR follows the project's TDD-first methodology correctly by implementing failing tests before any implementation
- Score reflects that this is a well-structured test-first approach with comprehensive coverage, but deducted one point due to the tests currently failing by design (RED phase) and requiring substantial implementation work
- Pay close attention to
packages/ui/src/__tests__/shapes.test.tsto understand the complete API contract that needs implementation
Sequence Diagram
sequenceDiagram
participant User
participant render as "render()"
participant TypeGuards as "Type Guards"
participant TableRenderer as "renderTable()"
participant ListRenderer as "renderList()"
participant TreeRenderer as "renderTree()"
participant JsonRenderer as "renderJson()"
participant TextRenderer as "renderText()"
participant MarkdownRenderer as "renderMarkdown()"
User->>render: "render(shape, options?)"
render->>TypeGuards: "Check shape type"
alt Collection with objects
TypeGuards->>render: "isCollection() = true"
render->>TableRenderer: "renderTable(items, headers)"
TableRenderer->>User: "formatted table"
else Collection with primitives
TypeGuards->>render: "isCollection() = true"
render->>ListRenderer: "renderList(items)"
ListRenderer->>User: "bullet list"
else Hierarchy
TypeGuards->>render: "isHierarchy() = true"
render->>TreeRenderer: "renderTree(root)"
TreeRenderer->>User: "tree structure"
else KeyValue
TypeGuards->>render: "isKeyValue() = true"
render->>render: "format key-value pairs"
render->>User: "formatted pairs"
else Resource (json)
TypeGuards->>render: "isResource() = true"
render->>JsonRenderer: "renderJson(data)"
JsonRenderer->>User: "formatted JSON"
else Resource (text)
TypeGuards->>render: "isResource() = true"
render->>TextRenderer: "renderText(data)"
TextRenderer->>User: "plain text"
else Resource (markdown)
TypeGuards->>render: "isResource() = true"
render->>MarkdownRenderer: "renderMarkdown(data)"
MarkdownRenderer->>User: "processed markdown"
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
| const treeResult = renderTree({ root: null }); | ||
| const jsonResult = renderJson({ key: "value" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Test calls renderTree() with { root: null } but Hierarchy type expects TreeNode with name property
| const treeResult = renderTree({ root: null }); | |
| const jsonResult = renderJson({ key: "value" }); | |
| const treeResult = renderTree({ root: { name: "root", children: [] } }); | |
| const jsonResult = renderJson({ key: "value" }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/ui/src/__tests__/shapes.test.ts
Line: 345:346
Comment:
**logic:** Test calls renderTree() with { root: null } but Hierarchy type expects TreeNode with name property
```suggestion
const treeResult = renderTree({ root: { name: "root", children: [] } });
const jsonResult = renderJson({ key: "value" });
```
How can I resolve this? If you propose a fix, please make it concise.555109e to
d3dd7f8
Compare
885a6aa to
0246fb8
Compare
0246fb8 to
f86a139
Compare
d3dd7f8 to
ce4b35b
Compare
|
Restacked after downstack update (formatRelative test stabilization); no additional changes in this PR. |
- Add Shape type: Collection | Hierarchy | KeyValue | Resource - Add type guards: isCollection, isHierarchy, isKeyValue, isResource - Add unified render() function dispatching to correct renderer - TreeNode and related types for hierarchy rendering Fixes #52, #53 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ce4b35b to
9efbf52
Compare
f86a139 to
3daf6f2
Compare
|
Adjusted the standalone renderTree test to use a valid tree object (no null root), now asserting both root and child nodes. |

Fixes #52, #53
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com