From dcc413bfd05378ef3d9c1e9a779d67c24e57ea4b Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Mon, 23 May 2022 18:59:30 +0800 Subject: [PATCH] fix: the page is still the old data after saving the environment (#43) * fix: the page is still the old data after saving the environment * update code --- package.json | 1 - .../eoui/table/eo-table/eo-table.component.ts | 2 +- .../shared/components/env/env.component.ts | 51 ++++++++++++------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index f050769ce..29432757b 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "eslint-plugin-import": "2.26.0", "eslint-plugin-jsdoc": "39.2.9", "eslint-plugin-prefer-arrow": "1.2.3", - "module-alias": "2.2.2", "npm-run-all": "4.1.5", "ts-node": "10.7.0", "typescript": "~4.6.4", diff --git a/src/workbench/browser/src/app/eoui/table/eo-table/eo-table.component.ts b/src/workbench/browser/src/app/eoui/table/eo-table/eo-table.component.ts index 658a120e4..bb141402f 100644 --- a/src/workbench/browser/src/app/eoui/table/eo-table/eo-table.component.ts +++ b/src/workbench/browser/src/app/eoui/table/eo-table/eo-table.component.ts @@ -48,7 +48,7 @@ export class EoTableComponent implements OnInit, AfterContentInit { return this.modelData; } @Input() set model(value) { - this.modelData = value.flat(Infinity); + this.modelData = (value ?? []).flat(Infinity); const emptyList = this.modelData.filter(isEmptyValue); if (emptyList.length === 0) { // * If has no empty line, then add a new line. diff --git a/src/workbench/browser/src/app/shared/components/env/env.component.ts b/src/workbench/browser/src/app/shared/components/env/env.component.ts index 75ba9378e..351291de7 100644 --- a/src/workbench/browser/src/app/shared/components/env/env.component.ts +++ b/src/workbench/browser/src/app/shared/components/env/env.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Store } from '@ngxs/store'; -import { StorageHandleResult, StorageHandleStatus } from '../../../../../../../platform/browser/IndexedDB'; +import { StorageHandleResult, StorageHandleStatus } from 'eo/platform/browser/IndexedDB'; import { NzMessageService } from 'ng-zorro-antd/message'; import { EoTableComponent } from '../../../eoui/table/eo-table/eo-table.component'; import { Change } from '../../store/env.state'; @@ -54,21 +54,28 @@ export class EnvComponent implements OnInit, OnDestroy { getAllEnv(uuid?: number) { const projectID = 1; - this.storage.run('environmentLoadAllByProjectID', [projectID], (result: StorageHandleResult) => { - if (result.status !== StorageHandleStatus.success) { - this.envList = []; - this.handleAddEnv(projectID); - return; - } - this.envList = result.data; - this.handleSwitchEnv(uuid ?? result.data[0].uuid); + return new Promise((resolve) => { + this.storage.run('environmentLoadAllByProjectID', [projectID], async (result: StorageHandleResult) => { + if (result.status !== StorageHandleStatus.success) { + this.envList = []; + await this.handleAddEnv(projectID); + resolve(true); + return; + } + this.envList = result.data; + await this.handleSwitchEnv(uuid ?? result.data[0].uuid); + resolve(true); + }); }); } handleDeleteEnv(uuid: string) { // * delete env in menu on left sidebar - this.storage.run('environmentRemove', [uuid], (result: StorageHandleResult) => { - this.getAllEnv(); + this.storage.run('environmentRemove', [uuid], async (result: StorageHandleResult) => { + await this.getAllEnv(); + if (this.envUuid === Number(uuid)) { + this.envUuid = this.activeUuid; + } }); } handleDeleteParams(index) { @@ -78,11 +85,14 @@ export class EnvComponent implements OnInit, OnDestroy { } handleSwitchEnv(uuid) { // * switch env in menu on left sidebar - this.storage.run('environmentLoad', [uuid], (result: StorageHandleResult) => { - if (result.status === StorageHandleStatus.success) { - this.envInfo = result.data; - } - this.activeUuid = uuid; + return new Promise((resolve) => { + this.storage.run('environmentLoad', [uuid], (result: StorageHandleResult) => { + if (result.status === StorageHandleStatus.success) { + this.envInfo = result.data; + } + this.activeUuid = uuid; + resolve(true); + }); }); } @@ -109,10 +119,13 @@ export class EnvComponent implements OnInit, OnDestroy { this.storage.run( 'environmentUpdate', [{ ...other, name, parameters: data }, uuid], - (result: StorageHandleResult) => { + async (result: StorageHandleResult) => { if (result.status === StorageHandleStatus.success) { this.message.success('编辑成功'); - this.getAllEnv(this.activeUuid); + await this.getAllEnv(this.activeUuid); + if (this.envUuid === Number(uuid)) { + this.envUuid = Number(uuid); + } } else { this.message.success('编辑失败'); } @@ -143,7 +156,7 @@ export class EnvComponent implements OnInit, OnDestroy { this.handleSwitchEnv(this.envUuid); } - handleEnvSelectStatus(event) { + handleEnvSelectStatus(event: boolean) { if (event) { this.activeUuid = this.envUuid; this.handleSwitchEnv(this.activeUuid);