[];
- let selectedRelationship: Models.ColumnRelationship = null;
-
let spreadsheetContainer: SpreadsheetContainer;
let currentPage = 1;
@@ -125,7 +120,6 @@
let selectedRowForDelete: Models.Row['$id'] | null = null;
onMount(async () => {
- displayNames = preferences.getDisplayNames();
columnsOrder.set(preferences.getColumnOrder(tableId));
columnsWidth.set(preferences.getColumnWidths(tableId));
@@ -160,7 +154,7 @@
const staticColumns: Column[] = [
{
id: '$id',
- title: 'ID',
+ title: '$id',
width: getColumnWidth('$id', 225),
minimumWidth: 225,
draggable: false,
@@ -172,7 +166,7 @@
},
{
id: '$createdAt',
- title: 'createdAt',
+ title: '$createdAt',
width: getColumnWidth('$createdAt', { min: 200 }),
minimumWidth: 200,
draggable: true,
@@ -183,7 +177,7 @@
},
{
id: '$updatedAt',
- title: 'updatedAt',
+ title: '$updatedAt',
width: getColumnWidth('$updatedAt', { min: 200 }),
minimumWidth: 200,
draggable: true,
@@ -604,6 +598,19 @@
}
}
+ function getDisplayNamesForTable(relatedTable: string | object | null): string[] {
+ if (!relatedTable) return ['$id'];
+
+ let tableId = null;
+ if (typeof relatedTable === 'string') {
+ tableId = relatedTable;
+ } else if (typeof relatedTable === 'object' && '$tableId' in relatedTable) {
+ tableId = relatedTable.$tableId;
+ }
+
+ return preferences.getDisplayNames(tableId) ?? ['$id'];
+ }
+
const saveColumnWidthsToPreferences = debounce(
(column: { columnId: string; newWidth: number; fixedWidth: number }) => {
preferences.saveColumnWidths(organizationId, tableId, {
@@ -636,7 +643,7 @@
$: emptyCellsCount =
$paginatedRows.virtualLength >= emptyCellsLimit
? 0
- : emptyCellsLimit - $paginatedRows.virtualLength;
+ : emptyCellsLimit - $paginatedRows.virtualLength + (!$expandTabs ? 2 : 0);
$: canShowDatetimePopover = true;
@@ -785,32 +792,31 @@
{/snippet}
{:else if isRelationship(rowColumn)}
- {@const args = displayNames?.[rowColumn.relatedTable] ?? [
- '$id'
- ]}
+ {@const args = getDisplayNamesForTable(row[columnId])}
{#if !isRelationshipToMany(rowColumn)}
{#if row[columnId]}
- {@const related = row[columnId]}
- {
- e.preventDefault();
- e.stopPropagation();
- // TODO: open sheet maybes
- goto(
- `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/table/${rowColumn.relatedTable}/row/${related.$id}`
- );
- }}>
- {#each args as arg, i}
- {#if arg !== undefined}
- {#if i} |{/if}
- {related?.[arg]}
- {/if}
- {/each}
-
+ {@const displayValue = args
+ .map((arg) => row[columnId]?.[arg])
+ .filter(Boolean)
+ .join(' | ')}
+
+ {#if displayValue}
+ {
+ $databaseRelatedRowSheetOptions.show = true;
+ $databaseRelatedRowSheetOptions.tableId =
+ columnId;
+ $databaseRelatedRowSheetOptions.rowId =
+ row[columnId]?.['$id'];
+ }}>
+ {displayValue}
+
+ {:else}
+
+ {/if}
{:else}
- n/a
+
{/if}
{:else}
{@const itemsNum = row[columnId]?.length}
@@ -818,12 +824,11 @@
variant="extra-compact"
disabled={!itemsNum}
badge={itemsNum ?? 0}
- on:click={(e) => {
- e.stopPropagation();
- e.preventDefault();
- relationshipData = row[columnId];
- showRelationships = true;
- selectedRelationship = rowColumn;
+ on:click={() => {
+ $databaseRelatedRowSheetOptions.show = true;
+ $databaseRelatedRowSheetOptions.tableId = columnId;
+ $databaseRelatedRowSheetOptions.rowId =
+ row[columnId]?.['$id'];
}}>
Items
@@ -941,7 +946,8 @@
{#if !$isSmallViewport}
{
$randomDataModalState.show = true;
}}>Generate sample data
@@ -976,8 +982,6 @@
{/if}
-
-
({
+ title: 'Update related row',
+ show: false,
+ rowId: null,
+ tableId: null
+});
+
export const showRecordsCreateSheet = writable({
show: false,
row: null
@@ -156,3 +168,12 @@ export const spreadsheetRenderKey = writable('initial');
export const paginatedRowsLoading = writable(false);
export const paginatedRows = createSparsePagedDataStore(SPREADSHEET_PAGE_LIMIT);
+
+export const PROHIBITED_ROW_KEYS = [
+ '$id',
+ '$collection',
+ '$tableId',
+ '$databaseId',
+ '$createdAt',
+ '$updatedAt'
+];