Move primary display column option in to column popover

This commit is contained in:
Andrew Kingston 2020-10-14 19:40:01 +01:00
parent 3de238c66a
commit 472dded1fc
3 changed files with 20 additions and 12 deletions

View File

@ -91,7 +91,7 @@ export const getBackendUiStore = () => {
return state return state
}) })
}, },
saveField: ({ originalName, field }) => { saveField: ({ originalName, field, primaryDisplay = false }) => {
store.update(state => { store.update(state => {
// delete the original if renaming // delete the original if renaming
if (originalName) { if (originalName) {
@ -102,8 +102,12 @@ export const getBackendUiStore = () => {
} }
} }
state.draftTable.schema[field.name] = cloneDeep(field) // Optionally set primary display
if (primaryDisplay) {
state.draftTable.primaryDisplay = field.name
}
state.draftTable.schema[field.name] = cloneDeep(field)
store.actions.tables.save(state.draftTable) store.actions.tables.save(state.draftTable)
return state return state
}) })

View File

@ -28,9 +28,15 @@
export let field = { export let field = {
type: "string", type: "string",
constraints: fieldDefinitions.STRING.constraints, constraints: fieldDefinitions.STRING.constraints,
// Initial value for column name in other table for linked records
fieldName: $backendUiStore.selectedTable.name,
} }
let originalName = field.name let originalName = field.name
let primaryDisplay =
$backendUiStore.selectedTable.primaryDisplay == null ||
$backendUiStore.selectedTable.primaryDisplay === field.name
$: tableOptions = $backendUiStore.tables.filter( $: tableOptions = $backendUiStore.tables.filter(
table => table._id !== $backendUiStore.draftTable._id table => table._id !== $backendUiStore.draftTable._id
) )
@ -41,6 +47,7 @@
backendUiStore.actions.tables.saveField({ backendUiStore.actions.tables.saveField({
originalName, originalName,
field, field,
primaryDisplay,
}) })
return state return state
}) })
@ -86,6 +93,13 @@
text="Required" /> text="Required" />
{/if} {/if}
{#if field.type !== 'link'}
<Toggle
bind:checked={primaryDisplay}
thin
text="Use as table display column" />
{/if}
{#if field.type === 'string'} {#if field.type === 'string'}
<Input <Input
thin thin

View File

@ -78,16 +78,6 @@
bind:value={table.name} bind:value={table.name}
on:input={checkValid} on:input={checkValid}
{error} /> {error} />
<Select
label="Primary Display Column"
thin
secondary
bind:value={table.primaryDisplay}>
<option value="">Choose an option</option>
{#each fields as field}
<option value={field}>{field}</option>
{/each}
</Select>
<footer> <footer>
<Button secondary on:click={hideEditor}>Cancel</Button> <Button secondary on:click={hideEditor}>Cancel</Button>
<Button primary disabled={error} on:click={save}>Save</Button> <Button primary disabled={error} on:click={save}>Save</Button>