fixes views store

This commit is contained in:
Keviin Åberg Kultalahti 2021-04-01 11:53:22 +02:00
parent 3a8e753eae
commit 50da4159e1
3 changed files with 11 additions and 13 deletions

View File

@ -21,6 +21,7 @@ context("Create a View", () => {
cy.get("input").type("Test View") cy.get("input").type("Test View")
cy.contains("Save View").click() cy.contains("Save View").click()
}) })
cy.wait(1000)
cy.get(".table-title h1").contains("Test View") cy.get(".table-title h1").contains("Test View")
cy.get("[data-cy=table-header]").then($headers => { cy.get("[data-cy=table-header]").then($headers => {
expect($headers).to.have.length(3) expect($headers).to.have.length(3)

View File

@ -44,7 +44,7 @@
<EditTablePopover {table} /> <EditTablePopover {table} />
{/if} {/if}
</NavItem> </NavItem>
{#each Object.keys(table.views || {}) as viewName} {#each Object.keys(table.views || {}) as viewName, idx (idx)}
<NavItem <NavItem
indentLevel={1} indentLevel={1}
icon="ri-eye-line" icon="ri-eye-line"

View File

@ -10,7 +10,7 @@ export function createViewsStore() {
return { return {
subscribe, subscribe,
select: view => { select: async view => {
update(state => ({ update(state => ({
...state, ...state,
selected: view, selected: view,
@ -29,18 +29,15 @@ export function createViewsStore() {
...json, ...json,
} }
update(state => { const viewTable = get(tables).list.find(
const viewTable = get(tables).list.find( table => table._id === view.tableId
table => table._id === view.tableId )
)
if (view.originalName) delete viewTable.views[view.originalName] if (view.originalName) delete viewTable.views[view.originalName]
viewTable.views[view.name] = viewMeta viewTable.views[view.name] = viewMeta
await tables.save(viewTable)
state.tables = state.tables
state.selectedView = viewMeta update(state => ({...state, selected: viewMeta}))
return state
})
}, },
} }
} }