Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cypress/component/store/tablesStore.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,29 @@ describe('tables store setters', () => {
expect(store.contexts.map(context => context.id)).to.deep.equal([1, 2])
expect(hasStrayIndex(store.contexts)).to.equal(false)
})

it('setView keeps the copy inside table.views in sync', () => {
const store = useTablesStore()
const view = { id: 7, tableId: 4, title: 'Board' }
store.setTables([{ id: 4, title: 'T', views: [view] }])
store.setViews([view])

store.setView({ id: 7, tableId: 4, title: 'Board renamed' })

expect(store.views[0].title).to.equal('Board renamed')
expect(store.tables[0].views[0].title).to.equal('Board renamed')
})

it('removeView drops the view from table.views as well', () => {
cy.intercept('DELETE', '**/apps/tables/view/7', { statusCode: 200, body: true }).as('del')
const store = useTablesStore()
const view = { id: 7, tableId: 4, title: 'Board' }
store.setTables([{ id: 4, title: 'T', views: [view] }])
store.setViews([view])

cy.wrap(null).then(() => store.removeView({ viewId: 7 })).then(() => {
expect(store.views).to.have.length(0)
expect(store.tables[0].views).to.have.length(0)
})
})
})
11 changes: 11 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
if (index !== -1) {
this.views[index] = view
}

const tableViews = this.tables.find(t => t.id === view.tableId)?.views
const tableIndex = tableViews?.findIndex(v => v.id === view.id) ?? -1
if (tableIndex !== -1) {
tableViews[tableIndex] = view
}
},
setContext(context) {
const index = this.contexts.findIndex(c => c.id === context.id)
Expand Down Expand Up @@ -173,7 +179,7 @@
return true
},

/**

Check warning on line 182 in src/store/store.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @PARAM "tables" declaration
* We have two sources of views, this coming from tables endpoint, and those
* that were shared directly or through contexts.
*/
Expand Down Expand Up @@ -262,6 +268,11 @@
const views = this.views
const index = views.findIndex(v => v.id === viewId)
if (index !== -1) {
const tableViews = this.tables.find(t => t.id === views[index].tableId)?.views
const tableIndex = tableViews?.findIndex(v => v.id === viewId) ?? -1
if (tableIndex !== -1) {
tableViews.splice(tableIndex, 1)
}
views.splice(index, 1)
}
this.setViews([...views])
Expand Down
Loading