Prevent using invalid data types as display columns

This commit is contained in:
Andrew Kingston 2023-04-17 18:49:36 +01:00
parent 466e11aa57
commit 5d964a756c
2 changed files with 29 additions and 7 deletions

View File

@ -20,6 +20,14 @@
ui, ui,
columns, columns,
} = getContext("sheet") } = getContext("sheet")
const bannedDisplayColumnTypes = [
"link",
"array",
"attachment",
"boolean",
"formula",
"json",
]
let anchor let anchor
let open = false let open = false
@ -151,7 +159,9 @@
<MenuItem <MenuItem
icon="Label" icon="Label"
on:click={makeDisplayColumn} on:click={makeDisplayColumn}
disabled={column.idx === "sticky" || !$config.allowEditColumns} disabled={column.idx === "sticky" ||
!$config.allowEditColumns ||
bannedDisplayColumnTypes.includes(column.schema.type)}
> >
Use as display column Use as display column
</MenuItem> </MenuItem>

View File

@ -57,15 +57,15 @@
} }
// Debounced function to search for rows based on the search string // Debounced function to search for rows based on the search string
const search = debounce(async searchString => { const search = debounce(async (searchString, force = false) => {
// Avoid update state at all if we've already handled the update and this is // Avoid update state at all if we've already handled the update and this is
// a wasted search due to svelte reactivity // a wasted search due to svelte reactivity
if (!searchString && !lastSearchString) { if (!force && !searchString && !lastSearchString) {
return return
} }
// Reset state if this search is invalid // Reset state if this search is invalid
if (!searchString || !schema?.tableId || !isOpen) { if (!schema?.tableId || !isOpen) {
lastSearchString = null lastSearchString = null
candidateIndex = null candidateIndex = null
searchResults = [] searchResults = []
@ -83,7 +83,7 @@
limit: 20, limit: 20,
query: { query: {
string: { string: {
[`1:${primaryDisplay}`]: searchString, [`1:${primaryDisplay}`]: searchString || "",
}, },
}, },
}) })
@ -118,6 +118,8 @@
const open = async () => { const open = async () => {
isOpen = true isOpen = true
searchString = null
search(null, true)
// Fetch definition if required // Fetch definition if required
if (!definition) { if (!definition) {
@ -200,6 +202,16 @@
dispatch("edit-row", relatedRow) dispatch("edit-row", relatedRow)
} }
const readable = value => {
if (value == null) {
return ""
}
if (value instanceof Object) {
return JSON.stringify(value)
}
return value
}
onMount(() => { onMount(() => {
api = { api = {
focus: open, focus: open,
@ -220,7 +232,7 @@
? () => showRelationship(relationship._id) ? () => showRelationship(relationship._id)
: null} : null}
> >
{relationship.primaryDisplay} {readable(relationship.primaryDisplay)}
</span> </span>
{#if editable} {#if editable}
<Icon <Icon
@ -267,7 +279,7 @@
> >
<div class="badge"> <div class="badge">
<span> <span>
{row.primaryDisplay} {readable(row.primaryDisplay)}
</span> </span>
</div> </div>
{#if isRowSelected(row)} {#if isRowSelected(row)}