Fix issue creating columns due to 'draft' concept when mutating table schemas
This commit is contained in:
parent
3e3808186c
commit
20bd1815ac
|
@ -102,7 +102,7 @@
|
||||||
// in the case of internal tables the sourceId will just be undefined
|
// in the case of internal tables the sourceId will just be undefined
|
||||||
$: tableOptions = $tables.list.filter(
|
$: tableOptions = $tables.list.filter(
|
||||||
opt =>
|
opt =>
|
||||||
opt._id !== $tables.draft._id &&
|
opt._id !== $tables.selected._id &&
|
||||||
opt.type === table.type &&
|
opt.type === table.type &&
|
||||||
table.sourceId === opt.sourceId
|
table.sourceId === opt.sourceId
|
||||||
)
|
)
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
|
|
||||||
async function saveColumn() {
|
async function saveColumn() {
|
||||||
if (field.type === AUTO_TYPE) {
|
if (field.type === AUTO_TYPE) {
|
||||||
field = buildAutoColumn($tables.draft.name, field.name, field.subtype)
|
field = buildAutoColumn($tables.selected.name, field.name, field.subtype)
|
||||||
}
|
}
|
||||||
if (field.type !== LINK_TYPE) {
|
if (field.type !== LINK_TYPE) {
|
||||||
delete field.fieldName
|
delete field.fieldName
|
||||||
|
@ -310,7 +310,7 @@
|
||||||
newError.name = `${PROHIBITED_COLUMN_NAMES.join(
|
newError.name = `${PROHIBITED_COLUMN_NAMES.join(
|
||||||
", "
|
", "
|
||||||
)} are not allowed as column names`
|
)} are not allowed as column names`
|
||||||
} else if (inUse($tables.draft, fieldInfo.name, originalName)) {
|
} else if (inUse($tables.selected, fieldInfo.name, originalName)) {
|
||||||
newError.name = `Column name already in use.`
|
newError.name = `Column name already in use.`
|
||||||
}
|
}
|
||||||
if (fieldInfo.fieldName && fieldInfo.tableId) {
|
if (fieldInfo.fieldName && fieldInfo.tableId) {
|
||||||
|
|
|
@ -84,13 +84,13 @@ export function createTablesStore() {
|
||||||
primaryDisplay = false,
|
primaryDisplay = false,
|
||||||
indexes,
|
indexes,
|
||||||
}) => {
|
}) => {
|
||||||
let promise
|
let draft = cloneDeep(get(derivedStore).selected)
|
||||||
store.update(state => {
|
|
||||||
// delete the original if renaming
|
// delete the original if renaming
|
||||||
// need to handle if the column had no name, empty string
|
// need to handle if the column had no name, empty string
|
||||||
if (originalName != null && originalName !== field.name) {
|
if (originalName != null && originalName !== field.name) {
|
||||||
delete state.draft.schema[originalName]
|
delete draft.schema[originalName]
|
||||||
state.draft._rename = {
|
draft._rename = {
|
||||||
old: originalName,
|
old: originalName,
|
||||||
updated: field.name,
|
updated: field.name,
|
||||||
}
|
}
|
||||||
|
@ -98,41 +98,29 @@ export function createTablesStore() {
|
||||||
|
|
||||||
// Optionally set display column
|
// Optionally set display column
|
||||||
if (primaryDisplay) {
|
if (primaryDisplay) {
|
||||||
state.draft.primaryDisplay = field.name
|
draft.primaryDisplay = field.name
|
||||||
} else if (state.draft.primaryDisplay === originalName) {
|
} else if (draft.primaryDisplay === originalName) {
|
||||||
const fields = Object.keys(state.draft.schema)
|
const fields = Object.keys(draft.schema)
|
||||||
// pick another display column randomly if unselecting
|
// pick another display column randomly if unselecting
|
||||||
state.draft.primaryDisplay = fields.filter(
|
draft.primaryDisplay = fields.filter(
|
||||||
name => name !== originalName || name !== field
|
name => name !== originalName || name !== field
|
||||||
)[0]
|
)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexes) {
|
if (indexes) {
|
||||||
state.draft.indexes = indexes
|
draft.indexes = indexes
|
||||||
}
|
}
|
||||||
|
draft.schema = {
|
||||||
state.draft.schema = {
|
...draft.schema,
|
||||||
...state.draft.schema,
|
|
||||||
[field.name]: cloneDeep(field),
|
[field.name]: cloneDeep(field),
|
||||||
}
|
}
|
||||||
promise = save(state.draft)
|
|
||||||
return state
|
await save(draft)
|
||||||
})
|
|
||||||
if (promise) {
|
|
||||||
await promise
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteField = async field => {
|
const deleteField = async field => {
|
||||||
let promise
|
let draft = cloneDeep(get(derivedStore).selected)
|
||||||
store.update(state => {
|
delete draft.schema[field.name]
|
||||||
delete state.draft.schema[field.name]
|
await save(draft)
|
||||||
promise = save(state.draft)
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
if (promise) {
|
|
||||||
await promise
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue