From 08a48a9ff91ccf10524e768874f953c35f2771c0 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 10 Jun 2024 08:57:24 +0100 Subject: [PATCH] Make new schema validation errors visible to users, and reset schema when saving fails --- .../src/components/grid/stores/datasource.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 09b8be4868..8b8ffdf2cf 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -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) + } } }