2020-11-19 19:39:22 +01:00
|
|
|
import API from "./api"
|
2020-11-12 13:24:45 +01:00
|
|
|
import { enrichRows } from "./rows"
|
2020-11-12 10:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all rows in a view.
|
|
|
|
*/
|
2020-11-12 13:24:45 +01:00
|
|
|
export const fetchViewData = async ({
|
|
|
|
name,
|
|
|
|
field,
|
|
|
|
groupBy,
|
|
|
|
calculation,
|
|
|
|
tableId,
|
|
|
|
}) => {
|
2020-11-12 10:07:09 +01:00
|
|
|
const params = new URLSearchParams()
|
|
|
|
|
|
|
|
if (calculation) {
|
|
|
|
params.set("field", field)
|
|
|
|
params.set("calculation", calculation)
|
|
|
|
}
|
|
|
|
if (groupBy) {
|
|
|
|
params.set("group", groupBy)
|
|
|
|
}
|
|
|
|
|
|
|
|
const QUERY_VIEW_URL = field
|
|
|
|
? `/api/views/${name}?${params}`
|
|
|
|
: `/api/views/${name}`
|
|
|
|
|
2020-11-19 19:39:22 +01:00
|
|
|
const rows = await API.get({ url: QUERY_VIEW_URL })
|
2020-11-12 13:24:45 +01:00
|
|
|
return await enrichRows(rows, tableId)
|
2020-11-12 10:07:09 +01:00
|
|
|
}
|