Skip to content

Conversation

@galligan
Copy link
Contributor

  • 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

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Adds Shape discriminated union type with Collection, Hierarchy, KeyValue, and Resource variants plus corresponding type guards
  • Introduces unified render() function that dispatches to appropriate renderers based on shape type and format preferences
  • Implements TreeNode types and comprehensive test coverage following TDD RED phase methodology

Important Files Changed

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.ts to 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
Loading

Copy link

@greptile-apps greptile-apps bot left a 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

Edit Code Review Agent Settings | Greptile

Comment on lines 345 to 346
const treeResult = renderTree({ root: null });
const jsonResult = renderJson({ key: "value" });
Copy link

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

Suggested change
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.

@galligan galligan changed the base branch from p3-13/ui/create-tokens to graphite-base/76 January 23, 2026 21:30
@galligan galligan force-pushed the p3-14/ui/shapes-render branch from 885a6aa to 0246fb8 Compare January 23, 2026 21:35
@galligan galligan changed the base branch from graphite-base/76 to p3-13/ui/create-tokens January 23, 2026 21:35
@galligan galligan force-pushed the p3-14/ui/shapes-render branch from 0246fb8 to f86a139 Compare January 23, 2026 23:09
@galligan galligan force-pushed the p3-13/ui/create-tokens branch from d3dd7f8 to ce4b35b Compare January 23, 2026 23:09
@galligan
Copy link
Contributor Author

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>
@galligan galligan changed the base branch from p3-13/ui/create-tokens to graphite-base/76 January 24, 2026 02:50
@galligan galligan force-pushed the p3-14/ui/shapes-render branch from f86a139 to 3daf6f2 Compare January 24, 2026 02:52
@galligan galligan changed the base branch from graphite-base/76 to p3-13/ui/create-tokens January 24, 2026 02:52
@galligan
Copy link
Contributor Author

Adjusted the standalone renderTree test to use a valid tree object (no null root), now asserting both root and child nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants