Skip to content

feat:adjust the homepage and default page settings mode#1214

Merged
hexqi merged 8 commits intoopentiny:developfrom
lichunn:feat/page-child
Mar 19, 2025
Merged

feat:adjust the homepage and default page settings mode#1214
hexqi merged 8 commits intoopentiny:developfrom
lichunn:feat/page-child

Conversation

@lichunn
Copy link
Collaborator

@lichunn lichunn commented Mar 12, 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?

Issue Number: N/A

What is the new behavior?

1、主页调整为在下拉菜单设置
2、默认页调整为由父级页面在设置面板下拉选择,保存时更新子页面状态

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Introduced a “Set as Home” option in the page tree that lets users designate a page as the home page following confirmation.
    • Enhanced the default page selection experience by replacing the checkbox with an intuitive dropdown menu for choosing from available child pages.
    • Improved notification behavior during page updates, offering more flexible display of success alerts based on user actions.
    • Added a new method to set a default page, ensuring the default page state is updated appropriately during page edits.
    • Added a new event handler to allow setting a page as the home page from the page tree component.
    • Introduced a new property to store the default page setting for the current page.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

Walkthrough

The changes update the page management workflow by modifying function signatures to include an isUpdateTree parameter, allowing callers to selectively control notifications and tree updates. New functions and event handlers are introduced to support setting a page as the home page and managing default page selections. UI elements have been updated by replacing checkboxes with dropdowns, and reactive state management has been enhanced through additional properties and methods to better handle page default settings.

Changes

File(s) Change Summary
packages/common/js/http.js
packages/plugins/page/src/PageSetting.vue
Updated page update functions to include an additional isUpdateTree parameter. In handlePageUpdate and updatePage, conditional notification display is implemented. A new function (settingDefaultPage) calls updatePage with notifications suppressed.
packages/plugins/page/src/Main.vue
packages/plugins/page/src/PageTree.vue
Added home page functionality. A new settingHome method is introduced to handle setting a page as the home page, including event emission and modal confirmation via imported hooks (useModal, useNotify). The row operations in PageTree.vue are updated to include the "设置为主页" option with appropriate filtering.
packages/plugins/page/src/PageGeneral.vue
packages/plugins/page/src/composable/usePage.js
Enhanced default page selection UI and logic. In PageGeneral.vue, a dropdown (tiny-select) replaces the checkbox for selecting a default page, with new reactive state (defaultPageId) and helper methods (setChildAndDefaultPage, changeDefaultPage). In usePage.js, a new defaultPage property and resetPageData function are introduced to manage default page settings.

Possibly related PRs

Suggested labels

enhancement, bug

Suggested reviewers

  • hexqi
  • rhlin

Poem

I'm a bouncy little rabbit, coding in the den,
Skipping through changes on paths with a hop and a pen.
Notifications now can hide or gleam, oh what a sight,
Home pages set with a modal's light.
Default pages chosen by a dropdown's cheer,
My whiskers twitch with joy—coding magic is here!
🐰 Happy hops to every commit!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc3793b and b865ae9.

