2
0
mirror of https://github.com/frappe/books.git synced 2024-09-07 21:29:03 +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[];
},
async getDbDefaultPath(companyName: string) {
return (await ipcRenderer.invoke(
IPC_ACTIONS.GET_DB_DEFAULT_PATH,
companyName
)) as string;
},
async getEnv() {
return (await ipcRenderer.invoke(IPC_ACTIONS.GET_ENV)) as {
isDevelopment: boolean;

View File

@ -8,7 +8,7 @@ import {
} from 'electron';
import { autoUpdater } from 'electron-updater';
import { constants } from 'fs';
import fs from 'fs/promises';
import fs from 'fs-extra';
import path from 'path';
import { SelectFileOptions, SelectFileReturn } from 'utils/types';
import databaseManager from '../backend/database/manager';
@ -38,6 +38,22 @@ export default function registerIpcMainActionListeners(main: Main) {
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(
IPC_ACTIONS.GET_OPEN_FILEPATH,
async (_, options: OpenDialogOptions) => {

View File

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

View File

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

View File

@ -44,10 +44,6 @@ const appSourcePath = path.join(root, 'dist_electron', 'build', 'main.js');
});
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('submit-button').waitFor();

View File

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