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(#679): update menu when logged in on static #681

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

Decipher
Copy link
Member

@Decipher Decipher commented Nov 5, 2023

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

Screenshots/Media:

Summary by CodeRabbit

  • New Features
    • Introduced a feature in the "druxt-menu" module that dynamically updates menu items for logged-in users on statically generated sites.
  • Bug Fixes
    • Enhanced the Vue component's lifecycle to fetch fresh menu data under specific conditions, improving user experience.

Copy link

changeset-bot bot commented Nov 5, 2023

🦋 Changeset detected

Latest commit: bec8514

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
druxt-menu Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Nov 5, 2023

Walkthrough

The changes introduce a new feature to the "druxt-menu" module, enabling the update of menu items for logged-in users on a statically generated site. This is achieved by adding a mounted lifecycle hook to the Vue component, which fetches fresh menu data under specific conditions.

Changes

File Summary
.changeset/flat-birds-play.md Introduces a patch to the "druxt-menu" module, adding a feature to update menu items for logged-in users on static sites.
packages/menu/src/components/DruxtMenu.vue Adds a mounted lifecycle hook to fetch fresh menu data if the user is logged in and the site is statically generated.

Poem

🍂 As the leaves fall this November day, 🍁

Code changes dance in a lively ballet. 🩰

Druxt-menu now has a new way, 🔄

To update menus, come what may. 🌐

So here's to the coders, working away, 💻

Making the web a better place to stay. 🌍

Let's celebrate this update, hip hip hooray! 🎉

And continue coding, in our unique way. 🐇


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f8c6b57 and 13d0f73.
Files selected for processing (2)
  • .changeset/flat-birds-play.md (1 hunks)
  • packages/menu/src/components/DruxtMenu.vue (1 hunks)
Additional comments: 2
.changeset/flat-birds-play.md (1)
  • 1-5: The changeset file correctly specifies the module being patched and provides a brief description of the feature being added. Ensure that the feature number (Menu not showing authenticated links #679) corresponds to the correct issue or feature request in your tracking system.
packages/menu/src/components/DruxtMenu.vue (1)
  • 222-228: This new mounted lifecycle hook checks if the user is logged in and if the page is statically generated. If both conditions are met, it clears the value property and fetches the updated menu data using the druxt.fetchData method. This change modifies the behavior of the component when it is mounted under specific conditions, ensuring that the menu items are updated appropriately for logged-in users on static pages.

However, it's important to note that this code assumes the existence of $auth and $store.app.context.isStatic properties. If these properties are not guaranteed to exist in all contexts where this component is used, it would be safer to add additional checks to prevent potential errors.

- if ((this.$auth || {}).loggedIn && this.$store.app.context.isStatic) {
+ if (this.$auth?.loggedIn && this.$store?.app?.context?.isStatic) {

@Decipher
Copy link
Member Author

Decipher commented Nov 5, 2023

Failing tests appear to be passing locally. Investigating.

@Decipher
Copy link
Member Author

Decipher commented Nov 5, 2023

Tests are also failing on develop. Maintenance required.

@Decipher Decipher force-pushed the feature/679-menu_auth branch from 13d0f73 to 15f5c22 Compare November 5, 2023 23:50
Copy link

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7c282de and 15f5c22.
Files selected for processing (2)
  • .changeset/flat-birds-play.md (1 hunks)
  • packages/menu/src/components/DruxtMenu.vue (1 hunks)
Additional comments: 1
.changeset/flat-birds-play.md (1)
  • 1-5: This changeset file correctly specifies the module that is being patched and provides a brief description of the feature being added. Ensure that the feature number (Menu not showing authenticated links #679) corresponds to the correct issue or feature request in your tracking system.

Comment on lines 219 to 229
},
},

mounted() {
// If logged in and statically generated, re-fetch the menu.
if ((this.$auth || {}).loggedIn && this.$store.app.context.isStatic) {
this.value = undefined
const settings = this.$options.druxt.settings(this, this.component.settings)
this.$options.druxt.fetchData.call(this, settings)
}
},
Copy link

Choose a reason for hiding this comment

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

The mounted lifecycle hook has been added to check if the user is logged in and if the page is statically generated. If both conditions are met, it clears the value property and fetches the updated menu data using the druxt.fetchData method. This ensures that the menu items are updated appropriately for logged-in users on static pages.

However, it's important to note that this approach assumes that the this.$auth object and this.$store.app.context.isStatic property are always available and correctly set, which might not always be the case. It would be safer to add some error handling or checks to ensure these properties exist and are in the expected format before using them.

  mounted() {
    // If logged in and statically generated, re-fetch the menu.
-   if ((this.$auth || {}).loggedIn && this.$store.app.context.isStatic) {
+   if (this.$auth?.loggedIn && this.$store?.app?.context?.isStatic) {
      this.value = undefined
      const settings = this.$options.druxt.settings(this, this.component.settings)
      this.$options.druxt.fetchData.call(this, settings)
    }
  },

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
},
},
mounted() {
// If logged in and statically generated, re-fetch the menu.
if ((this.$auth || {}).loggedIn && this.$store.app.context.isStatic) {
this.value = undefined
const settings = this.$options.druxt.settings(this, this.component.settings)
this.$options.druxt.fetchData.call(this, settings)
}
},
mounted() {
// If logged in and statically generated, re-fetch the menu.
if (this.$auth?.loggedIn && this.$store?.app?.context?.isStatic) {
this.value = undefined
const settings = this.$options.druxt.settings(this, this.component.settings)
this.$options.druxt.fetchData.call(this, settings)
}
},

Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Merging #681 (bec8514) into develop (7c282de) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #681   +/-   ##
========================================
  Coverage    96.14%   96.14%           
========================================
  Files           91       91           
  Lines         2362     2362           
  Branches       509      509           
========================================
  Hits          2271     2271           
  Misses          76       76           
  Partials        15       15           
Files Coverage Δ
packages/menu/src/components/DruxtMenu.vue 100.00% <ø> (ø)

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

Copy link

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 15f5c22 and bec8514.
Files selected for processing (1)
  • packages/menu/src/components/DruxtMenu.vue (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/menu/src/components/DruxtMenu.vue

@Decipher Decipher merged commit 6298025 into develop Nov 8, 2023
4 checks passed
@Decipher Decipher deleted the feature/679-menu_auth branch November 8, 2023 23:17
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.

1 participant