diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index 0f57d56f3e..16ee67cc5b 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -27,6 +27,8 @@ context("Create a Table", () => { cy.get(".actions input") .first() .type("updated") + // Unset table display column + cy.contains("display column").click() cy.contains("Save Column").click() cy.contains("nameupdated").should("have.text", "nameupdated") }) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index cf47051d38..e61f1b38e9 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -87,6 +87,8 @@ Cypress.Commands.add("addColumn", (tableName, columnName, type) => { cy.get("input") .first() .type(columnName) + // Unset table display column + cy.contains("display column").click() cy.get("select").select(type) cy.contains("Save").click() }) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index d89796f9cc..f48b561ef0 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -91,10 +91,11 @@ export const getBackendUiStore = () => { return state }) }, - saveField: ({ originalName, field }) => { + saveField: ({ originalName, field, primaryDisplay = false }) => { store.update(state => { // delete the original if renaming - if (originalName) { + // need to handle if the column had no name, empty string + if (originalName || originalName === "") { delete state.draftTable.schema[originalName] state.draftTable._rename = { old: originalName, @@ -102,8 +103,12 @@ export const getBackendUiStore = () => { } } - state.draftTable.schema[field.name] = cloneDeep(field) + // Optionally set display column + if (primaryDisplay) { + state.draftTable.primaryDisplay = field.name + } + state.draftTable.schema[field.name] = cloneDeep(field) store.actions.tables.save(state.draftTable) return state }) diff --git a/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte index e4db32d900..2857b651c3 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte @@ -33,7 +33,7 @@ function deleteColumn() { if (field.name === $backendUiStore.selectedTable.primaryDisplay) { - notifier.danger("You cannot delete the primary display column") + notifier.danger("You cannot delete the display column") } else { backendUiStore.actions.tables.deleteField(field) notifier.success("Column deleted") @@ -43,7 +43,11 @@ function sort(direction, column) { backendUiStore.update(state => { - state.sort = { direction, column } + if (direction !== "none") { + state.sort = { direction, column } + } else { + state.sort = undefined + } return state }) hideEditor() @@ -70,6 +74,12 @@ Delete + {#if sortDirection === 'desc' || sortDirection === 'asc'} +
  • sort('none', field.name)}> + + Remove sort +
  • + {/if} {#if sortDirection === 'desc' || sortColumn !== field.name}
  • sort('asc', field.name)}> diff --git a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte index 14755ce6fe..3748e4ed98 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte @@ -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'} + + {/if} + {#if field.type === 'string'} -