From 8c81d5916b32657fe25074e4275b8ffb88ec5857 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 21 Feb 2023 10:46:38 +0000 Subject: [PATCH] Disable editing autocolumns --- .../src/components/app/spreadsheet/DateCell.svelte | 8 +++++--- .../components/app/spreadsheet/OptionsCell.svelte | 12 +++++++----- .../components/app/spreadsheet/Spreadsheet.svelte | 6 ++++-- .../src/components/app/spreadsheet/TextCell.svelte | 5 ++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/client/src/components/app/spreadsheet/DateCell.svelte b/packages/client/src/components/app/spreadsheet/DateCell.svelte index 903738ca35..a57ee4e10a 100644 --- a/packages/client/src/components/app/spreadsheet/DateCell.svelte +++ b/packages/client/src/components/app/spreadsheet/DateCell.svelte @@ -4,8 +4,9 @@ export let value export let schema - export let selected 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 // date, but will make actual ISO dates invalid @@ -17,18 +18,19 @@ : dateOnly ? "MMM D YYYY" : "MMM D YYYY, HH:mm" + $: editable = selected && !readonly
{dayjs(timeOnly ? time : value).format(format)}
- {#if selected} + {#if editable} {/if}
-{#if selected} +{#if editable}
x != null) $: unselectedOptions = options.filter(x => !values.includes(x)) $: { @@ -44,9 +46,9 @@
(open = true) : null} + on:click={editable ? () => (open = true) : null} >
{#each values as val (val)} @@ -62,7 +64,7 @@ {/if} {/each}
- {#if selected} + {#if editable} {/if} {#if open} @@ -101,7 +103,7 @@ overflow: hidden; gap: 4px; } - .container.selected:hover { + .container.editable:hover { cursor: pointer; } .values { diff --git a/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte b/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte index 6275934b3a..d772e88505 100644 --- a/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte +++ b/packages/client/src/components/app/spreadsheet/Spreadsheet.svelte @@ -37,7 +37,8 @@ limit, }) $: fields = Object.keys($fetch.schema || {}) - $: initWidths(fields) + $: fieldCount = fields.length + $: fieldCount, initWidths() $: gridStyles = getGridStyles(widths) $: schema = $fetch.schema $: rowCount = $fetch.rows?.length || 0 @@ -58,7 +59,7 @@ }) } - const initWidths = fields => { + const initWidths = () => { widths = fields.map(() => defaultWidth) } @@ -306,6 +307,7 @@ schema={schema[field]} selected={selectedCell === cellIdx} onChange={val => handleChange(row._id, field, val)} + readonly={schema[field]?.autocolumn} />
{/each} diff --git a/packages/client/src/components/app/spreadsheet/TextCell.svelte b/packages/client/src/components/app/spreadsheet/TextCell.svelte index 47e30aae2d..19531c88aa 100644 --- a/packages/client/src/components/app/spreadsheet/TextCell.svelte +++ b/packages/client/src/components/app/spreadsheet/TextCell.svelte @@ -3,13 +3,16 @@ export let selected = false export let onChange export let type = "text" + export let readonly = false + + $: editable = selected && !readonly const handleChange = e => { onChange(e.target.value) } -{#if selected} +{#if editable} {:else}