diff --git a/packages/builder/src/components/backend/DataTable/buttons/ExportButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/ExportButton.svelte index a43629a5a9..fadf6d83da 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/ExportButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/ExportButton.svelte @@ -56,10 +56,7 @@ } const exportAllData = async () => { - return await API.exportView({ - viewName: view, - format: exportFormat, - }) + return await API.exportView(view, exportFormat) } const exportFilteredData = async () => { diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/v1/[viewName]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/v1/[viewName]/index.svelte index 2c822569b7..093999559b 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/v1/[viewName]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/v1/[viewName]/index.svelte @@ -43,8 +43,7 @@ return } try { - data = await API.fetchViewData({ - name, + data = await API.fetchViewData(name, { calculation, field, groupBy, diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 5e0e55d559..08820f750c 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -30,6 +30,7 @@ import { SelfEndpoints } from "./self" import { TableEndpoints } from "./tables" import { TemplateEndpoints } from "./templates" import { UserEndpoints } from "./user" +import { ViewEndpoints } from "./views" export enum HTTPMethod { POST = "POST", @@ -130,4 +131,5 @@ export type APIClient = BaseAPIClient & SelfEndpoints & TableEndpoints & TemplateEndpoints & - UserEndpoints & { rowActions: RowActionEndpoints; [key: string]: any } + UserEndpoints & + ViewEndpoints & { rowActions: RowActionEndpoints; [key: string]: any } diff --git a/packages/frontend-core/src/api/views.js b/packages/frontend-core/src/api/views.ts similarity index 63% rename from packages/frontend-core/src/api/views.js rename to packages/frontend-core/src/api/views.ts index 1d710c5171..3f8ac8aa41 100644 --- a/packages/frontend-core/src/api/views.js +++ b/packages/frontend-core/src/api/views.ts @@ -1,4 +1,15 @@ -export const buildViewEndpoints = API => ({ +import { Row } from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface ViewEndpoints { + // Missing request or response types + fetchViewData: (name: string, opts: any) => Promise + exportView: (name: string, format: string) => Promise + saveView: (view: any) => Promise + deleteView: (name: string) => Promise +} + +export const buildViewEndpoints = (API: BaseAPIClient): ViewEndpoints => ({ /** * Fetches all rows in a view * @param name the name of the view @@ -6,7 +17,7 @@ export const buildViewEndpoints = API => ({ * @param groupBy the field to group by * @param calculation the calculation to perform */ - fetchViewData: async ({ name, field, groupBy, calculation }) => { + fetchViewData: async (name, { field, groupBy, calculation }) => { const params = new URLSearchParams() if (calculation) { params.set("field", field) @@ -23,11 +34,11 @@ export const buildViewEndpoints = API => ({ /** * Exports a view for download - * @param viewName the view to export + * @param name the view to export * @param format the format to download */ - exportView: async ({ viewName, format }) => { - const safeViewName = encodeURIComponent(viewName) + exportView: async (name, format) => { + const safeViewName = encodeURIComponent(name) return await API.get({ url: `/api/views/export?view=${safeViewName}&format=${format}`, parseResponse: async response => { @@ -51,9 +62,9 @@ export const buildViewEndpoints = API => ({ * Deletes a view. * @param viewName the name of the view to delete */ - deleteView: async viewName => { + deleteView: async name => { return await API.delete({ - url: `/api/views/${encodeURIComponent(viewName)}`, + url: `/api/views/${encodeURIComponent(name)}`, }) }, }) diff --git a/packages/frontend-core/src/fetch/ViewFetch.js b/packages/frontend-core/src/fetch/ViewFetch.js index 981969f46c..272c222dd4 100644 --- a/packages/frontend-core/src/fetch/ViewFetch.js +++ b/packages/frontend-core/src/fetch/ViewFetch.js @@ -8,7 +8,7 @@ export default class ViewFetch extends DataFetch { async getData() { const { datasource } = this.options try { - const res = await this.API.fetchViewData(datasource) + const res = await this.API.fetchViewData(datasource.name) return { rows: res || [] } } catch (error) { return { rows: [] }