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(#684): add druxtMenu/flushEntities mutation #689

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

Decipher
Copy link
Member

@Decipher Decipher commented Jan 7, 2024

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

Adds druxtMenu/flushEntities Vuex mutation to allow the menu vuex store to be flushed when logging in/out with an authenticated user.

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

    • Implemented a feature to refresh menu data for logged-in users, ensuring up-to-date information is displayed.
  • Refactor

    • Enhanced the menu data management to allow selective clearing of menu-related data from the application state.

Copy link

changeset-bot bot commented Jan 7, 2024

🦋 Changeset detected

Latest commit: 273a630

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

This PR includes changesets to release 2 packages
Name Type
druxt-menu Minor
druxt-site 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 Jan 7, 2024

Walkthrough

The DruxtMenu component has been updated to enhance cache management for logged-in users on statically generated sites. It now includes functionality to clear specific menu-related entities from the Vuex state before fetching new menu data. This ensures that users see the most current menu information without old data interfering.

Changes

File Path Change Summary
.packages/menu/src/components/DruxtMenu.vue, .changeset/happy-ties-rule.md Added a commit to flush entities with a specific prefix before fetching menu data if logged in and statically generated.
.packages/menu/src/stores/menu.js, .test/stores/menu.test.js Modified DruxtMenuStore to include a new flushEntities mutator function, which removes JSON:API menu item entities from the Vuex state object. This function takes a prefix parameter and can be used to flush all menu entities or entities for a specific prefix. Added tests for the AddEntities and flushEntities functions in the DruxtStore to verify the behavior of adding and flushing entities in the druxtMenu store.

🐇💻✨
In the code burrow, deep and vast,
A rabbit tweaked the menu's past.
Old data flushed, the new shall last,
Ensuring menus are unsurpassed. 🍃🥕

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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 96d693d and 2f0c175.
Files selected for processing (3)
  • .changeset/happy-ties-rule.md (1 hunks)
  • packages/menu/src/components/DruxtMenu.vue (1 hunks)
  • packages/menu/src/stores/menu.js (2 hunks)
Additional comments: 3
.changeset/happy-ties-rule.md (1)
  • 5-5: The changeset description is clear and follows the conventional commit message format.
packages/menu/src/stores/menu.js (1)
  • 49-69: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [26-52]

The addEntities mutation method is implemented correctly, ensuring reactivity with Vue's reactivity system.

packages/menu/src/components/DruxtMenu.vue (1)
  • 225-225: Verify that the settings variable is being used correctly in the mounted lifecycle hook, as it is defined but not used in the provided code snippet.
Verification successful

The previous ast-grep command contained a syntax error. I will correct the pattern and run a new script to check if the settings variable is used within the fetchData method.


The ast-grep pattern still contains a syntax error. I will now use ripgrep (rg) to search for references to the settings variable within the fetchData method.


The ripgrep command contained a regex parse error. I will correct the regex pattern and run a new script to check if the settings variable is used within the fetchData method.


The regex pattern used in the ripgrep command is still causing a parse error. I will simplify the pattern to avoid these issues and attempt to verify the usage of the settings variable within the fetchData method once more.


Based on the output from the latest script, it is evident that the settings variable is indeed used within the fetchData method in the DruxtMenu.vue file. The settings variable is passed as an argument to the fetchData method and is also used within the method itself.

This confirms that the settings variable is being used correctly in the context of the fetchData method, and the review comment concerning the usage of settings is addressed.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if settings variable is used within fetchData method.
ast-grep --lang javascript --pattern $'fetchData($_) {
  $$$
  settings
  $$$
}'

Length of output: 544



Script:

#!/bin/bash
# Corrected command to check if settings variable is used within fetchData method.
ast-grep --lang javascript --pattern $'method_definition[name="fetchData"] {
  $$$
  identifier[name="settings"]
  $$$
}'

Length of output: 626



Script:

#!/bin/bash
# Use ripgrep to search for references to the 'settings' variable within the 'fetchData' method.
rg "fetchData\(.*\)\s*{[^}]*settings[^}]*}" -A 3 -B 3

Length of output: 195



Script:

#!/bin/bash
# Corrected regex pattern to search for references to the 'settings' variable within the 'fetchData' method.
rg "fetchData\(.*\)\s*{.*settings.*}" -A 3 -B 3

Length of output: 183



Script:

#!/bin/bash
# Simplified regex pattern to search for references to the 'settings' variable within the 'fetchData' method.
rg "fetchData" -A 10 -B 10 | rg "settings"

Length of output: 2766

packages/menu/src/stores/menu.js Outdated Show resolved Hide resolved
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 2f0c175 and ddf282e.
Files selected for processing (1)
  • packages/menu/src/stores/menu.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/menu/src/stores/menu.js

Copy link

codecov bot commented Jan 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (96d693d) 96.14% compared to head (273a630) 96.23%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #689      +/-   ##
===========================================
+ Coverage    96.14%   96.23%   +0.09%     
===========================================
  Files           91       91              
  Lines         2362     2367       +5     
  Branches       509      511       +2     
===========================================
+ Hits          2271     2278       +7     
+ Misses          76       74       -2     
  Partials        15       15              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ddf282e and d27e3ca.
Files selected for processing (1)
  • packages/menu/test/stores/menu.test.js (1 hunks)

packages/menu/test/stores/menu.test.js Show resolved Hide resolved
packages/menu/test/stores/menu.test.js Outdated Show resolved Hide resolved
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 d27e3ca and 273a630.
Files selected for processing (1)
  • packages/menu/test/stores/menu.test.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/menu/test/stores/menu.test.js

@Decipher Decipher merged commit 26b1bc6 into develop Jan 8, 2024
9 checks passed
@Decipher Decipher deleted the feature/684-menu_flush_entities branch January 8, 2024 00:46
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