📒 Files selected for processing (1)
  • packages/plugins/page/src/PageSetting.vue (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/page/src/PageSetting.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check

🪧 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.
  • @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.

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/PageGeneral.vue (2)

56-67: Replaced checkbox with dropdown for default page selection.

The UI enhancement from checkbox to dropdown allows users to select a specific child page as the default, which is more intuitive than the previous approach. However, consider these improvements:

  1. Add a "None" option to allow clearing the default page selection
  2. Include visual feedback when the selection is saved
<tiny-select
  v-model="state.defaultPageId"
  :options="state.childPageOp"
  placeholder="请选择默认跳转页"
  @change="changeDefaultPage"
+  clearable
></tiny-select>

117-136: Add error handling to the async child page fetching.

The function to set child and default pages should include error handling for the asynchronous operation.

const setChildAndDefaultPage = async (id) => {
  if (pageSettingState.isNew) {
    state.childPageList = []
    state.childPageOp = []
    state.defaultPageId = ''
  } else {
-   state.childPageList = await getPageChildren(id)
-   if (state.childPageList?.length) {
-     state.defaultPageId = state.childPageList?.find((item) => item.isDefault)?.id
-     state.childPageOp = state.childPageList.map((item) => {
-       return {
-         value: item.id,
-         label: item.name,
-         icon: iconFile()
-       }
-     })
-     setDefaultPage(state.childPageList, state.defaultPageId)
-   }
+   try {
+     state.childPageList = await getPageChildren(id)
+     if (state.childPageList?.length) {
+       state.defaultPageId = state.childPageList?.find((item) => item.isDefault)?.id
+       state.childPageOp = state.childPageList.map((item) => {
+         return {
+           value: item.id,
+           label: item.name,
+           icon: iconFile()
+         }
+       })
+       setDefaultPage(state.childPageList, state.defaultPageId)
+     }
+   } catch (error) {
+     console.error('Failed to fetch child pages:', error)
+     // Consider adding user notification here
+   }
  }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66a6d00 and e292232.

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

40-40: Function signature enhancement adds flexibility for notification control.

The addition of the isShowNotify parameter with a default value of true provides a clean way to control notification display while maintaining backward compatibility with existing code.


60-62: Good implementation of conditional notification.

This conditional block properly implements the notification toggle feature based on the new parameter. The code is clean and follows the existing code style.

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

69-69: New reactive state property for tracking default page.

The addition of the defaultPage property to the reactive state object is a good approach for managing the default page state.


197-197: Proper state reset for defaultPage.

Resetting the defaultPage to null in the resetPageData function ensures clean state management when navigating between pages.


493-497: Well-implemented utility function with proper null checks.

The setDefaultPage function is properly implemented with null/empty checks to prevent errors. It efficiently finds and sets the default page from a list of child pages based on an ID.


519-519: Appropriate export of the new function.

Adding the new setDefaultPage function to the exports makes it accessible to other components that need this functionality.

packages/plugins/page/src/PageSetting.vue (5)

211-211: Updated function signature maintains consistency with http.js changes.

The addition of the isShowNotify parameter with a default value of true aligns with the changes in the handlePageUpdate function, ensuring consistent notification behavior.


215-215: Proper propagation of notification control parameter.

The isShowNotify parameter is correctly passed to the handlePageUpdate function, ensuring the notification control works throughout the call chain.


276-276: Appropriate reset of defaultPage during copy operation.

Resetting the defaultPage to null when copying a page prevents unintended inheritance of default page settings from the original page.


295-298: New utility function for setting default page.

The settingDefaultPage function provides a clean way to update the default page settings. Passing false to updatePage for the isShowNotify parameter is a good choice to avoid redundant notifications when multiple updates are happening in sequence.


312-312: Sequential update of default page after main page edit.

Calling settingDefaultPage after editPage ensures that both the main page content and the default page settings are updated in the correct sequence.

packages/plugins/page/src/Main.vue (5)

28-28: New event handler for setting homepage.

The addition of the @settingHome event handler connects the UI action to the corresponding functionality.


40-41: Imported necessary hooks for notification and confirmation.

The addition of useModal and useNotify imports provides access to the confirmation dialog and notification functionality needed for the new feature.


46-46: Imported API function for homepage update.

The import of handleRouteHomeUpdate provides access to the API function needed to persist homepage changes.


122-141: Well-implemented homepage setting function with user confirmation.

The settingHome function properly:

  1. Uses a confirmation dialog to prevent accidental changes
  2. Constructs the necessary parameters
  3. Calls the appropriate API function
  4. Handles success and error states with notifications
  5. Updates the UI state to reflect the change

This implementation follows good practices for user interaction and state management.


186-188: Appropriate export of the new functionality.

Adding the settingHome function to the exports makes it accessible to other components that need this functionality.

packages/plugins/page/src/PageTree.vue (4)

99-99: Good enhancement with the settingHome event.

Adding the 'settingHome' event to the emits array is a clear way to extend the component's API. The explicit declaration in the emits array follows Vue 3 best practices.


244-246: Implement the settingHome handler correctly.

The handler is well-formed, with a clean implementation that simply emits the necessary event with the node data.


253-253: UI labeling looks good with a descriptive action name.

The "设置为主页" (Set as Home) label clearly indicates the purpose of this action.


271-273: Appropriate filtering logic for the settingHome operation.

The filtering logic prevents the "Set as Home" operation from appearing for non-page nodes or public group pages, which is a good UX decision.

packages/plugins/page/src/PageGeneral.vue (6)

73-75: Import statements updated correctly for new component requirements.

The imports were updated to properly support the changes, such as adding reactive and removing the unused Checkbox import.


98-98: Properly destructured additional methods from usePage.

The methods getPageChildren and setDefaultPage are now correctly imported from the usePage composable.


111-115: Well-structured reactive state for child page management.

The reactive state object is well-organized with clear property names for child page list, options, and the selected default page ID.


138-140: Default page change handler is clean and concise.

The changeDefaultPage method effectively updates the default page using the shared setDefaultPage method.


144-144: WatchEffect now correctly initializes child pages.

The watchEffect hook has been properly updated to call the new setChildAndDefaultPage method when dependencies change.


286-287: Successfully exported new state and methods.

The new reactive state and changeDefaultPage method are properly added to the returned object, making them available to the template.

@hexqi hexqi added this to the v2.4.0 milestone Mar 17, 2025
@hexqi hexqi merged commit 564f929 into opentiny:develop Mar 19, 2025
1 check passed
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.

2 participants