Improve relationship cell
This commit is contained in:
parent
616e25ac27
commit
66c84b9f82
|
@ -19,9 +19,9 @@
|
||||||
let definition
|
let definition
|
||||||
let primaryDisplay
|
let primaryDisplay
|
||||||
let candidateIndex
|
let candidateIndex
|
||||||
|
let lastSearchId
|
||||||
|
|
||||||
$: editable = selected && !readonly
|
$: editable = selected && !readonly
|
||||||
$: search(searchString)
|
|
||||||
$: results = getResults(searchResults, value)
|
$: results = getResults(searchResults, value)
|
||||||
$: lookupMap = buildLookupMap(value, isOpen)
|
$: lookupMap = buildLookupMap(value, isOpen)
|
||||||
$: {
|
$: {
|
||||||
|
@ -48,29 +48,41 @@
|
||||||
return lookupMap?.[row._id] === true
|
return lookupMap?.[row._id] === true
|
||||||
}
|
}
|
||||||
|
|
||||||
const search = debounce(async searchString => {
|
const search = debounce(async value => {
|
||||||
if (!searchString || !schema?.tableId || !isOpen) {
|
if (!value || !schema?.tableId || !isOpen) {
|
||||||
|
searchString = value
|
||||||
candidateIndex = null
|
candidateIndex = null
|
||||||
searchResults = []
|
searchResults = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastSearchId = Math.random()
|
||||||
|
const thisSearchId = lastSearchId
|
||||||
const results = await API.searchTable({
|
const results = await API.searchTable({
|
||||||
paginate: false,
|
paginate: false,
|
||||||
tableId: schema.tableId,
|
tableId: schema.tableId,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
query: {
|
query: {
|
||||||
string: {
|
string: {
|
||||||
[`1:${primaryDisplay}`]: searchString,
|
[`1:${primaryDisplay}`]: value,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// In case searching takes longer than our debounced update, abandon these
|
||||||
|
// results
|
||||||
|
if (thisSearchId !== lastSearchId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort and process results
|
||||||
searchResults = results.rows?.map(row => ({
|
searchResults = results.rows?.map(row => ({
|
||||||
...row,
|
...row,
|
||||||
primaryDisplay: row[primaryDisplay],
|
primaryDisplay: row[primaryDisplay],
|
||||||
}))
|
}))
|
||||||
candidateIndex = searchResults?.length ? 0 : null
|
candidateIndex = searchResults?.length ? 0 : null
|
||||||
}, 500)
|
searchString = value
|
||||||
|
}, 250)
|
||||||
|
|
||||||
const sortRows = rows => {
|
const sortRows = rows => {
|
||||||
if (!rows?.length) {
|
if (!rows?.length) {
|
||||||
|
@ -161,7 +173,6 @@
|
||||||
{#if relationship.primaryDisplay}
|
{#if relationship.primaryDisplay}
|
||||||
<div class="badge" style="--color: {getColor(idx)}">
|
<div class="badge" style="--color: {getColor(idx)}">
|
||||||
{relationship.primaryDisplay}
|
{relationship.primaryDisplay}
|
||||||
{relationship.primaryDisplay}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -170,9 +181,15 @@
|
||||||
{#if isOpen}
|
{#if isOpen}
|
||||||
<div class="dropdown" on:wheel|stopPropagation>
|
<div class="dropdown" on:wheel|stopPropagation>
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<Input autofocus quiet type="text" bind:value={searchString} />
|
<Input
|
||||||
|
autofocus
|
||||||
|
quiet
|
||||||
|
type="text"
|
||||||
|
value={searchString}
|
||||||
|
on:change={e => search(e.detail)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#if !searchResults?.length}
|
{#if !searchString}
|
||||||
{#if primaryDisplay}
|
{#if primaryDisplay}
|
||||||
<div class="info">
|
<div class="info">
|
||||||
Search for {definition.name} rows by {primaryDisplay}
|
Search for {definition.name} rows by {primaryDisplay}
|
||||||
|
@ -194,9 +211,6 @@
|
||||||
>
|
>
|
||||||
<div class="badge" style="--color: {getColor(idx)}">
|
<div class="badge" style="--color: {getColor(idx)}">
|
||||||
{row.primaryDisplay}
|
{row.primaryDisplay}
|
||||||
{row.primaryDisplay}
|
|
||||||
{row.primaryDisplay}
|
|
||||||
{row.primaryDisplay}
|
|
||||||
</div>
|
</div>
|
||||||
{#if isRowSelected(row)}
|
{#if isRowSelected(row)}
|
||||||
<Icon
|
<Icon
|
||||||
|
@ -238,7 +252,7 @@
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
.result .badge {
|
.result .badge {
|
||||||
max-width: calc(100% - 24px);
|
max-width: 340px;
|
||||||
}
|
}
|
||||||
.dropdown {
|
.dropdown {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
Loading…
Reference in New Issue