diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateViewModal.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateViewModal.svelte index 6d0a672bc7..6a7f5b96a1 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateViewModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateViewModal.svelte @@ -16,13 +16,13 @@ return } try { - await viewsStore.create({ + const newView = await viewsStore.create({ name, tableId: $tables.selected._id, field, }) notifications.success(`View ${name} created`) - $goto(`../../view/${encodeURIComponent(name)}`) + $goto(`../../view/v2/${newView.id}`) } catch (error) { notifications.error("Error creating view") } diff --git a/packages/builder/src/stores/backend/views.js b/packages/builder/src/stores/backend/views.js index 0ddda1f415..8df337a299 100644 --- a/packages/builder/src/stores/backend/views.js +++ b/packages/builder/src/stores/backend/views.js @@ -41,19 +41,17 @@ export function createViewsStore() { } const create = async view => { - const savedView = await API.viewV2.create(view) + const savedViewResponse = await API.viewV2.create(view) + const savedView = savedViewResponse.data // Update tables tables.update(state => { const table = state.list.find(table => table._id === view.tableId) - if (table) { - if (view.originalName) { - delete table.views[view.originalName] - } - table.views[view.name] = savedView - } + table.views[view.name] = savedView return { ...state } }) + + return savedView } const save = async view => {