1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Honor fields on views

This commit is contained in:
Adria Navarro 2024-08-28 19:05:14 +02:00
parent 1bc1db9b29
commit 383aad7265
5 changed files with 47 additions and 16 deletions

View file

@ -71,8 +71,11 @@ export async function searchView(
})
const searchOptions: RequiredKeys<SearchViewRowRequest> &
RequiredKeys<Pick<RowSearchParams, "tableId" | "query" | "fields">> = {
RequiredKeys<
Pick<RowSearchParams, "tableId" | "viewId" | "query" | "fields">
> = {
tableId: view.tableId,
viewId: view.id,
query: enrichedQuery,
fields: viewFields,
...getSortOptions(body, view),

View file

@ -17,6 +17,7 @@ import {
FieldType,
LinkDocumentValue,
Row,
SquashTableFields,
Table,
TableSchema,
} from "@budibase/types"
@ -245,11 +246,13 @@ function getPrimaryDisplayValue(row: Row, table?: Table) {
* This function will take the given enriched rows and squash the links to only contain the primary display field.
* @param table The table from which the rows originated.
* @param enriched The pre-enriched rows (full docs) which are to be squashed.
* @param squashFields Per link column (key) define which columns are allowed while squashing.
* @returns The rows after having their links squashed to only contain the ID and primary display.
*/
export async function squashLinks<T = Row[] | Row>(
table: Table,
enriched: T
enriched: T,
squashFields?: SquashTableFields
): Promise<T> {
// will populate this as we find them
const linkedTables = [table]
@ -270,17 +273,11 @@ export async function squashLinks<T = Row[] | Row>(
const obj: any = { _id: link._id }
obj.primaryDisplay = getPrimaryDisplayValue(link, linkedTable)
// TODO
// const allowRelationshipSchemas = await features.flags.isEnabled(
// FeatureFlag.ENRICHED_RELATIONSHIPS
// )
// if (schema.schema && allowRelationshipSchemas) {
// for (const relField of Object.entries(schema.schema)
// .filter(([_, field]) => field.visible !== false)
// .map(([fieldKey]) => fieldKey)) {
// obj[relField] = link[relField]
// }
// }
if (squashFields && squashFields[column]) {
for (const relField of squashFields[column].visibleFieldNames) {
obj[relField] = link[relField]
}
}
newLinks.push(obj)
}

View file

@ -86,16 +86,21 @@ export async function search(
options.query = removeInvalidFilters(options.query, queriableFields)
}
let outputRowOptions
if (options.viewId) {
outputRowOptions = sdk.views.outputRowOptions(table, options.viewId)
}
let result: SearchResponse<Row>
if (isExternalTable) {
span?.addTags({ searchType: "external" })
result = await external.search(options, table)
result = await external.search(options, table, outputRowOptions)
} else if (dbCore.isSqsEnabledForTenant()) {
span?.addTags({ searchType: "sqs" })
result = await internal.sqs.search(options, table)
result = await internal.sqs.search(options, table, { outputRowOptions })
} else {
span?.addTags({ searchType: "lucene" })
result = await internal.lucene.search(options, table)
result = await internal.lucene.search(options, table, outputRowOptions)
}
span?.addTags({

View file

@ -1,7 +1,9 @@
import {
FieldType,
OutputRowOptions,
RelationSchemaField,
RenameColumn,
SquashTableFields,
Table,
TableSchema,
View,
@ -250,3 +252,26 @@ export function syncSchema(
return view
}
export function outputRowOptions(
table: Table,
viewId: string
): OutputRowOptions {
const view = Object.values(table.views || {}).find(
(v): v is ViewV2 => sdk.views.isV2(v) && v.id === viewId
)
const viewSchema = view?.schema || {}
const squashFields: SquashTableFields = {}
for (const key of Object.keys(viewSchema)) {
if (viewSchema[key].columns) {
squashFields[key] = {
visibleFieldNames: Object.entries(viewSchema[key].columns)
.filter(([_, c]) => c.visible !== false)
.map(([columnName]) => columnName),
}
}
}
return { squashNestedFields: squashFields }
}

View file

@ -5,6 +5,7 @@ import { WithRequired } from "../shared"
export interface SearchParams {
tableId?: string
viewId?: string
query?: SearchFilters
paginate?: boolean
bookmark?: string | number