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
})
},
saveField: ({ originalName, field }) => {
saveField: ({ originalName, field, primaryDisplay = false }) => {
store.update(state => {
// delete the original if renaming
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)
return state
})

View File

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

View File

@ -78,16 +78,6 @@
bind:value={table.name}
on:input={checkValid}
{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>
<Button secondary on:click={hideEditor}>Cancel</Button>
<Button primary disabled={error} on:click={save}>Save</Button>