Allow clicking on relationships in spectrum table

This commit is contained in:
Andrew Kingston 2021-04-12 15:12:59 +01:00
parent afca35a229
commit f76fb21562
4 changed files with 25 additions and 10 deletions

View File

@ -5,6 +5,7 @@
import RelationshipRenderer from "./RelationshipRenderer.svelte" import RelationshipRenderer from "./RelationshipRenderer.svelte"
import AttachmentRenderer from "./AttachmentRenderer.svelte" import AttachmentRenderer from "./AttachmentRenderer.svelte"
export let row
export let schema export let schema
export let value export let value
export let customRenderers = [] export let customRenderers = []
@ -16,7 +17,7 @@
{#if value != null && value !== ''} {#if value != null && value !== ''}
{#if customRenderer} {#if customRenderer}
<svelte:component this={customRenderer.component} {value} /> <svelte:component this={customRenderer.component} {schema} {value} />
{:else if plainTypes.includes(type)} {:else if plainTypes.includes(type)}
<StringRenderer {value} /> <StringRenderer {value} />
{:else if type === 'boolean'} {:else if type === 'boolean'}
@ -24,7 +25,7 @@
{:else if type === 'datetime'} {:else if type === 'datetime'}
<DateTimeRenderer {value} /> <DateTimeRenderer {value} />
{:else if type === 'link'} {:else if type === 'link'}
<RelationshipRenderer {value} /> <RelationshipRenderer {row} {schema} {value} on:clickrelationship />
{:else if type === 'attachment'} {:else if type === 'attachment'}
<AttachmentRenderer {value} /> <AttachmentRenderer {value} />
{/if} {/if}

View File

@ -1,16 +1,30 @@
<script> <script>
import "@spectrum-css/label/dist/index-vars.css" import "@spectrum-css/label/dist/index-vars.css"
import { createEventDispatcher } from "svelte"
export let row
export let value export let value
export let schema
const dispatch = createEventDispatcher()
const displayLimit = 5 const displayLimit = 5
$: relationships = value?.slice(0, displayLimit) ?? [] $: relationships = value?.slice(0, displayLimit) ?? []
$: leftover = (value?.length ?? 0) - relationships.length $: leftover = (value?.length ?? 0) - relationships.length
const onClick = e => {
e.stopPropagation()
dispatch("clickrelationship", {
tableId: row.tableId,
rowId: row._id,
fieldName: schema?.name,
})
}
</script> </script>
{#each relationships as relationship} {#each relationships as relationship}
{#if relationship?.primaryDisplay} {#if relationship?.primaryDisplay}
<span class="spectrum-Label spectrum-Label--grey"> <span class="spectrum-Label spectrum-Label--grey" on:click={onClick}>
{relationship.primaryDisplay} {relationship.primaryDisplay}
</span> </span>
{/if} {/if}

View File

@ -227,8 +227,10 @@
<div class="spectrum-Table-cell-content"> <div class="spectrum-Table-cell-content">
<CellRenderer <CellRenderer
{customRenderers} {customRenderers}
{row}
schema={schema[field]} schema={schema[field]}
value={row[field]} /> value={row[field]}
on:clickrelationship />
</div> </div>
</td> </td>
{/each} {/each}

View File

@ -58,12 +58,9 @@
selectedRows = [] selectedRows = []
} }
const selectRelationship = (row, fieldName) => { const selectRelationship = ({ tableId, rowId, fieldName }) => {
if (!row?.[fieldName]?.length) {
return
}
$goto( $goto(
`/${$params.application}/data/table/${row.tableId}/relationship/${row._id}/${fieldName}` `/builder/${$params.application}/data/table/${tableId}/relationship/${rowId}/${fieldName}`
) )
} }
@ -120,7 +117,8 @@
allowEditColumns={allowEditing} allowEditColumns={allowEditing}
showAutoColumns={!hideAutocolumns} showAutoColumns={!hideAutocolumns}
on:editcolumn={e => editColumn(e.detail)} on:editcolumn={e => editColumn(e.detail)}
on:editrow={e => editRow(e.detail)} /> on:editrow={e => editRow(e.detail)}
on:clickrelationship={e => selectRelationship(e.detail)} />
{/key} {/key}
<Modal bind:this={editRowModal}> <Modal bind:this={editRowModal}>