2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +00:00

fix(ux): remove file selection on create

This commit is contained in:
18alantom 2023-07-11 13:43:32 +05:30
parent 952241b0bd
commit 23916a3b1d
6 changed files with 39 additions and 32 deletions

View File

@ -117,6 +117,13 @@ const ipc = {
)) as ConfigFilesWithModified[]; )) as ConfigFilesWithModified[];
}, },
async getDbDefaultPath(companyName: string) {
return (await ipcRenderer.invoke(
IPC_ACTIONS.GET_DB_DEFAULT_PATH,
companyName
)) as string;
},
async getEnv() { async getEnv() {
return (await ipcRenderer.invoke(IPC_ACTIONS.GET_ENV)) as { return (await ipcRenderer.invoke(IPC_ACTIONS.GET_ENV)) as {
isDevelopment: boolean; isDevelopment: boolean;

View File

@ -8,7 +8,7 @@ import {
} from 'electron'; } from 'electron';
import { autoUpdater } from 'electron-updater'; import { autoUpdater } from 'electron-updater';
import { constants } from 'fs'; import { constants } from 'fs';
import fs from 'fs/promises'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import { SelectFileOptions, SelectFileReturn } from 'utils/types'; import { SelectFileOptions, SelectFileReturn } from 'utils/types';
import databaseManager from '../backend/database/manager'; import databaseManager from '../backend/database/manager';
@ -38,6 +38,22 @@ export default function registerIpcMainActionListeners(main: Main) {
return true; return true;
}); });
ipcMain.handle(
IPC_ACTIONS.GET_DB_DEFAULT_PATH,
async (_, companyName: string) => {
let root = app.getPath('documents');
if (main.isDevelopment) {
root = 'dbs';
}
const dbsPath = path.join(root, 'Frappe Books');
const backupPath = path.join(dbsPath, 'backups');
await fs.ensureDir(backupPath);
return path.join(dbsPath, `${companyName}.books.db`);
}
);
ipcMain.handle( ipcMain.handle(
IPC_ACTIONS.GET_OPEN_FILEPATH, IPC_ACTIONS.GET_OPEN_FILEPATH,
async (_, options: OpenDialogOptions) => { async (_, options: OpenDialogOptions) => {

View File

@ -19,6 +19,7 @@
<DatabaseSelector <DatabaseSelector
v-if="activeScreen === 'DatabaseSelector'" v-if="activeScreen === 'DatabaseSelector'"
ref="databaseSelector" ref="databaseSelector"
@new-database="newDatabase"
@file-selected="fileSelected" @file-selected="fileSelected"
/> />
<SetupWizard <SetupWizard
@ -136,7 +137,7 @@ export default defineComponent({
return; return;
} }
await this.fileSelected(lastSelectedFilePath, false); await this.fileSelected(lastSelectedFilePath);
}, },
async setSearcher(): Promise<void> { async setSearcher(): Promise<void> {
this.searcher = new Search(fyo); this.searcher = new Search(fyo);
@ -156,13 +157,11 @@ export default defineComponent({
await this.setSearcher(); await this.setSearcher();
updateConfigFiles(fyo); updateConfigFiles(fyo);
}, },
async fileSelected(filePath: string, isNew?: boolean): Promise<void> { newDatabase() {
fyo.config.set('lastSelectedFilePath', filePath);
if (isNew) {
this.activeScreen = Screen.SetupWizard; this.activeScreen = Screen.SetupWizard;
return; },
} async fileSelected(filePath: string): Promise<void> {
fyo.config.set('lastSelectedFilePath', filePath);
if (filePath !== ':memory:' && !(await ipc.checkDbAccess(filePath))) { if (filePath !== ':memory:' && !(await ipc.checkDbAccess(filePath))) {
await showDialog({ await showDialog({
title: this.t`Cannot open file`, title: this.t`Cannot open file`,
@ -183,12 +182,10 @@ export default defineComponent({
} }
}, },
async setupComplete(setupWizardOptions: SetupWizardOptions): Promise<void> { async setupComplete(setupWizardOptions: SetupWizardOptions): Promise<void> {
const filePath = fyo.config.get('lastSelectedFilePath'); const companyName = setupWizardOptions.companyName;
if (typeof filePath !== 'string') { const filePath = await ipc.getDbDefaultPath(companyName);
return;
}
await setupInstance(filePath, setupWizardOptions, fyo); await setupInstance(filePath, setupWizardOptions, fyo);
fyo.config.set('lastSelectedFilePath', filePath);
await this.setDesk(filePath); await this.setDesk(filePath);
}, },
async showSetupWizardOrDesk(filePath: string): Promise<void> { async showSetupWizardOrDesk(filePath: string): Promise<void> {

View File

@ -260,7 +260,7 @@ export default defineComponent({
Modal, Modal,
Button, Button,
}, },
emits: ['file-selected'], emits: ['file-selected', 'new-database'],
data() { data() {
return { return {
openModal: false, openModal: false,
@ -363,17 +363,12 @@ export default defineComponent({
(a, b) => Date.parse(b.modified) - Date.parse(a.modified) (a, b) => Date.parse(b.modified) - Date.parse(a.modified)
); );
}, },
async newDatabase() { newDatabase() {
if (this.creatingDemo) { if (this.creatingDemo) {
return; return;
} }
const { filePath, canceled } = await getSavePath('books', 'db'); this.$emit('new-database');
if (canceled || !filePath) {
return;
}
this.emitFileSelected(filePath, true);
}, },
async existingDatabase() { async existingDatabase() {
if (this.creatingDemo) { if (this.creatingDemo) {
@ -390,17 +385,12 @@ export default defineComponent({
this.emitFileSelected(file.dbPath); this.emitFileSelected(file.dbPath);
}, },
emitFileSelected(filePath: string, isNew?: boolean) { emitFileSelected(filePath: string) {
if (!filePath) { if (!filePath) {
return; return;
} }
if (isNew) { this.$emit('file-selected', filePath);
this.$emit('file-selected', filePath, isNew);
return;
}
this.$emit('file-selected', filePath, !!isNew);
}, },
}, },
}); });

View File

@ -44,10 +44,6 @@ const appSourcePath = path.join(root, 'dist_electron', 'build', 'main.js');
}); });
test('fill setup form', async (t) => { test('fill setup form', async (t) => {
await electronApp.evaluate(({ dialog }, filePath) => {
dialog.showSaveDialog = () =>
Promise.resolve({ canceled: false, filePath });
}, ':memory:');
await window.getByTestId('create-new-file').click(); await window.getByTestId('create-new-file').click();
await window.getByTestId('submit-button').waitFor(); await window.getByTestId('submit-button').waitFor();

View File

@ -25,6 +25,7 @@ export enum IPC_ACTIONS {
GET_DB_LIST = 'get-db-list', GET_DB_LIST = 'get-db-list',
GET_TEMPLATES = 'get-templates', GET_TEMPLATES = 'get-templates',
DELETE_FILE = 'delete-file', DELETE_FILE = 'delete-file',
GET_DB_DEFAULT_PATH = 'get-db-default-path',
// Database messages // Database messages
DB_CREATE = 'db-create', DB_CREATE = 'db-create',
DB_CONNECT = 'db-connect', DB_CONNECT = 'db-connect',