Implement search and push

This commit is contained in:
Adria Navarro 2023-09-15 18:52:50 +02:00
parent 45a474f7ea
commit 79e179d726
2 changed files with 29 additions and 8 deletions

View File

@ -1,16 +1,36 @@
<script> <script>
import { getContext } from "svelte"
import RelationshipCell from "./RelationshipCell.svelte" import RelationshipCell from "./RelationshipCell.svelte"
import { FieldSubtype } from "@budibase/types" import { FieldSubtype } from "@budibase/types"
import { TableNames } from "../../../constants"
const subtypeToTable = { const { API } = getContext("grid")
[FieldSubtype.USER]: TableNames.USERS, const { subtype } = $$props.schema
}
const schema = { const schema = {
...$$props.schema, ...$$props.schema,
tableId: subtypeToTable[$$props.schema.subtype], tableId: "external",
}
async function searchFunction(searchParams) {
if (subtype !== FieldSubtype.USER) {
throw `Search for '${subtype}' not implemented`
}
const results = await API.searchUsers({
...searchParams,
})
return {
...results,
data: undefined,
rows: results.data,
}
} }
</script> </script>
<RelationshipCell {...$$props} {schema} /> <RelationshipCell
{...$$props}
{schema}
{searchFunction}
primaryDisplay={"email"}
relationshipType={"many-to-one"}
/>

View File

@ -30,6 +30,8 @@
export let invertX = false export let invertX = false
export let invertY = false export let invertY = false
export let contentLines = 1 export let contentLines = 1
export let searchFunction = API.searchTable
export let primaryDisplay
const { API, dispatch } = getContext("grid") const { API, dispatch } = getContext("grid")
const color = getColor(0) const color = getColor(0)
@ -38,7 +40,6 @@
let searchResults let searchResults
let searchString let searchString
let lastSearchString let lastSearchString
let primaryDisplay
let candidateIndex let candidateIndex
let lastSearchId let lastSearchId
let searching = false let searching = false
@ -96,7 +97,7 @@
lastSearchId = Math.random() lastSearchId = Math.random()
searching = true searching = true
const thisSearchId = lastSearchId const thisSearchId = lastSearchId
const results = await API.searchTable({ const results = await searchFunction({
paginate: false, paginate: false,
tableId: schema.tableId, tableId: schema.tableId,
limit: 20, limit: 20,