From afe04cccafe752248fcaf76bcb9e381302849f24 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 11 May 2023 10:23:07 +0530 Subject: [PATCH] fix: init with schemas even if no db - ux: show reload dialog on settings save --- backend/database/manager.ts | 6 +++++- fyo/index.ts | 2 +- src/pages/Settings/Settings.vue | 23 +++++++++++++++++------ src/pages/SetupWizard/SetupWizard.vue | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/database/manager.ts b/backend/database/manager.ts index 170aa3ea..fe78f3ca 100644 --- a/backend/database/manager.ts +++ b/backend/database/manager.ts @@ -18,7 +18,11 @@ export class DatabaseManager extends DatabaseDemuxBase { } getSchemaMap() { - return this.db?.schemaMap ?? {}; + if (this.#isInitialized) { + return this.db?.schemaMap ?? getSchemas(); + } + + return getSchemas(); } async createNewDatabase(dbPath: string, countryCode: string) { diff --git a/fyo/index.ts b/fyo/index.ts index acec2c01..2194904f 100644 --- a/fyo/index.ts +++ b/fyo/index.ts @@ -167,7 +167,7 @@ export class Fyo { } getField(schemaName: string, fieldname: string) { - return this.fieldMap[schemaName][fieldname]; + return this.fieldMap[schemaName]?.[fieldname]; } async getValue( diff --git a/src/pages/Settings/Settings.vue b/src/pages/Settings/Settings.vue index be22d8b2..3ada16b1 100644 --- a/src/pages/Settings/Settings.vue +++ b/src/pages/Settings/Settings.vue @@ -78,14 +78,14 @@ import FormHeader from 'src/components/FormHeader.vue'; import { handleErrorWithDialog } from 'src/errorHandling'; import { getErrorMessage } from 'src/utils'; import { evaluateHidden } from 'src/utils/doc'; -import { showToast } from 'src/utils/interactive'; +import { shortcutsKey } from 'src/utils/injectionKeys'; +import { showDialog } from 'src/utils/interactive'; import { reloadWindow } from 'src/utils/ipcCalls'; import { docsPathMap } from 'src/utils/misc'; import { docsPathRef } from 'src/utils/refs'; import { UIGroupedFields } from 'src/utils/types'; import { computed, defineComponent, inject } from 'vue'; import CommonFormSection from '../CommonForm/CommonFormSection.vue'; -import { shortcutsKey } from 'src/utils/injectionKeys'; const COMPONENT_NAME = 'Settings'; @@ -165,11 +165,22 @@ export default defineComponent({ } this.update(); - await showToast({ - message: this.t`Changes will be visible on reload`, - actionText: this.t`Reload App`, + showDialog({ + title: this.t`Reload Frappe Books?`, + detail: this.t`Changes made to settings will be visible on reload.`, type: 'info', - action: reloadWindow, + buttons: [ + { + label: this.t`Yes`, + isPrimary: true, + action: reloadWindow, + }, + { + label: this.t`No`, + action() {}, + isEscape: true, + }, + ], }); }, async syncDoc(doc: Doc): Promise { diff --git a/src/pages/SetupWizard/SetupWizard.vue b/src/pages/SetupWizard/SetupWizard.vue index 960f133c..42ed5009 100644 --- a/src/pages/SetupWizard/SetupWizard.vue +++ b/src/pages/SetupWizard/SetupWizard.vue @@ -109,6 +109,9 @@ export default defineComponent({ }, async mounted() { this.docOrNull = getSetupWizardDoc(); + if (!this.fyo.db.isConnected) { + await this.fyo.db.init(); + } if (this.fyo.store.isDevelopment) { // @ts-ignore