Limit results on preview

This commit is contained in:
Adria Navarro 2024-02-08 14:22:22 +01:00
parent a55e75ae18
commit 9c82f84155
1 changed files with 18 additions and 4 deletions

View File

@ -4,13 +4,27 @@
export let schema = {}
export let rows = []
export let maxRowsToDisplay = 5
$: rowsCopy = cloneDeep(rows)
let rowsToDisplay
$: {
rowsToDisplay = [
...cloneDeep(rows).slice(0, maxRowsToDisplay),
// { [Object.keys(schema)[0]]: "1" },
]
if (rows.length - maxRowsToDisplay) {
rowsToDisplay.push({
[Object.keys(schema)[0]]: `...${
rows.length - maxRowsToDisplay
} further items`,
})
}
}
// Cast field in query preview response to number if specified by schema
$: {
for (let i = 0; i < rowsCopy.length; i++) {
let row = rowsCopy[i]
for (let i = 0; i < rowsToDisplay.length; i++) {
let row = rowsToDisplay[i]
for (let fieldName of Object.keys(schema)) {
if (schema[fieldName] === "number" && !isNaN(Number(row[fieldName]))) {
row[fieldName] = Number(row[fieldName])
@ -23,7 +37,7 @@
</script>
<div class="table">
<Table {schema} data={rowsCopy} allowEditing={false} />
<Table {schema} data={rowsToDisplay} allowEditing={false} />
</div>
<style>