mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-20 00:03:21 +00:00
fix: preserve table column order for integer-like column names
This commit is contained in:
@@ -378,7 +378,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleArrayOfObjectsHeaders(json: any) {
|
||||
function handleArrayOfObjectsHeaders(json: any): {
|
||||
rows: any[]
|
||||
explicitHeaders?: string[]
|
||||
} {
|
||||
// handle possible a first row of headers
|
||||
if (
|
||||
Array.isArray(json) &&
|
||||
@@ -401,10 +404,10 @@
|
||||
rows[i - 1] = obj
|
||||
}
|
||||
|
||||
return rows
|
||||
return { rows, explicitHeaders: headers }
|
||||
}
|
||||
|
||||
return json
|
||||
return { rows: json }
|
||||
}
|
||||
|
||||
type InputObject = { [key: string]: number[] }
|
||||
@@ -635,11 +638,13 @@
|
||||
typeof result === 'object' && 'table-row-object' in result
|
||||
? result['table-row-object']
|
||||
: result}
|
||||
{@const { rows, explicitHeaders } = handleArrayOfObjectsHeaders(data)}
|
||||
<AutoDataTable
|
||||
class={fixTableSizingToParent
|
||||
? 'absolute inset-0 [&>div]:h-full [&>div]:min-h-[10rem]'
|
||||
: ''}
|
||||
objects={handleArrayOfObjectsHeaders(data)}
|
||||
objects={rows}
|
||||
{explicitHeaders}
|
||||
/>
|
||||
{:else if !forceJson && resultKind === 'html'}
|
||||
<div class="h-full">
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
import DownloadCsv from './DownloadCsv.svelte'
|
||||
interface Props {
|
||||
objects?: Array<Record<string, any>>
|
||||
explicitHeaders?: string[]
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { objects = [], class: className }: Props = $props()
|
||||
let { objects = [], explicitHeaders, class: className }: Props = $props()
|
||||
|
||||
let currentPage = $state(1)
|
||||
let perPage = $state(25)
|
||||
@@ -36,8 +37,11 @@
|
||||
}[] = $state([])
|
||||
let headers: string[] = $state([])
|
||||
|
||||
function recomputeObjectsAndHeaders(objects: Array<Record<string, any>>) {
|
||||
;[headers, structuredObjects] = computeStructuredObjectsAndHeaders(objects)
|
||||
function recomputeObjectsAndHeaders(
|
||||
objects: Array<Record<string, any>>,
|
||||
explicitHeaders?: string[]
|
||||
) {
|
||||
;[headers, structuredObjects] = computeStructuredObjectsAndHeaders(objects, explicitHeaders)
|
||||
}
|
||||
|
||||
function adjustCurrentPage() {
|
||||
@@ -160,7 +164,7 @@
|
||||
}
|
||||
}
|
||||
run(() => {
|
||||
recomputeObjectsAndHeaders(objects)
|
||||
recomputeObjectsAndHeaders(objects, explicitHeaders)
|
||||
})
|
||||
run(() => {
|
||||
perPage && adjustCurrentPage()
|
||||
|
||||
@@ -8,7 +8,10 @@ export function isEmail(value: string) {
|
||||
return value?.includes('@')
|
||||
}
|
||||
|
||||
export function computeStructuredObjectsAndHeaders(objects: Array<Record<string, any>>): [
|
||||
export function computeStructuredObjectsAndHeaders(
|
||||
objects: Array<Record<string, any>>,
|
||||
explicitHeaders?: string[]
|
||||
): [
|
||||
string[],
|
||||
{
|
||||
_id: number
|
||||
@@ -18,7 +21,7 @@ export function computeStructuredObjectsAndHeaders(objects: Array<Record<string,
|
||||
if (Array.isArray(objects)) {
|
||||
let nextId = 1
|
||||
|
||||
let hds: string[] = []
|
||||
let hds: string[] = explicitHeaders ? [...explicitHeaders] : []
|
||||
let objs = objects.map((obj) => {
|
||||
let rowData = obj && typeof obj == 'object' ? obj : {}
|
||||
if (Array.isArray(rowData)) {
|
||||
|
||||
Reference in New Issue
Block a user