Disable editing autocolumns

This commit is contained in:
Andrew Kingston 2023-02-21 10:46:38 +00:00
parent dbf8494c4b
commit 8c81d5916b
4 changed files with 20 additions and 11 deletions

View File

@ -4,8 +4,9 @@
export let value export let value
export let schema export let schema
export let selected
export let onChange export let onChange
export let selected = false
export let readonly = false
// adding the 0- will turn a string like 00:00:00 into a valid ISO // adding the 0- will turn a string like 00:00:00 into a valid ISO
// date, but will make actual ISO dates invalid // date, but will make actual ISO dates invalid
@ -17,18 +18,19 @@
: dateOnly : dateOnly
? "MMM D YYYY" ? "MMM D YYYY"
: "MMM D YYYY, HH:mm" : "MMM D YYYY, HH:mm"
$: editable = selected && !readonly
</script> </script>
<div class="container"> <div class="container">
<div class="value"> <div class="value">
{dayjs(timeOnly ? time : value).format(format)} {dayjs(timeOnly ? time : value).format(format)}
</div> </div>
{#if selected} {#if editable}
<Icon name="Calendar" /> <Icon name="Calendar" />
{/if} {/if}
</div> </div>
{#if selected} {#if editable}
<div class="picker"> <div class="picker">
<CoreDatePicker <CoreDatePicker
{value} {value}

View File

@ -3,14 +3,16 @@
export let value export let value
export let schema export let schema
export let selected = false
export let onChange export let onChange
export let selected = false
export let multi = false export let multi = false
export let readonly = false
const options = schema?.constraints?.inclusion || [] const options = schema?.constraints?.inclusion || []
let open = false let open = false
$: editable = selected && !readonly
$: values = Array.isArray(value) ? value : [value].filter(x => x != null) $: values = Array.isArray(value) ? value : [value].filter(x => x != null)
$: unselectedOptions = options.filter(x => !values.includes(x)) $: unselectedOptions = options.filter(x => !values.includes(x))
$: { $: {
@ -44,9 +46,9 @@
<div <div
class="container" class="container"
class:multi class:multi
class:selected class:editable
class:open class:open
on:click={selected ? () => (open = true) : null} on:click={editable ? () => (open = true) : null}
> >
<div class="values"> <div class="values">
{#each values as val (val)} {#each values as val (val)}
@ -62,7 +64,7 @@
{/if} {/if}
{/each} {/each}
</div> </div>
{#if selected} {#if editable}
<Icon name="ChevronDown" /> <Icon name="ChevronDown" />
{/if} {/if}
{#if open} {#if open}
@ -101,7 +103,7 @@
overflow: hidden; overflow: hidden;
gap: 4px; gap: 4px;
} }
.container.selected:hover { .container.editable:hover {
cursor: pointer; cursor: pointer;
} }
.values { .values {

View File

@ -37,7 +37,8 @@
limit, limit,
}) })
$: fields = Object.keys($fetch.schema || {}) $: fields = Object.keys($fetch.schema || {})
$: initWidths(fields) $: fieldCount = fields.length
$: fieldCount, initWidths()
$: gridStyles = getGridStyles(widths) $: gridStyles = getGridStyles(widths)
$: schema = $fetch.schema $: schema = $fetch.schema
$: rowCount = $fetch.rows?.length || 0 $: rowCount = $fetch.rows?.length || 0
@ -58,7 +59,7 @@
}) })
} }
const initWidths = fields => { const initWidths = () => {
widths = fields.map(() => defaultWidth) widths = fields.map(() => defaultWidth)
} }
@ -306,6 +307,7 @@
schema={schema[field]} schema={schema[field]}
selected={selectedCell === cellIdx} selected={selectedCell === cellIdx}
onChange={val => handleChange(row._id, field, val)} onChange={val => handleChange(row._id, field, val)}
readonly={schema[field]?.autocolumn}
/> />
</div> </div>
{/each} {/each}

View File

@ -3,13 +3,16 @@
export let selected = false export let selected = false
export let onChange export let onChange
export let type = "text" export let type = "text"
export let readonly = false
$: editable = selected && !readonly
const handleChange = e => { const handleChange = e => {
onChange(e.target.value) onChange(e.target.value)
} }
</script> </script>
{#if selected} {#if editable}
<input {type} value={value || ""} on:change={handleChange} /> <input {type} value={value || ""} on:change={handleChange} />
{:else} {:else}
<div class="text-cell"> <div class="text-cell">