Skip to content
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: parent form field in page settings do not display #1069

Merged
merged 3 commits into from
Jan 25, 2025

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Jan 24, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

页面新建子页面或者子文件夹,父没有正确显示
image

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Improved page management with enhanced parent ID handling.
    • Added new constants for page group categorization.
  • Refactor

    • Optimized state management for page parent selection.
    • Introduced a more robust method for retrieving parent nodes.
  • Bug Fixes

    • Resolved potential issues with parent ID data binding and comparison.

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request focuses on modifying the page management logic in the Vue.js application. Changes are made to PageGeneral.vue and usePage.js, introducing a new computed property pageParentId and two constants STATIC_PAGE_GROUP_ID and COMMON_PAGE_GROUP_ID. The modifications enhance state management for page parent relationships, improve type handling for page IDs, and introduce a new getParentNode function to simplify tree data manipulation.

Changes

File Change Summary
packages/plugins/page/src/PageGeneral.vue - Added pageParentId computed property
- Modified v-model binding for tiny-select
- Updated oldParentId initialization
packages/plugins/page/src/composable/usePage.js - Added STATIC_PAGE_GROUP_ID and COMMON_PAGE_GROUP_ID constants
- Introduced getParentNode function
- Updated changeTreeData function logic

Sequence Diagram

sequenceDiagram
    participant Vue Component
    participant usePage
    participant TreeData
    
    Vue Component->>usePage: Call changeTreeData
    usePage->>usePage: getParentNode(parentId)
    usePage->>TreeData: Retrieve parent node
    usePage->>TreeData: Update tree structure
    TreeData-->>usePage: Return updated data
    usePage-->>Vue Component: Confirm changes
Loading

Possibly related PRs

Suggested reviewers

  • rhlin
  • lichunn

Poem

🐰 In the realm of pages and trees,
Where IDs dance with gentle ease,
A computed prop springs to life,
Cutting through complexity's strife!
Code hops forward, clean and bright 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Jan 24, 2025
@gene9831 gene9831 marked this pull request as ready for review January 24, 2025 07:23
@gene9831
Copy link
Collaborator Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/plugins/page/src/PageGeneral.vue (1)

35-35: Consider renaming the event handler to improve clarity.
The method name changeParentForderId likely contains a typo and could be renamed to something like changeParentFolderId for better readability.

- @change="changeParentForderId"
+ @change="changeParentFolderId"
packages/plugins/page/src/composable/usePage.js (1)

78-80: Consider naming strategy for group IDs.
Hardcoding these numeric IDs is fine for now, but if more groups are introduced, you may want a more scalable naming or an enum-like structure for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48f25c6 and ba62f9f.

📒 Files selected for processing (2)
  • packages/plugins/page/src/PageGeneral.vue (3 hunks)
  • packages/plugins/page/src/composable/usePage.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (4)
packages/plugins/page/src/PageGeneral.vue (3)

97-105: Validate edge cases when forcing the parentId to a string.
Wrapping pageSettingState.currentPageData.parentId in String() ensures consistent string-based comparisons; however, be aware that null, undefined, or other falsy values will become "null" or "undefined" strings. If that’s unintended, consider guarding against these values.


115-115: Check for potential infinite loops or missing entries in treeDataMapping.
While this loop breaks if parent is falsy, ensure parentId always moves closer to ROOT_ID. Any unexpected missing entries or accidental cyclical references could cause issues.


246-246: Good approach exposing pageParentId.
Returning the computed property makes the parent ID logic self-contained and clearly managed within the component.

packages/plugins/page/src/composable/usePage.js (1)

157-162: Handle nonexistent entries in treeDataMapping.
getParentNode may return undefined if treeDataMapping lacks the given parent key. If that scenario is possible, consider returning a fallback or throwing an error.

packages/plugins/page/src/PageGeneral.vue Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/plugins/page/src/composable/usePage.js (2)

157-161: Add JSDoc documentation and type safety.

The function logic is correct, but could benefit from improved documentation and type safety.

+/**
+ * Retrieves the parent node based on the provided parentId
+ * @param {string | number} parentId - The ID of the parent node
+ * @returns {PageNode | undefined} The parent node or undefined if not found
+ */
 const getParentNode = (parentId) => {
+  if (typeof parentId !== 'string' && typeof parentId !== 'number') {
+    return undefined
+  }
   return parentId === pageSettingState.ROOT_ID
     ? { id: pageSettingState.ROOT_ID, children: pageSettingState.pages[STATIC_PAGE_GROUP_ID].data }
     : pageSettingState.treeDataMapping[parentId]
 }

164-171: Add error handling and return value.

While the null checks are good, consider adding error handling and documenting the return value.

+/**
+ * Changes the tree data structure when a node's parent changes
+ * @param {string | number} newParentId - The ID of the new parent
+ * @param {string | number} oldParentId - The ID of the old parent
+ * @returns {boolean} True if the change was successful, false otherwise
+ */
 const changeTreeData = (newParentId, oldParentId) => {
   if (newParentId && oldParentId && String(newParentId) !== String(oldParentId)) {
     const folderData = getParentNode(newParentId)
     const parentData = getParentNode(oldParentId)

     if (!folderData || !parentData) {
-      return
+      return false
     }

     const currentPageDataId = pageSettingState.currentPageData.id
     const curDataIndex = parentData.children?.findIndex?.(({ id }) => id === currentPageDataId)

     if (curDataIndex > -1) {
       const splicedPageData = parentData.children.splice(curDataIndex, 1)[0]
       if (!folderData.children) {
         folderData.children = []
       }
       folderData.children.unshift(splicedPageData)
+      return true
     }
   }
+  return false
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba62f9f and 5f7b024.

📒 Files selected for processing (1)
  • packages/plugins/page/src/composable/usePage.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (1)
packages/plugins/page/src/composable/usePage.js (1)

78-80: LGTM! Good use of constants for page group IDs.

The constants improve code maintainability by replacing magic numbers and are used consistently throughout the code.

@hexqi hexqi merged commit 2d47b79 into opentiny:release/v2.2.0 Jan 25, 2025
2 checks passed
hexqi pushed a commit to hexqi/tiny-engine that referenced this pull request Jan 25, 2025
@gene9831 gene9831 deleted the fix/page-setting-parent branch February 8, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants