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>
import { getContext } from "svelte"
import RelationshipCell from "./RelationshipCell.svelte"
import { FieldSubtype } from "@budibase/types"
import { TableNames } from "../../../constants"
const subtypeToTable = {
[FieldSubtype.USER]: TableNames.USERS,
}
const { API } = getContext("grid")
const { subtype } = $$props.schema
const 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>
<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 invertY = false
export let contentLines = 1
export let searchFunction = API.searchTable
export let primaryDisplay
const { API, dispatch } = getContext("grid")
const color = getColor(0)
@ -38,7 +40,6 @@
let searchResults
let searchString
let lastSearchString
let primaryDisplay
let candidateIndex
let lastSearchId
let searching = false
@ -96,7 +97,7 @@
lastSearchId = Math.random()
searching = true
const thisSearchId = lastSearchId
const results = await API.searchTable({
const results = await searchFunction({
paginate: false,
tableId: schema.tableId,
limit: 20,