Skip to content

Commit

Permalink
fix: the page is still the old data after saving the environment (#43)
Browse files Browse the repository at this point in the history
* fix: the page is still the old data after saving the environment

* update code
  • Loading branch information
buqiyuan authored May 23, 2022
1 parent be21e79 commit dcc413b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
});
});
}

Expand All @@ -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('编辑失败');
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dcc413b

Please sign in to comment.