Make sticky column the primary display and fix opening options cells

This commit is contained in:
Andrew Kingston 2023-02-21 11:10:26 +00:00
parent 8c81d5916b
commit 8f5c5cc758
2 changed files with 22 additions and 5 deletions

View File

@ -41,6 +41,14 @@
} }
} }
} }
const toggleOpen = () => {
if (multi) {
open = true
} else {
open = !open
}
}
</script> </script>
<div <div
@ -48,7 +56,7 @@
class:multi class:multi
class:editable class:editable
class:open class:open
on:click={editable ? () => (open = true) : null} on:click={editable ? toggleOpen : null}
> >
<div class="values"> <div class="values">
{#each values as val (val)} {#each values as val (val)}

View File

@ -36,11 +36,12 @@
query, query,
limit, limit,
}) })
$: fields = Object.keys($fetch.schema || {}) $: schema = $fetch.schema
$: primaryDisplay = $fetch.definition?.primaryDisplay
$: fields = getFields(schema, primaryDisplay)
$: fieldCount = fields.length $: fieldCount = fields.length
$: fieldCount, initWidths() $: fieldCount, initWidths()
$: gridStyles = getGridStyles(widths) $: gridStyles = getGridStyles(widths)
$: schema = $fetch.schema
$: rowCount = $fetch.rows?.length || 0 $: rowCount = $fetch.rows?.length || 0
$: selectedRowCount = Object.values(selectedRows).filter(x => !!x).length $: selectedRowCount = Object.values(selectedRows).filter(x => !!x).length
$: rows = getSortedRows($fetch.rows, newRows) $: rows = getSortedRows($fetch.rows, newRows)
@ -59,6 +60,14 @@
}) })
} }
const getFields = (schema, primaryDisplay) => {
let fields = Object.keys(schema || {})
if (primaryDisplay) {
fields = [primaryDisplay, ...fields.filter(x => x !== primaryDisplay)]
}
return fields
}
const initWidths = () => { const initWidths = () => {
widths = fields.map(() => defaultWidth) widths = fields.map(() => defaultWidth)
} }
@ -293,7 +302,7 @@
<div <div
class="cell" class="cell"
class:row-selected={rowSelected} class:row-selected={rowSelected}
class:sticky={fieldIdx === 0} class:sticky={field === primaryDisplay}
class:hovered={rowHovered} class:hovered={rowHovered}
class:selected={selectedCell === cellIdx} class:selected={selectedCell === cellIdx}
class:shadow={horizontallyScrolled} class:shadow={horizontallyScrolled}
@ -328,7 +337,7 @@
{#each fields as field, fieldIdx} {#each fields as field, fieldIdx}
<div <div
class="cell new" class="cell new"
class:sticky={fieldIdx === 0} class:sticky={field === primaryDisplay}
class:shadow={horizontallyScrolled} class:shadow={horizontallyScrolled}
class:hovered={hoveredRow === "new"} class:hovered={hoveredRow === "new"}
on:click={() => addRow(field)} on:click={() => addRow(field)}