Skip to content

Commit

Permalink
Merge pull request #10745 from Budibase/revert-10234-budi-1855-handli…
Browse files Browse the repository at this point in the history
…ng-deletion-of-display-columns-use

Revert "Assign a new display column when deleting field"
  • Loading branch information
deanhannigan authored May 31, 2023
2 parents b42fe0a + b2e7b14 commit 2498e62
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 628 deletions.
41 changes: 9 additions & 32 deletions packages/builder/src/stores/backend/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,6 @@ export function createTablesStore() {
replaceTable(table._id, null)
}

const assignDisplayColumn = ({
primaryDisplay,
draft,
field,
originalName,
}) => {
if (primaryDisplay) {
draft.primaryDisplay = field.name
} else if (draft.primaryDisplay === originalName) {
const fields = Object.keys(draft.schema)
// pick another display column randomly if unselecting
draft.primaryDisplay = fields.filter(
name =>
(name !== originalName || name !== field.name) &&
!["attachment", "json", "link"].includes(draft.schema[name].type)
)[0]
}
}

const saveField = async ({
originalName,
field,
Expand All @@ -117,13 +98,15 @@ export function createTablesStore() {
}

// Optionally set display column
assignDisplayColumn({
primaryDisplay,
draft,
field,
originalName,
})

if (primaryDisplay) {
draft.primaryDisplay = field.name
} else if (draft.primaryDisplay === originalName) {
const fields = Object.keys(draft.schema)
// pick another display column randomly if unselecting
draft.primaryDisplay = fields.filter(
name => name !== originalName || name !== field
)[0]
}
if (indexes) {
draft.indexes = indexes
}
Expand All @@ -137,12 +120,6 @@ export function createTablesStore() {

const deleteField = async field => {
let draft = cloneDeep(get(derivedStore).selected)
assignDisplayColumn({
primaryDisplay: false,
draft,
field,
originalName: draft.primaryDisplay === field.name ? field.name : false,
})
delete draft.schema[field.name]
await save(draft)
}
Expand Down
Loading

0 comments on commit 2498e62

Please sign in to comment.