From 3a58aa624fa03d1fc9d59b3dd8606f425e8d255f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 20 Jul 2023 09:46:27 +0200 Subject: [PATCH] Use new schema endpoint --- .../TableNavigator/popovers/EditViewPopover.svelte | 4 ++-- .../src/components/commandPalette/CommandPalette.svelte | 9 ++++++++- packages/frontend-core/src/api/viewsV2.js | 7 +++++++ packages/frontend-core/src/fetch/ViewV2Fetch.js | 8 ++------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditViewPopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditViewPopover.svelte index 99f19935a1..febe7c3c84 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditViewPopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditViewPopover.svelte @@ -35,11 +35,11 @@ try { const isSelected = decodeURIComponent($params.viewName) === $views.selectedViewName - const id = view.tableId + const { tableId } = view await views.delete(view) notifications.success("View deleted") if (isSelected) { - $goto(`./table/${id}`) + $goto(`./table/${tableId}`) } } catch (error) { notifications.error("Error deleting view") diff --git a/packages/builder/src/components/commandPalette/CommandPalette.svelte b/packages/builder/src/components/commandPalette/CommandPalette.svelte index 3c95dbbd0b..327e83c48d 100644 --- a/packages/builder/src/components/commandPalette/CommandPalette.svelte +++ b/packages/builder/src/components/commandPalette/CommandPalette.svelte @@ -109,7 +109,14 @@ type: "View", name: view.name, icon: "Remove", - action: () => $goto(`./data/view/${view.name}`), + action: () => { + debugger + if (view.version === 2) { + $goto(`./data/view/v2/${view.id}`) + } else { + $goto(`./data/view/${view.name}`) + } + }, })) ?? []), ...($queries?.list?.map(query => ({ type: "Query", diff --git a/packages/frontend-core/src/api/viewsV2.js b/packages/frontend-core/src/api/viewsV2.js index 98245430d8..a32f4205f8 100644 --- a/packages/frontend-core/src/api/viewsV2.js +++ b/packages/frontend-core/src/api/viewsV2.js @@ -26,4 +26,11 @@ export const buildViewV2Endpoints = API => ({ delete: async viewId => { return await API.delete({ url: `/api/v2/views/${viewId}` }) }, + /** + * Returns schema of a view + * @param viewId the id of the view + */ + getSchema: async viewId => { + return await API.get({ url: `/api/v2/views/${viewId}/schema` }) + }, }) diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js index 1976eb0bd5..d5e643a830 100644 --- a/packages/frontend-core/src/fetch/ViewV2Fetch.js +++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js @@ -1,5 +1,3 @@ -import { get } from "svelte/store" -import { views as viewsStore } from "stores/backend" import DataFetch from "./DataFetch.js" export default class ViewV2Fetch extends DataFetch { @@ -9,10 +7,8 @@ export default class ViewV2Fetch extends DataFetch { async getDefinition(datasource) { try { - const views = get(viewsStore).list - const { tableId } = views.find(v => v.id === datasource.tableId) - const result = await this.API.fetchTableDefinition(tableId) - return result + const { schema } = await this.API.viewV2.getSchema(datasource.tableId) + return { schema } } catch (error) { this.store.update(state => ({ ...state,