-
Notifications
You must be signed in to change notification settings - Fork 341
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
fix: resetCanvasState indirectly called in useHistory, resets the isBlock status #1009
fix: resetCanvasState indirectly called in useHistory, resets the isBlock status #1009
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/toolbars/redoundo/src/composable/useHistory.js (1)
64-64
: LGTM! Consider adding documentation.The addition of
true
as the second argument toimportSchema
correctly preserves the canvas state during history navigation, fixing the issue withisBlock
status being reset. However, the purpose of this parameter isn't immediately clear from the code.Consider adding a comment explaining why
true
is passed here, for example:- useCanvas().importSchema(string2Schema(list[historyState.index]), true) + // Pass true to preserve canvas state properties (e.g., isBlock) during history navigation + useCanvas().importSchema(string2Schema(list[historyState.index]), true)packages/canvas/DesignCanvas/src/api/useCanvas.js (1)
Line range hint
513-525
: Enhance error handling in importSchema.The current error handling only logs to console. Consider providing more context and proper error propagation.
try { importData = JSON.parse(data) } catch (error) { - // eslint-disable-next-line no-console - console.error('[useCanvas.importSchema] Invalid data') + const message = '[useCanvas.importSchema] Failed to parse schema data' + console.error(message, error) + throw new Error(message) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/canvas/DesignCanvas/src/api/useCanvas.js
(3 hunks)packages/toolbars/redoundo/src/composable/useHistory.js
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
🔇 Additional comments (2)
packages/canvas/DesignCanvas/src/api/useCanvas.js (2)
114-126
: LGTM! Well-documented implementation.The addition of the
partial
parameter toresetCanvasState
is well-implemented and properly documented. The conditional state reset logic effectively addresses the issue withisBlock
status being reset during history navigation.
525-526
: Add JSON schema validation.The comment "JSON 格式校验" suggests that JSON validation should be performed, but the implementation is missing.
Let's check if there's a schema validation utility in the codebase:
Would you like me to help implement the JSON schema validation for the canvas state?
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/canvas/DesignCanvas/src/api/useCanvas.js (2)
563-563
: Add unit tests for the new parameters.The changes to
resetCanvasState
andimportSchema
need test coverage to ensure they maintain theisBlock
status correctly.Would you like me to generate unit tests that verify:
resetCanvasState
preservesisBlock
whenpartial
is trueimportSchema
correctly uses theresetPartial
parameter- History navigation maintains the
isBlock
status
563-563
: Document the new parameters in JSDoc.The new parameters need to be documented to explain their purpose and behavior.
Add JSDoc comments for the modified functions:
+/** + * Resets the canvas state + * @param {Object} state - The new state to apply + * @param {boolean} partial - If true, preserves existing state values not present in the new state + */ const resetCanvasState = async (state = {}, partial = false) => { +/** + * Imports schema data into the canvas + * @param {Object|string} data - The schema data to import + * @param {boolean} resetPartial - If true, preserves existing state values during reset + */ const importSchema = (data, resetPartial = false) => {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/canvas/DesignCanvas/src/api/useCanvas.js
(1 hunks)packages/toolbars/redoundo/src/composable/useHistory.js
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/toolbars/redoundo/src/composable/useHistory.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
🔇 Additional comments (1)
packages/canvas/DesignCanvas/src/api/useCanvas.js (1)
563-563
: Update function calls to use the new parameters.Functions that call
resetCanvasState
orimportSchema
need to be updated to use the new parameters correctly.Let's verify the usage of these functions:
adf6551
to
28a6508
Compare
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
历史记录前进或者后退时,会重置全部画布数据,导致部分数据丢失。比如区块中历史记录前进或者后退,画布的
![isblock1](https://private-user-images.githubusercontent.com/26267243/401427971-88d1bbca-836b-4197-abe6-6d7ff42c3396.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5Njc5MTYsIm5iZiI6MTczODk2NzYxNiwicGF0aCI6Ii8yNjI2NzI0My80MDE0Mjc5NzEtODhkMWJiY2EtODM2Yi00MTk3LWFiZTYtNmQ3ZmY0MmMzMzk2LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDIyMzMzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM2NDJkNDg3MTIzOThiNjcxZjBjZWZjYWFmMGEzZTk1YjM0YWZlNGQ2NTU3ODg1NDY4NTY2MzM5MjY0YTMwMWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.IX40cKvuMEQnuvUNlQnCUD6MBQ6PICkb6zl6gtfsm_0)
isBlock
被重置成了false
。下面例子中,画布顶部加了一个路由bar,只有在isBlock
为false
时才显示,但是回退后,出现了路由barWhat is the new behavior?
修改后
![isblock2](https://private-user-images.githubusercontent.com/26267243/401428414-b004e235-1276-44ab-aee7-098cec2dd3f7.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5Njc5MTYsIm5iZiI6MTczODk2NzYxNiwicGF0aCI6Ii8yNjI2NzI0My80MDE0Mjg0MTQtYjAwNGUyMzUtMTI3Ni00NGFiLWFlZTctMDk4Y2VjMmRkM2Y3LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDIyMzMzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU4OGEyYjNkNTE1YmUzMWFhZjE1ODJiYTM4YjU0N2U1NDljNzc1YjAwNWE2NDZlNTQwMWVlYWUyMmM2MDBmYjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.XBHCOa0I4OIGVM9Vmkgjm3FdYfJxpkEa-nyytNPPric)
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Improvements