This commit is contained in:
Adria Navarro 2024-05-15 11:01:36 +02:00
parent 25d86d179d
commit 062df0ff8b
2 changed files with 6 additions and 20 deletions

View File

@ -79,9 +79,7 @@ export async function search(
} }
const table = await sdk.tables.getTable(options.tableId) const table = await sdk.tables.getTable(options.tableId)
options = searchInputMapping(table, options, { options = searchInputMapping(table, options)
isSql: !!table.sql,
})
if (isExternalTable) { if (isExternalTable) {
return external.search(options, table) return external.search(options, table)

View File

@ -52,8 +52,7 @@ function findColumnInQueries(
function userColumnMapping( function userColumnMapping(
column: string, column: string,
options: RowSearchParams, options: RowSearchParams,
isDeprecatedSingleUserColumn: boolean = false, isDeprecatedSingleUserColumn: boolean = false
isSql: boolean = false
) { ) {
findColumnInQueries(column, options, (filterValue: any): any => { findColumnInQueries(column, options, (filterValue: any): any => {
const isArray = Array.isArray(filterValue), const isArray = Array.isArray(filterValue),
@ -71,33 +70,23 @@ function userColumnMapping(
} }
} }
let wrapper = (s: string) => s
if (isDeprecatedSingleUserColumn && filterValue && isSql) {
// Deprecated single users are stored as stringified arrays of a single value
wrapper = (s: string) => JSON.stringify([s])
}
if (isArray) { if (isArray) {
return filterValue.map(el => { return filterValue.map(el => {
if (typeof el === "string") { if (typeof el === "string") {
return wrapper(processString(el)) return processString(el)
} else { } else {
return el return el
} }
}) })
} else { } else {
return wrapper(processString(filterValue)) return processString(filterValue)
} }
}) })
} }
// maps through the search parameters to check if any of the inputs are invalid // maps through the search parameters to check if any of the inputs are invalid
// based on the table schema, converts them to something that is valid. // based on the table schema, converts them to something that is valid.
export function searchInputMapping( export function searchInputMapping(table: Table, options: RowSearchParams) {
table: Table,
options: RowSearchParams,
datasourceOptions: { isSql?: boolean } = {}
) {
if (!table?.schema) { if (!table?.schema) {
return options return options
} }
@ -119,8 +108,7 @@ export function searchInputMapping(
userColumnMapping( userColumnMapping(
key, key,
options, options,
helpers.schema.isDeprecatedSingleUserColumn(column), helpers.schema.isDeprecatedSingleUserColumn(column)
datasourceOptions.isSql
) )
break break
} }