1
0
Fork 0
mirror of synced 2024-07-13 02:05:54 +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,
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)
}
}
}