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

feat:preview multi page structured data transfer and nested display #978

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

lichunn
Copy link
Contributor

@lichunn lichunn commented Dec 30, 2024

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?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced page preview functionality with dynamic ancestor retrieval
    • Improved page structure generation with family page support
  • Improvements

    • Updated template and script generation to support more flexible component naming
    • Refined page navigation and preview capabilities
  • Technical Updates

    • Optimized recursive ancestor retrieval methods
    • Added support for additional context in component generation

The release introduces more dynamic page handling and improved preview capabilities across multiple components.

Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (3)
  • refactor/develop
  • ospp-*
  • release/*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces enhancements to page generation and preview functionality across multiple packages. The changes focus on improving the dynamic generation of page structures, particularly in handling page ancestors and family relationships. Key modifications include adding a new getFamilyPages method in Preview.vue, introducing a getFamily function in usePage.js, and updating various generator components to support more flexible page and component generation.

Changes

File Change Summary
packages/design-core/src/preview/src/preview/Preview.vue Added getFamilyPages method to dynamically generate family pages based on ancestors
packages/plugins/page/src/composable/usePage.js Introduced getFamily function and refactored getAncestorsRecursively to improve page ancestor retrieval
packages/toolbars/preview/src/Main.vue Added getFamily to populate params.ancestors during page preview
packages/vue-generator/src/generator/vue/sfc/* Updated multiple generator functions to accept nextPage parameter for more flexible component generation

Sequence Diagram

sequenceDiagram
    participant Main as Main.vue
    participant UsePage as usePage
    participant Preview as Preview.vue
    participant Generator as Vue Generator

    Main->>UsePage: getFamily(pageId)
    UsePage-->>Main: Return page ancestors
    Main->>Preview: Pass ancestors to preview
    Preview->>Preview: Generate family pages
    Preview->>Generator: Generate components with family context
Loading

Possibly related PRs

Suggested Labels

enhancement, ospp-2024

Suggested Reviewers

  • lichunn

Poem

🐰 Hopping through code with glee,
Ancestors traced, pages set free!
Recursive paths, dynamic and bright,
Generating structures with rabbit might!
Code flows smooth, no more delay! 🚀


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.

@gene9831
Copy link
Collaborator

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

✅ 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: 0

🧹 Nitpick comments (5)
packages/vue-generator/src/generator/vue/sfc/generateTemplate.js (1)

197-201: Conditionally replacing RouterView is clever; handle multi-view scenarios.

Replacing 'RouterView' with nextPage helps in dynamic page routing, but watch for edge-cases like multiple RouterView instances in a single layout. Consider how the logic should behave if multiple views exist or if componentName might need further checks.

packages/toolbars/preview/src/Main.vue (1)

33-33: Destructure getFamily for clarity.

Nice extraction of getFamily from usePage. Be mindful of future expansions in the composable, which may group related methods together.

packages/vue-generator/src/generator/vue/sfc/genSetupSFC.js (1)

200-205: Forward nextPage into template generation hooks.

Passing nextPage to genTemplateByHook can be powerful for multi-page logic. Confirm that any plugin hooks expecting fewer parameters remain backward-compatible.

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

214-228: Standalone getAncestorsRecursively function is clearer.

Pulling the recursive logic into its own function neatly separates concerns. This improves readability, though consider whether tail-recursive or iterative approaches might be beneficial if dealing with very deep page trees.


250-259: getFamily filters pages only, reversing for a top-down order.

That’s a straightforward approach. It might be worth adding a default fallback if id is invalid to prevent possible errors or empty returns.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 304e010 and a0c3ddf.

📒 Files selected for processing (6)
  • packages/design-core/src/preview/src/preview/Preview.vue (3 hunks)
  • packages/plugins/page/src/composable/usePage.js (3 hunks)
  • packages/toolbars/preview/src/Main.vue (3 hunks)
  • packages/vue-generator/src/generator/vue/sfc/genSetupSFC.js (3 hunks)
  • packages/vue-generator/src/generator/vue/sfc/generateScript.js (3 hunks)
  • packages/vue-generator/src/generator/vue/sfc/generateTemplate.js (4 hunks)
🔇 Additional comments (20)
packages/vue-generator/src/generator/vue/sfc/generateTemplate.js (3)

175-175: Introduce nextPage parameter carefully.

Adding nextPage as a parameter to recursiveGenTemplateByHook broadens its functionality and looks consistent with other changes. Ensure all call sites pass the correct type, and handle the case where nextPage might be null or undefined.


214-214: Propagate nextPage to downstream hooks.

Ensuring the nextPage argument is passed to each hookItem preserves the intended logic. Confirm any custom hooks can handle (or ignore) this parameter correctly.


236-242: New usage pattern with nextPage looks consistent.

Both genTemplateByHook and the internal call to recursiveGenTemplateByHook properly integrate nextPage. The usage is coherent with the rest of the code changes.

packages/toolbars/preview/src/Main.vue (2)

15-15: Import usePage usage is appropriate.

Importing usePage aligns well with the newly introduced getFamily function. No issues noted.


83-83: Validate the result of getFamily.

Assigning params.ancestors = await getFamily(params.id) is a good approach. Consider safeguarding if getFamily returns an empty array or any unexpected structure, especially for invalid page IDs.

packages/vue-generator/src/generator/vue/sfc/genSetupSFC.js (3)

70-70: Add nextPage parameter to generateSFCFile.

This additional parameter broadens the function’s scope. Verify that calling code consistently provides nextPage where needed and handles the case if it’s absent or null.


208-208: Script generation also respects new param.

genScriptByHook alignment with nextPage suggests a consistent approach across template and script generation. This looks good.


216-216: genSFCWithDefaultPlugin integrates nextPage thoroughly.

The expansion of function signatures and final call to generateSFCFile with nextPage ensures the entire SFC pipeline can handle pagination or additional next-page context seamlessly.

Also applies to: 273-273

packages/design-core/src/preview/src/preview/Preview.vue (6)

46-46: Synchronized export of getAllNestedBlocksSchema and generatePageCode.

Extracting these methods from getMetaApi here is consistent with usage. Confirm they remain in sync with the importer’s version.


88-88: New helper function getFamilyPages.

Introducing getFamilyPages to gather an array of pages based on ancestors is a clean approach. This new layer systematically organizes the page data.


89-89: Use const for familyPages instead of let.

As previously noted, the reference to familyPages is never reassigned, so changing it to const enhances clarity and enforces immutability.


94-94: Replace '0' with pageSettingState.ROOT_ID if feasible.

As previously mentioned, referencing '0' directly may be fragile. Using pageSettingState.ROOT_ID is more consistent and self-documenting.


95-108: Combine repeated logic to reduce duplication.

These two blocks differ only in a couple of fields (panelName: 'Main.vue' and index). You might factor out the shared logic to a helper, as previously suggested.

Also applies to: 110-123


144-144: Insert getFamilyPages result seamlessly.

Appending getFamilyPages(appData) to pageCode before blocks is well-integrated. The final array merges hierarchy-based pages with block-based pages for a consolidated preview experience.

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

276-276: Expose getFamily in default export.

Exporting getFamily for broader usage is in line with the new logic in Main.vue and Preview.vue. This maintains consistency across the codebase.

packages/vue-generator/src/generator/vue/sfc/generateScript.js (5)

8-8: Ensure consistency in calling the modified function.
You've added config and nextPage to the defaultGenImportHook parameters. Verify that all existing call sites have been updated accordingly to avoid undefined or incorrect usage.


10-12: Avoid capitalizing non-class variables.
This mirrors a prior suggestion: consider renaming ImportContent to a lowercase format (e.g. importContent) for clarity and consistency.


14-16: Validate or sanitize nextPage before using it in an import statement.
Conditional import logic is powerful, but be sure you trust or sanitize nextPage to mitigate potential security risks with dynamic imports.


168-168: Double-check new parameter usage in genScriptByHook.
The addition of the nextPage parameter looks fine, but confirm all callers correctly pass it and that it’s not inadvertently omitted.


212-212: Confirm consistent usage of nextPage.
At line 212, genScript[GEN_SCRIPT_HOOKS.GEN_IMPORT] now takes nextPage. Make sure this parameter aligns with the rest of the codebase, especially in downstream calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants