Type view endpoints
This commit is contained in:
parent
170d45320b
commit
1b467f2e74
|
@ -56,10 +56,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportAllData = async () => {
|
const exportAllData = async () => {
|
||||||
return await API.exportView({
|
return await API.exportView(view, exportFormat)
|
||||||
viewName: view,
|
|
||||||
format: exportFormat,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportFilteredData = async () => {
|
const exportFilteredData = async () => {
|
||||||
|
|
|
@ -43,8 +43,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data = await API.fetchViewData({
|
data = await API.fetchViewData(name, {
|
||||||
name,
|
|
||||||
calculation,
|
calculation,
|
||||||
field,
|
field,
|
||||||
groupBy,
|
groupBy,
|
||||||
|
|
|
@ -30,6 +30,7 @@ import { SelfEndpoints } from "./self"
|
||||||
import { TableEndpoints } from "./tables"
|
import { TableEndpoints } from "./tables"
|
||||||
import { TemplateEndpoints } from "./templates"
|
import { TemplateEndpoints } from "./templates"
|
||||||
import { UserEndpoints } from "./user"
|
import { UserEndpoints } from "./user"
|
||||||
|
import { ViewEndpoints } from "./views"
|
||||||
|
|
||||||
export enum HTTPMethod {
|
export enum HTTPMethod {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
|
@ -130,4 +131,5 @@ export type APIClient = BaseAPIClient &
|
||||||
SelfEndpoints &
|
SelfEndpoints &
|
||||||
TableEndpoints &
|
TableEndpoints &
|
||||||
TemplateEndpoints &
|
TemplateEndpoints &
|
||||||
UserEndpoints & { rowActions: RowActionEndpoints; [key: string]: any }
|
UserEndpoints &
|
||||||
|
ViewEndpoints & { rowActions: RowActionEndpoints; [key: string]: any }
|
||||||
|
|
|
@ -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<Row[]>
|
||||||
|
exportView: (name: string, format: string) => Promise<any>
|
||||||
|
saveView: (view: any) => Promise<any>
|
||||||
|
deleteView: (name: string) => Promise<any>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildViewEndpoints = (API: BaseAPIClient): ViewEndpoints => ({
|
||||||
/**
|
/**
|
||||||
* Fetches all rows in a view
|
* Fetches all rows in a view
|
||||||
* @param name the name of the view
|
* @param name the name of the view
|
||||||
|
@ -6,7 +17,7 @@ export const buildViewEndpoints = API => ({
|
||||||
* @param groupBy the field to group by
|
* @param groupBy the field to group by
|
||||||
* @param calculation the calculation to perform
|
* @param calculation the calculation to perform
|
||||||
*/
|
*/
|
||||||
fetchViewData: async ({ name, field, groupBy, calculation }) => {
|
fetchViewData: async (name, { field, groupBy, calculation }) => {
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
if (calculation) {
|
if (calculation) {
|
||||||
params.set("field", field)
|
params.set("field", field)
|
||||||
|
@ -23,11 +34,11 @@ export const buildViewEndpoints = API => ({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports a view for download
|
* Exports a view for download
|
||||||
* @param viewName the view to export
|
* @param name the view to export
|
||||||
* @param format the format to download
|
* @param format the format to download
|
||||||
*/
|
*/
|
||||||
exportView: async ({ viewName, format }) => {
|
exportView: async (name, format) => {
|
||||||
const safeViewName = encodeURIComponent(viewName)
|
const safeViewName = encodeURIComponent(name)
|
||||||
return await API.get({
|
return await API.get({
|
||||||
url: `/api/views/export?view=${safeViewName}&format=${format}`,
|
url: `/api/views/export?view=${safeViewName}&format=${format}`,
|
||||||
parseResponse: async response => {
|
parseResponse: async response => {
|
||||||
|
@ -51,9 +62,9 @@ export const buildViewEndpoints = API => ({
|
||||||
* Deletes a view.
|
* Deletes a view.
|
||||||
* @param viewName the name of the view to delete
|
* @param viewName the name of the view to delete
|
||||||
*/
|
*/
|
||||||
deleteView: async viewName => {
|
deleteView: async name => {
|
||||||
return await API.delete({
|
return await API.delete({
|
||||||
url: `/api/views/${encodeURIComponent(viewName)}`,
|
url: `/api/views/${encodeURIComponent(name)}`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
|
@ -8,7 +8,7 @@ export default class ViewFetch extends DataFetch {
|
||||||
async getData() {
|
async getData() {
|
||||||
const { datasource } = this.options
|
const { datasource } = this.options
|
||||||
try {
|
try {
|
||||||
const res = await this.API.fetchViewData(datasource)
|
const res = await this.API.fetchViewData(datasource.name)
|
||||||
return { rows: res || [] }
|
return { rows: res || [] }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { rows: [] }
|
return { rows: [] }
|
||||||
|
|
Loading…
Reference in New Issue