1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

Make new schema validation errors visible to users, and reset schema when saving fails

This commit is contained in:
Andrew Kingston 2024-06-10 08:57:24 +01:00
parent ae863a6e16
commit 08a48a9ff9

View file

@ -94,6 +94,7 @@ export const createActions = context => {
nonPlus, nonPlus,
schemaMutations, schemaMutations,
schema, schema,
notifications,
} = context } = context
// Gets the appropriate API for the configured datasource type // Gets the appropriate API for the configured datasource type
@ -125,16 +126,25 @@ export const createActions = context => {
// Saves the datasource definition // Saves the datasource definition
const saveDefinition = async newDefinition => { const saveDefinition = async newDefinition => {
// Update local state // Update local state
const originalDefinition = get(definition)
definition.set(newDefinition) definition.set(newDefinition)
// Update server // Update server
if (get(config).canSaveSchema) { 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 // Broadcast change so external state can be updated, as this change
// will not be received by the builder websocket because we caused it // will not be received by the builder websocket because we caused it
// ourselves // ourselves
dispatch("updatedatasource", newDefinition) 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)
}
} }
} }