Avoid relationship picker making rows calls for empty string ID

This commit is contained in:
Andrew Kingston 2021-02-12 11:17:13 +00:00
parent 075de3edaf
commit bd7d95aabc
2 changed files with 2 additions and 61 deletions

View File

@ -1,59 +0,0 @@
<script>
import { Label, Multiselect } from "@budibase/bbui"
import { capitalise } from "./helpers"
import { getContext } from "svelte"
const { API } = getContext("sdk")
export let schema = {}
export let linkedRows = []
export let showLabel = true
export let secondary
let linkedTable
let allRows = []
$: label = capitalise(schema.name)
$: linkedTableId = schema.tableId
$: fetchRows(linkedTableId)
$: fetchTable(linkedTableId)
async function fetchTable(id) {
if (id != null) {
linkedTable = await API.fetchTableDefinition(id)
}
}
async function fetchRows(id) {
if (id != null) {
allRows = await API.fetchTableData(id)
}
}
function getPrettyName(row) {
return row[(linkedTable && linkedTable.primaryDisplay) || "_id"]
}
</script>
{#if linkedTable != null}
{#if linkedTable.primaryDisplay == null}
{#if showLabel}
<Label extraSmall grey>{label}</Label>
{/if}
<Label small black>
Please choose a display column for the
<b>{linkedTable.name}</b>
table.
</Label>
{:else}
<Multiselect
{secondary}
bind:value={linkedRows}
label={showLabel ? label : null}
placeholder="Choose some options">
{#each allRows as row}
<option value={row._id}>{getPrettyName(row)}</option>
{/each}
</Multiselect>
{/if}
{/if}

View File

@ -24,7 +24,7 @@
$: fetchTable(linkedTableId) $: fetchTable(linkedTableId)
const fetchTable = async id => { const fetchTable = async id => {
if (id != null) { if (id) {
const result = await API.fetchTableDefinition(id) const result = await API.fetchTableDefinition(id)
if (!result.error) { if (!result.error) {
tableDefinition = result tableDefinition = result
@ -33,7 +33,7 @@
} }
const fetchRows = async id => { const fetchRows = async id => {
if (id != null) { if (id) {
const rows = await API.fetchTableData(id) const rows = await API.fetchTableData(id)
options = rows && !rows.error ? rows : [] options = rows && !rows.error ? rows : []
} }