Skip to content

Commit

Permalink
Merge branch 'release/druxt-menu-0.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Jan 8, 2024
2 parents ef3067f + 7be612c commit 6ec4587
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/menu/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# druxt-menu

## 0.21.0

### Minor Changes

- 26b1bc6f: feat(#684): added druxtMenu/flushEntities Vuex mutation.

## 0.20.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/menu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "druxt-menu",
"version": "0.20.0",
"version": "0.21.0",
"description": "Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.",
"keywords": [
"cms",
Expand Down
1 change: 1 addition & 0 deletions packages/menu/src/components/DruxtMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default {
mounted() {
// If logged in and statically generated, re-fetch the menu.
if (this?.$auth?.loggedIn && this?.$store?.app?.context?.isStatic) {
this.$store.commit('druxtMenu/flushEntities', { prefix: this.lang })
const settings = this.$options.druxt.settings(this, this.component.settings)
this.$options.druxt.fetchData.call(this, settings)
}
Expand Down
29 changes: 28 additions & 1 deletion packages/menu/src/stores/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ const DruxtMenuStore = ({ store }) => {
const entity = entities[index]
Vue.set(state.entities[prefix], entity.id, entity)
}
}
},

/**
* @name flushEntities
* @mutator {object} flushEntities=entities Removes JSON:API menu item entities from the Vuex state object.
* @param {flushEntitiesContext} context
*
* @example @lang js
* // Flush all menu entities.
* this.$store.commit('druxt/flushCollection', {})
*/
flushEntities (state, { prefix }) {
if (!prefix || typeof state.entities !== 'object') Vue.set(state, 'entities', {})
if (prefix) Vue.set(state.entities, prefix, {})
},
},

/**
Expand Down Expand Up @@ -120,3 +134,16 @@ export { DruxtMenuStore }
* @typedef {object} State
* @property {object} entities - The Drupal JSON:API Menu Item entities.
*/

/**
* Parameters for the `flushEntities` mutation.
*
* @typedef {object} flushEntitiesContext
*
* @param {string} [prefix] - (Optional) The JSON:API endpoint prefix or langcode.
*
* @example @lang js
* {
* prefix: 'en'
* }
*/
18 changes: 18 additions & 0 deletions packages/menu/test/stores/menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ describe('DruxtStore', () => {
expect(store.$druxtMenu.get).toHaveBeenCalledWith('main', { test: true }, undefined)
store.dispatch('druxtMenu/get', 'name')
})

test('AddEntities', async () => {
expect(store.state.druxtMenu.entities).toStrictEqual({})
store.commit('druxtMenu/addEntities', { entities: [{ id: 'test' }] })
expect(Object.entries(store.state.druxtMenu.entities[undefined]).length).toBe(1)
expect(store.state.druxtMenu.entities[undefined].test).toStrictEqual({ id: 'test' })
})

test('flushEntities', async () => {
expect(store.state.druxtMenu.entities).toStrictEqual({})
store.commit('druxtMenu/addEntities', { entities: [{ id: 'test' }] })
store.commit('druxtMenu/addEntities', { entities: [{ id: 'test2' }], prefix: 'es' })
expect(Object.entries(store.state.druxtMenu.entities[undefined]).length).toBe(1)
store.commit('druxtMenu/flushEntities', { prefix: 'undefined' })
expect(Object.entries(store.state.druxtMenu.entities[undefined]).length).toBe(0)
store.commit('druxtMenu/flushEntities', {})
expect(Object.entries(store.state.druxtMenu.entities).length).toBe(0)
})
})
7 changes: 7 additions & 0 deletions packages/site/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# druxt-site

## 0.14.3

### Patch Changes

- Updated dependencies [26b1bc6f]
- [email protected]

## 0.14.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "druxt-site",
"version": "0.14.2",
"version": "0.14.3",
"description": "Out of the box Decoupled Drupal sites with Druxt.",
"keywords": [
"cms",
Expand Down Expand Up @@ -47,7 +47,7 @@
"druxt-blocks": "^0.17.1",
"druxt-breadcrumb": "^0.17.1",
"druxt-entity": "^0.28.0",
"druxt-menu": "^0.20.0",
"druxt-menu": "^0.21.0",
"druxt-router": "^0.29.1",
"druxt-schema": "^0.11.2",
"druxt-views": "^0.22.0",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11240,7 +11240,7 @@ __metadata:
languageName: unknown
linkType: soft

"druxt-menu@^0.20.0, druxt-menu@workspace:packages/menu":
"druxt-menu@^0.21.0, druxt-menu@workspace:packages/menu":
version: 0.0.0-use.local
resolution: "druxt-menu@workspace:packages/menu"
dependencies:
Expand Down Expand Up @@ -11322,7 +11322,7 @@ __metadata:
druxt-blocks: ^0.17.1
druxt-breadcrumb: ^0.17.1
druxt-entity: ^0.28.0
druxt-menu: ^0.20.0
druxt-menu: ^0.21.0
druxt-router: ^0.29.1
druxt-schema: ^0.11.2
druxt-views: ^0.22.0
Expand Down

0 comments on commit 6ec4587

Please sign in to comment.