Filter on the sdk
This commit is contained in:
parent
2186b0407a
commit
d1d86b6803
|
@ -8,7 +8,6 @@ import { gridSocket } from "../../../websockets"
|
|||
import sdk from "../../../sdk"
|
||||
import * as exporters from "../view/exporters"
|
||||
import { apiFileReturn } from "../../../utilities/fileSystem"
|
||||
import _ from "lodash"
|
||||
|
||||
function pickApi(tableId: any) {
|
||||
if (isExternalTable(tableId)) {
|
||||
|
@ -156,7 +155,7 @@ export async function searchView(ctx: Ctx<void, SearchResponse>) {
|
|||
}
|
||||
|
||||
ctx.status = 200
|
||||
let { rows } = await quotas.addQuery(
|
||||
const { rows } = await quotas.addQuery(
|
||||
() =>
|
||||
sdk.rows.search({
|
||||
tableId: view.tableId,
|
||||
|
@ -164,17 +163,13 @@ export async function searchView(ctx: Ctx<void, SearchResponse>) {
|
|||
sort: view.sort?.field,
|
||||
sortOrder: view.sort?.order,
|
||||
sortType: view.sort?.type,
|
||||
fields: view.columns,
|
||||
}),
|
||||
{
|
||||
datasourceId: view.tableId,
|
||||
}
|
||||
)
|
||||
|
||||
const { columns } = view
|
||||
if (columns) {
|
||||
rows = rows.map(r => _.pick(r, columns))
|
||||
}
|
||||
|
||||
ctx.body = { rows }
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { isExternalTable } from "../../../integrations/utils"
|
|||
import * as internal from "./search/internal"
|
||||
import * as external from "./search/external"
|
||||
import { Format } from "../../../api/controllers/view/exporters"
|
||||
import _ from "lodash"
|
||||
|
||||
export interface SearchParams {
|
||||
tableId: string
|
||||
|
@ -15,6 +16,7 @@ export interface SearchParams {
|
|||
sortType?: SortType
|
||||
version?: string
|
||||
disableEscaping?: boolean
|
||||
fields?: string[]
|
||||
}
|
||||
|
||||
export interface ViewParams {
|
||||
|
@ -33,7 +35,12 @@ function pickApi(tableId: any) {
|
|||
export async function search(options: SearchParams): Promise<{
|
||||
rows: any[]
|
||||
}> {
|
||||
return pickApi(options.tableId).search(options)
|
||||
let { rows } = await pickApi(options.tableId).search(options)
|
||||
|
||||
if (options.fields) {
|
||||
rows = rows.map((r: any) => _.pick(r, options.fields!))
|
||||
}
|
||||
return { rows }
|
||||
}
|
||||
|
||||
export interface ExportRowsParams {
|
||||
|
|
Loading…
Reference in New Issue