fix: init app without pageId cannot save page#1440
Conversation
|
""" WalkthroughThe changes refactor the page initialization logic in Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant useResource
participant pagePluginApi
participant useCanvas
participant layout
Caller->>useResource: initPageOrBlock(pageId, ...)
useResource->>pagePluginApi: getPagePluginApi()
alt pageId exists
useResource->>pagePluginApi: getPage(pageId)
pagePluginApi-->>useResource: pageInfo
useResource->>useResource: initPage(pageInfo)
else
useResource->>useResource: initPage(defaultPageInfo)
end
useResource->>layout: setPageStatus(pageInfo.occupier)
useResource->>useCanvas: initData(pageInfo.page_content)
useResource->>layout: setBreadcrumb(pageInfo.name)
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
packages/plugins/materials/src/composable/useResource.ts (1)
71-78: 🛠️ Refactor suggestionUpdate interface to reflect new data structure.
The
PageInfointerface should be updated to reflect the changes in data structure, particularly the addition of properties likeoccupier,page_content, andname.Update the interface to match the new data structure:
interface PageInfo { [x: string]: any meta: any id: string fileName: string + name?: string + occupier?: any + page_content?: any componentName: string props: any }
🧹 Nitpick comments (1)
packages/plugins/materials/src/composable/useResource.ts (1)
143-148: LGTM: Addresses the core issue effectively.This change appears to be the key fix for the issue described in the PR. It properly handles the case where there's no pageId in the URL but a default page exists with an ID, ensuring proper page initialization and saving capability.
Consider adding error handling for the API call to improve robustness:
if (pageInfo.meta?.id) { - const data = await pagePluginApi.getPageById(pageInfo.meta.id) - initPage(data) + try { + const data = await pagePluginApi.getPageById(pageInfo.meta.id) + initPage(data) + } catch (error) { + console.error('Failed to fetch page data:', error) + initPage(toRaw(pageInfo)) + } } else { initPage(toRaw(pageInfo)) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/plugins/materials/src/composable/useResource.ts(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
🔇 Additional comments (5)
packages/plugins/materials/src/composable/useResource.ts (5)
95-95: LGTM: Simplified data handling.The change from destructured schema to
pageInfo?.page_content || {}simplifies the data handling and aligns well with the new data structure approach.
119-119: LGTM: Improved code organization.Moving the
pagePluginApideclaration outside the conditional blocks improves code organization and reduces duplication.
123-123: LGTM: Centralized page initialization logic.Calling
initPage(data)instead of manually setting layout status, canvas data, and breadcrumb centralizes the initialization logic and improves maintainability.
138-141: LGTM: Consistent fallback structure.The change to use
page_contentwith nestedcomponentNamealigns with the new data structure and maintains consistency with how page data is handled throughout the function.
96-96:Details
❓ Verification inconclusive
Verify property name consistency.
The change from
pageInfo.fileNametopageInfo?.namesuggests a property name change in the data structure.Please verify that the property name change is consistent:
🏁 Script executed:
#!/bin/bash # Description: Check for any remaining usage of fileName vs name property # Expected: All should use the name property consistently echo "=== Searching for fileName usage ===" rg -A 2 "fileName" --type ts echo "=== Searching for pageInfo.name usage ===" rg -A 2 "pageInfo\.name" --type tsLength of output: 25845
🏁 Script executed:
#!/bin/bash echo "=== pageInfo in useResource.ts ===" rg -n "pageInfo" packages/plugins/materials/src/composable/useResource.ts echo -e "\n=== Searching for pageInfo.fileName usage ===" rg -A2 "pageInfo\\.fileName" --type ts echo -e "\n=== Inspecting type definitions in types.ts ===" sed -n '1,200p' packages/plugins/materials/src/composable/types.tsLength of output: 4867
🏁 Script executed:
#!/bin/bash echo "=== Imports in useResource.ts ===" sed -n '1,50p' packages/plugins/materials/src/composable/useResource.ts echo -e "\n=== Searching for PageInfo type/interface definition ===" rg -R "interface PageInfo" -n . echo -e "\n=== Searching for type alias PageInfo ===" rg -R "type PageInfo" -n .Length of output: 2516
Confirm PageInfo property name
We searched the repo and found no
pageInfo.fileNameusages—onlypageInfo?.nameat line 96 inuseResource.ts. ThePageInfotype is defined externally (in@opentiny/tiny-engine-meta-register), so please verify that it indeed exposes anameproperty (and notfileName).• packages/plugins/materials/src/composable/useResource.ts: line 96 (
useBreadcrumb().setBreadcrumbPage([pageInfo?.name || '']))
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
【问题描述】
进入设计器时,如果 url 上没有页面 id,编辑画布后保存,无法保存,保存接口会报错。
详见 #1282
【问题分析】
url 上没有页面 id 的逻辑,跟有页面 id 的初始化逻辑有差异,没有页面 id 的初始化逻辑,没有往
initData函数传入页面必要的相关参数,比如route等等。导致点击保存按钮,调用保存接口传参的时候,缺少必要参数,导致报错。【解决方案】
将有页面 id 和没有页面 id 的初始化逻辑保持一致。确保进入应用没有页面 id 时,自动寻找的页面 id 能够得到必要的相关参数。
【自测用例】
What is the current behavior?
Issue Number: #1282
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit