From 50da4159e1592a49d1ebcc81555681bac6e3f1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Thu, 1 Apr 2021 11:53:22 +0200 Subject: [PATCH] fixes views store --- .../cypress/integration/createView.spec.js | 1 + .../TableNavigator/TableNavigator.svelte | 2 +- packages/builder/src/stores/backend/views.js | 21 ++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/builder/cypress/integration/createView.spec.js b/packages/builder/cypress/integration/createView.spec.js index 4d8e2a8134..3ef15c0d9e 100644 --- a/packages/builder/cypress/integration/createView.spec.js +++ b/packages/builder/cypress/integration/createView.spec.js @@ -21,6 +21,7 @@ context("Create a View", () => { cy.get("input").type("Test View") cy.contains("Save View").click() }) + cy.wait(1000) cy.get(".table-title h1").contains("Test View") cy.get("[data-cy=table-header]").then($headers => { expect($headers).to.have.length(3) diff --git a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte index 4e7f430a1c..2b6e775c9a 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte @@ -44,7 +44,7 @@ {/if} - {#each Object.keys(table.views || {}) as viewName} + {#each Object.keys(table.views || {}) as viewName, idx (idx)} { + select: async view => { update(state => ({ ...state, selected: view, @@ -29,18 +29,15 @@ export function createViewsStore() { ...json, } - update(state => { - const viewTable = get(tables).list.find( - table => table._id === view.tableId - ) + const viewTable = get(tables).list.find( + table => table._id === view.tableId + ) - if (view.originalName) delete viewTable.views[view.originalName] - viewTable.views[view.name] = viewMeta - - state.tables = state.tables - state.selectedView = viewMeta - return state - }) + if (view.originalName) delete viewTable.views[view.originalName] + viewTable.views[view.name] = viewMeta + await tables.save(viewTable) + + update(state => ({...state, selected: viewMeta})) }, } }