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