Skip to content
Snippets Groups Projects
Commit 49575dcd authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'fix-set-in-element' into 'master'

Fix setInElement on API errors from ListElementEntities

Closes #694 and #729

See merge request !1011
parents 75052216 a14a9b12
No related branches found
No related tags found
1 merge request!1011Fix setInElement on API errors from ListElementEntities
......@@ -34,6 +34,13 @@ export const mutations = {
state.elements = clone(elements)
},
setInElement (state, { id, ...data }) {
// Empty object: remove instead of setting
if (!Object.keys(data).length) {
const newInElement = { ...state.inElement }
delete newInElement[id]
state.inElement = newInElement
return
}
state.inElement = {
...state.inElement,
[id]: data
......@@ -124,7 +131,7 @@ export const actions = {
const data = await api.listElementEntities(id)
commit('setInElement', { id, ...data })
} catch (err) {
commit('setInElement', null)
commit('setInElement', { id })
commit('notifications/notify', { type: 'error', text: errorParser(err) }, { root: true })
}
},
......
......@@ -38,14 +38,23 @@ describe('entity', () => {
assert.deepStrictEqual(state.elements, elementSample)
})
it('setInElement', () => {
const state = initialState()
mutations.setInElement(state, {
id: 'elementid',
...entitiesInElementSample
describe('setInElement', () => {
it('sets the elements of an entity', () => {
const state = initialState()
mutations.setInElement(state, {
id: 'elementid',
...entitiesInElementSample
})
assert.deepStrictEqual(state.inElement, {
elementid: entitiesInElementSample
})
})
assert.deepStrictEqual(state.inElement, {
elementid: entitiesInElementSample
it('deletes the elements of an entity', () => {
const state = initialState()
state.inElement.elementid = entitiesInElementSample
mutations.setInElement(state, { id: 'elementid' })
assert.deepStrictEqual(state.inElement, {})
})
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment