Add validation, traversal utilities and additional placement strategies#12
Closed
Add validation, traversal utilities and additional placement strategies#12
Conversation
- Add layout validation utilities (validateLayout, isValidLayoutNode, isValidPanelNode, isValidSplitNode) for validating layouts loaded from external sources like localStorage - Add layout traversal utilities (traverseLayout, findAllPanels, findAllSplits, countPanels, findNodeById, findPanelById, getPanelIds, getTreeDepth) for common layout operations - Add additional placement strategies: - lastPanelRightStrategy: adds panels to the right of the rightmost panel - lastPanelBottomStrategy: adds panels below the bottommost panel - equalHeightBottomStrategy: maintains equal heights when adding panels - createFixedPlacementStrategy: factory for custom fixed placement - Add comprehensive tests for all new utilities (96 new tests) https://claude.ai/code/session_016RbWKu8BS3dCvPnovr6Ysc
Code reviewFound 1 issue that needs attention: src/validation.ts (line 355-360)Issue: The Root cause: {
type: "split",
id: "split-1",
orientation: "horizontal",
ratio: 0.5,
left: null, // Invalid! Should be LayoutNode, not null
right: { type: "panel", id: "panel-1" }
}Suggested fix: Add explicit null checks before validating with if (!("left" in nodeObj) || nodeObj.left === null || !isValidLayoutNode(nodeObj.left)) {
return false;
}
if (!("right" in nodeObj) || nodeObj.right === null || !isValidLayoutNode(nodeObj.right)) {
return false;
}This ensures the type guard correctly narrows to Reference: src/validation.ts#L354-L361 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isValidPanelNode, isValidSplitNode) for validating layouts loaded from
external sources like localStorage
findAllSplits, countPanels, findNodeById, findPanelById, getPanelIds,
getTreeDepth) for common layout operations
https://claude.ai/code/session_016RbWKu8BS3dCvPnovr6Ysc