Make new schema validation errors visible to users, and reset schema when saving fails
This commit is contained in:
parent
ae863a6e16
commit
08a48a9ff9
|
@ -94,6 +94,7 @@ export const createActions = context => {
|
|||
nonPlus,
|
||||
schemaMutations,
|
||||
schema,
|
||||
notifications,
|
||||
} = context
|
||||
|
||||
// Gets the appropriate API for the configured datasource type
|
||||
|
@ -125,16 +126,25 @@ export const createActions = context => {
|
|||
// Saves the datasource definition
|
||||
const saveDefinition = async newDefinition => {
|
||||
// Update local state
|
||||
const originalDefinition = get(definition)
|
||||
definition.set(newDefinition)
|
||||
|
||||
// Update server
|
||||
if (get(config).canSaveSchema) {
|
||||
await getAPI()?.actions.saveDefinition(newDefinition)
|
||||
try {
|
||||
await getAPI()?.actions.saveDefinition(newDefinition)
|
||||
|
||||
// Broadcast change so external state can be updated, as this change
|
||||
// will not be received by the builder websocket because we caused it
|
||||
// ourselves
|
||||
dispatch("updatedatasource", newDefinition)
|
||||
// Broadcast change so external state can be updated, as this change
|
||||
// will not be received by the builder websocket because we caused it
|
||||
// ourselves
|
||||
dispatch("updatedatasource", newDefinition)
|
||||
} catch (error) {
|
||||
const msg = error?.message || error || "Unknown error"
|
||||
get(notifications).error(`Error saving schema: ${msg}`)
|
||||
|
||||
// Reset the definition if saving failed
|
||||
definition.set(originalDefinition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue