forked from tsai/budibase
5 changed files with 26 additions and 107 deletions
@ -1,80 +1,28 @@ |
|||||
<script> |
<script> |
||||
import { onMount } from "svelte" |
|
||||
import { goto, params } from "@sveltech/routify" |
|
||||
import api from "builderStore/api" |
|
||||
import { getTable } from "./tableCache" |
|
||||
|
|
||||
export let columnName |
export let columnName |
||||
export let row |
export let row |
||||
|
export let selectRelationship |
||||
|
|
||||
$: count = |
$: count = |
||||
row && columnName && Array.isArray(row[columnName]) |
row && columnName && Array.isArray(row[columnName]) |
||||
? row[columnName].length |
? row[columnName].length |
||||
: 0 |
: 0 |
||||
let linkedRows = [] |
|
||||
let displayColumn |
|
||||
|
|
||||
onMount(async () => { |
|
||||
linkedRows = await fetchLinkedRowsData(row, columnName) |
|
||||
if (linkedRows && linkedRows.length) { |
|
||||
const table = await getTable(linkedRows[0].tableId) |
|
||||
if (table && table.primaryDisplay) { |
|
||||
displayColumn = table.primaryDisplay |
|
||||
} |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
async function fetchLinkedRowsData(row, columnName) { |
|
||||
if (!row || !row._id) { |
|
||||
return [] |
|
||||
} |
|
||||
const QUERY_URL = `/api/${row.tableId}/${row._id}/enrich` |
|
||||
const response = await api.get(QUERY_URL) |
|
||||
const enrichedRow = await response.json() |
|
||||
return enrichedRow[columnName] |
|
||||
} |
|
||||
|
|
||||
// TODO: wire up |
|
||||
function drillIntoRelationship(row, fieldName) { |
|
||||
if (!row?.[fieldName]?.length) { |
|
||||
return |
|
||||
} |
|
||||
$goto( |
|
||||
`/${$params.application}/data/table/${tableId}/relationship/${row._id}/${fieldName}` |
|
||||
) |
|
||||
} |
|
||||
</script> |
</script> |
||||
|
|
||||
<div class="container"> |
<div |
||||
{#if linkedRows && linkedRows.length && displayColumn} |
class:link={count} |
||||
{#each linkedRows as linkedRow} |
on:click={() => selectRelationship(row, columnName)}> |
||||
{#if linkedRow[displayColumn] != null && linkedRow[displayColumn] !== ''} |
{count} |
||||
<div class="linked-row">{linkedRow[displayColumn]}</div> |
related row(s) |
||||
{/if} |
|
||||
{/each} |
|
||||
{:else}{count} related row(s){/if} |
|
||||
</div> |
</div> |
||||
|
|
||||
<style> |
<style> |
||||
.container { |
.link { |
||||
display: flex; |
text-decoration: underline; |
||||
flex-direction: row; |
|
||||
justify-content: flex-start; |
|
||||
align-items: center; |
|
||||
gap: var(--spacing-xs); |
|
||||
width: 100%; |
|
||||
} |
} |
||||
|
|
||||
/* This styling is opinionated to ensure these always look consistent */ |
.link:hover { |
||||
.linked-row { |
color: var(--grey-6); |
||||
color: white; |
cursor: pointer; |
||||
background-color: #616161; |
|
||||
border-radius: var(--border-radius-xs); |
|
||||
padding: var(--spacing-xs) var(--spacing-s) calc(var(--spacing-xs) + 1px) |
|
||||
var(--spacing-s); |
|
||||
line-height: 1; |
|
||||
font-size: 0.8em; |
|
||||
font-family: var(--font-sans); |
|
||||
font-weight: 500; |
|
||||
} |
} |
||||
</style> |
</style> |
||||
|
|||||
Loading…
Reference in new issue