Display ... when large array

This commit is contained in:
Adria Navarro 2024-02-07 15:13:48 +01:00
parent a7859f7fd8
commit ec5e533063
2 changed files with 12 additions and 2 deletions

View File

@ -1,7 +1,17 @@
<script>
export let data
export let maxRowsToDisplay = 5
$: string = JSON.stringify(data || {}, null, 2)
let string
$: {
string = JSON.stringify(data || {}, null, 2)
if (Array.isArray(data) && data.length > maxRowsToDisplay) {
string = JSON.stringify(data.slice(0, maxRowsToDisplay) || {}, null, 2)
// Display '...' at the end of the array
string = string.replace(/(}\n])/, "},\n ...\n]")
}
}
</script>
<textarea class="json" disabled value={string} />

View File

@ -41,7 +41,7 @@
</div>
<div class="content">
{#if activeTab === "JSON"}
<JSONPanel data={rows || {}} />
<JSONPanel data={rows?.length === 1 ? rows[0] : rows || {}} />
{:else if activeTab === "Schema"}
<SchemaPanel {onSchemaChange} {schema} />
{:else}