From d05e6432b39b3c77e5a3f463b1fd243807593881 Mon Sep 17 00:00:00 2001
From: sunzhouyang <sunzhouyang@eolink.com>
Date: Mon, 13 Mar 2023 19:45:24 +0800
Subject: [PATCH 1/5] fix: uninstall default and import

---
 .../params-import/params-import.component.ts          | 11 ++++++++++-
 .../api/http/test/body/api-test-body.component.ts     |  1 +
 .../browser/src/app/shared/constants/extension.ts     |  1 +
 .../shared/services/extensions/extension.service.ts   | 10 ++++++++--
 .../services/extensions/webExtension.service.ts       |  9 +++++++++
 5 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 src/workbench/browser/src/app/shared/constants/extension.ts

diff --git a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
index 21c9d1f84..f7acdd4ed 100644
--- a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
+++ b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
@@ -181,7 +181,15 @@ export class ParamsImportComponent implements OnInit {
     const combineFunc = {
       overwrite: data => data,
       append: (data, base) => base.concat(data),
-      mixin: (data, base) => obj2array(merge(array2obj(base), array2obj(data)))
+      mixin: (data, base) => {
+        const handleData = {};
+        for (let item of data) {
+          handleData[item.name] = {
+            'paramAttr.example': item.paramAttr.example
+          };
+        }
+        return obj2array(merge(array2obj(base), array2obj(handleData)));
+      }
     };
 
     const endParse = (data, type) => {
@@ -202,6 +210,7 @@ export class ParamsImportComponent implements OnInit {
     const result = combineFunc[type](json2Table(data), resultData);
     // * 后处理
     const finalData = endParse([...result, ...emptyRow], this.contentType);
+    console.log(finalData);
     this.baseDataChange.emit(finalData);
     this.handleCancel();
   }
diff --git a/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts b/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
index 6fa10d2d9..e41ae9381 100644
--- a/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
+++ b/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
@@ -152,6 +152,7 @@ export class ApiTestBodyComponent implements OnInit, OnChanges, OnDestroy {
     this.modelChange.emit(this.model);
   }
   handleParamsImport(data) {
+    console.log(data, '-------------');
     this.model = data;
     this.modelChange.emit(data);
   }
diff --git a/src/workbench/browser/src/app/shared/constants/extension.ts b/src/workbench/browser/src/app/shared/constants/extension.ts
new file mode 100644
index 000000000..bcb0c5e11
--- /dev/null
+++ b/src/workbench/browser/src/app/shared/constants/extension.ts
@@ -0,0 +1 @@
+export const defaultExtensions = ['postcat-export-openapi', 'postcat-import-openapi'];
diff --git a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
index fcdbf72dc..bb4b9ec71 100644
--- a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
+++ b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
@@ -2,16 +2,19 @@ import { HttpClient, HttpParams } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { ElectronService } from 'eo/workbench/browser/src/app/core/services';
 import { LanguageService } from 'eo/workbench/browser/src/app/core/services/language/language.service';
+import { defaultExtensions } from 'eo/workbench/browser/src/app/shared/constants/extension';
 import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
 import { FeatureInfo, ExtensionInfo, SidebarView } from 'eo/workbench/browser/src/app/shared/models/extension-manager';
 import { MessageService } from 'eo/workbench/browser/src/app/shared/services/message';
+import storageUtils from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
 import { APP_CONFIG } from 'eo/workbench/browser/src/environments/environment';
 import { lastValueFrom, Subscription } from 'rxjs';
 
 import { ExtensionCommonService } from './extension-store.service';
 import { WebExtensionService } from './webExtension.service';
 
-const defaultExtensions = ['postcat-export-openapi', 'postcat-import-openapi'];
+const uninstallDefaultExtensions = storageUtils.get('uninstall_default_ext_list');
+
 @Injectable({
   providedIn: 'root'
 })
@@ -44,7 +47,10 @@ export class ExtensionService {
     //* Web Installl
     const installedName = [];
     //Get extensions
-    [...this.webExtensionService.installedList, ...defaultExtensions.map(name => ({ name }))].forEach(val => {
+    [
+      ...this.webExtensionService.installedList,
+      ...defaultExtensions.filter(item => !(uninstallDefaultExtensions || []).includes(item)).map(name => ({ name }))
+    ].forEach(val => {
       if (this.installedList.some(m => m.name === val.name)) return;
       installedName.push(val.name);
     });
diff --git a/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts b/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
index 81d63db21..929d0e693 100644
--- a/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
+++ b/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
@@ -1,5 +1,6 @@
 import { Injectable } from '@angular/core';
 import { TranslateService } from 'eo/platform/common/i18n';
+import { defaultExtensions } from 'eo/workbench/browser/src/app/shared/constants/extension';
 import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
 import { eoDeepCopy, JSONParse } from 'eo/workbench/browser/src/app/utils/index.utils';
 import StorageUtil from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
@@ -17,6 +18,7 @@ type ExtensionItem = {
 };
 
 const extKey = 'ext_installed_list';
+const uninstallDebugKey = 'uninstall_default_ext_list';
 
 //* Web Extension manage service
 //! Can't import by other component,please use ExtensionService
@@ -138,6 +140,13 @@ export class WebExtensionService {
   unInstallExtension(extName: string): boolean {
     this.installedList = this.installedList.filter(n => n.name !== extName);
     StorageUtil.set(extKey, this.installedList);
+    if (!StorageUtil.get(uninstallDebugKey)) {
+      StorageUtil.set(uninstallDebugKey, []);
+    }
+    const uninstallDefaultExtArr = StorageUtil.get(uninstallDebugKey);
+    const uninstallDefaultExt = defaultExtensions.find(item => item === extName);
+    uninstallDefaultExtArr.push(uninstallDefaultExt);
+    StorageUtil.set(uninstallDebugKey, uninstallDefaultExtArr);
     return true;
   }
 

From 72d3a1556f1618f0ab98e156b33e95c1aae3502b Mon Sep 17 00:00:00 2001
From: sunzhouyang <sunzhouyang@eolink.com>
Date: Mon, 13 Mar 2023 19:53:18 +0800
Subject: [PATCH 2/5] style: remove console

---
 .../modules/api-shared/params-import/params-import.component.ts  | 1 -
 .../project/api/http/test/body/api-test-body.component.ts        | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
index f7acdd4ed..e29f33b6e 100644
--- a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
+++ b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
@@ -210,7 +210,6 @@ export class ParamsImportComponent implements OnInit {
     const result = combineFunc[type](json2Table(data), resultData);
     // * 后处理
     const finalData = endParse([...result, ...emptyRow], this.contentType);
-    console.log(finalData);
     this.baseDataChange.emit(finalData);
     this.handleCancel();
   }
diff --git a/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts b/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
index e41ae9381..6fa10d2d9 100644
--- a/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
+++ b/src/workbench/browser/src/app/pages/workspace/project/api/http/test/body/api-test-body.component.ts
@@ -152,7 +152,6 @@ export class ApiTestBodyComponent implements OnInit, OnChanges, OnDestroy {
     this.modelChange.emit(this.model);
   }
   handleParamsImport(data) {
-    console.log(data, '-------------');
     this.model = data;
     this.modelChange.emit(data);
   }

From e70e68a6faf3c8f2855682b78adf32cbf26f814d Mon Sep 17 00:00:00 2001
From: sunzhouyang <sunzhouyang@eolink.com>
Date: Mon, 13 Mar 2023 20:15:59 +0800
Subject: [PATCH 3/5] fix: Conflict resolution

---
 .../src/app/shared/services/extensions/extension.service.ts     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
index f8586f578..2e9de22a0 100644
--- a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
+++ b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
@@ -13,7 +13,7 @@ import { lastValueFrom, Subscription } from 'rxjs';
 import { ExtensionCommonService } from './extension-store.service';
 import { WebExtensionService } from './webExtension.service';
 
-const uninstallDefaultExtensions = storageUtil.get('uninstall_default_ext_list');
+const uninstallDefaultExtensions = StorageUtil.get('uninstall_default_ext_list');
 
 @Injectable({
   providedIn: 'root'

From ce9afa4a6b9153bfb2ae17ddaad0541092cfda2e Mon Sep 17 00:00:00 2001
From: sunzhouyang <sunzhouyang@eolink.com>
Date: Tue, 14 Mar 2023 14:21:19 +0800
Subject: [PATCH 4/5] fix: import problem and optimize

---
 .../params-import/params-import.component.ts  | 11 +---
 .../services/extensions/extension.service.ts  | 21 +++----
 .../extensions/webExtension.service.ts        | 11 ----
 .../browser/src/app/utils/eo-merge.ts         | 62 +++++++++++++++++++
 4 files changed, 74 insertions(+), 31 deletions(-)
 create mode 100644 src/workbench/browser/src/app/utils/eo-merge.ts

diff --git a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
index 6821a69ac..67c0f014b 100644
--- a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
+++ b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
@@ -1,5 +1,6 @@
 import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
 import { EoNgFeedbackMessageService } from 'eo-ng-feedback';
+import { pcMerge } from 'eo/workbench/browser/src/app/utils/eo-merge';
 import { cloneDeep, toArray, merge, isEmpty } from 'lodash-es';
 import { computed, observable, makeObservable, reaction } from 'mobx';
 import qs from 'qs';
@@ -182,15 +183,7 @@ export class ParamsImportComponent implements OnInit {
     const combineFunc = {
       overwrite: data => data,
       append: (data, base) => base.concat(data),
-      mixin: (data, base) => {
-        const handleData = {};
-        for (let item of data) {
-          handleData[item.name] = {
-            'paramAttr.example': item.paramAttr.example
-          };
-        }
-        return obj2array(merge(array2obj(base), array2obj(handleData)));
-      }
+      mixin: (data, base) => pcMerge(base, data, 'paramAttr.example', 'childList', false)
     };
 
     const endParse = (data, type) => {
diff --git a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
index 2e9de22a0..762ebd05e 100644
--- a/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
+++ b/src/workbench/browser/src/app/shared/services/extensions/extension.service.ts
@@ -6,6 +6,7 @@ import { defaultExtensions } from 'eo/workbench/browser/src/app/shared/constants
 import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
 import { FeatureInfo, ExtensionInfo, SidebarView } from 'eo/workbench/browser/src/app/shared/models/extension-manager';
 import { MessageService } from 'eo/workbench/browser/src/app/shared/services/message';
+import { StoreService } from 'eo/workbench/browser/src/app/shared/store/state.service';
 import StorageUtil from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
 import { APP_CONFIG } from 'eo/workbench/browser/src/environments/environment';
 import { lastValueFrom, Subscription } from 'rxjs';
@@ -13,8 +14,6 @@ import { lastValueFrom, Subscription } from 'rxjs';
 import { ExtensionCommonService } from './extension-store.service';
 import { WebExtensionService } from './webExtension.service';
 
-const uninstallDefaultExtensions = StorageUtil.get('uninstall_default_ext_list');
-
 @Injectable({
   providedIn: 'root'
 })
@@ -33,7 +32,8 @@ export class ExtensionService {
     private extensionCommon: ExtensionCommonService,
     private language: LanguageService,
     private webExtensionService: WebExtensionService,
-    private messageService: MessageService
+    private messageService: MessageService,
+    public store: StoreService
   ) {}
   async init() {
     await this.requestList('init');
@@ -44,17 +44,16 @@ export class ExtensionService {
       });
       return;
     }
-
     //* Web Installl
     const installedName = [];
     //Get extensions
-    [
-      ...this.webExtensionService.installedList,
-      ...defaultExtensions.filter(item => !(uninstallDefaultExtensions || []).includes(item)).map(name => ({ name }))
-    ].forEach(val => {
-      if (this.installedList.some(m => m.name === val.name)) return;
-      installedName.push(val.name);
-    });
+    [...this.webExtensionService.installedList, ...(!this.store.getAppHasInitial ? defaultExtensions.map(name => ({ name })) : [])].forEach(
+      val => {
+        if (this.installedList.some(m => m.name === val.name)) return;
+        installedName.push(val.name);
+      }
+    );
+
     //* Install Extension by foreach because of async
     const uniqueNames = [...Array.from(new Set(installedName)), ...this.webExtensionService.debugExtensionNames];
     for (let i = 0; i < uniqueNames.length; i++) {
diff --git a/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts b/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
index 7091e4558..88b36cb13 100644
--- a/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
+++ b/src/workbench/browser/src/app/shared/services/extensions/webExtension.service.ts
@@ -1,7 +1,4 @@
 import { Injectable } from '@angular/core';
-import { TranslateService } from 'eo/platform/common/i18n';
-import { defaultExtensions } from 'eo/workbench/browser/src/app/shared/constants/extension';
-import { DISABLE_EXTENSION_NAMES } from 'eo/workbench/browser/src/app/shared/constants/storageKeys';
 import { eoDeepCopy } from 'eo/workbench/browser/src/app/utils/index.utils';
 import StorageUtil from 'eo/workbench/browser/src/app/utils/storage/storage.utils';
 import { APP_CONFIG } from 'eo/workbench/browser/src/environments/environment';
@@ -18,7 +15,6 @@ type ExtensionItem = {
 };
 
 const extKey = 'ext_installed_list';
-const uninstallDebugKey = 'uninstall_default_ext_list';
 
 //* Web Extension manage service
 //! Can't import by other component,please use ExtensionService
@@ -140,13 +136,6 @@ export class WebExtensionService {
   unInstallExtension(extName: string): boolean {
     this.installedList = this.installedList.filter(n => n.name !== extName);
     StorageUtil.set(extKey, this.installedList);
-    if (!StorageUtil.get(uninstallDebugKey)) {
-      StorageUtil.set(uninstallDebugKey, []);
-    }
-    const uninstallDefaultExtArr = StorageUtil.get(uninstallDebugKey);
-    const uninstallDefaultExt = defaultExtensions.find(item => item === extName);
-    uninstallDefaultExtArr.push(uninstallDefaultExt);
-    StorageUtil.set(uninstallDebugKey, Array.from(new Set(uninstallDefaultExtArr)));
     return true;
   }
 
diff --git a/src/workbench/browser/src/app/utils/eo-merge.ts b/src/workbench/browser/src/app/utils/eo-merge.ts
new file mode 100644
index 000000000..c6521d317
--- /dev/null
+++ b/src/workbench/browser/src/app/utils/eo-merge.ts
@@ -0,0 +1,62 @@
+import { cloneDeep } from 'lodash-es';
+export interface ParamAttr {
+  example: string;
+}
+
+export interface ChildList {
+  name: string;
+  isRequired: number;
+  description: string;
+  paramAttr: ParamAttr;
+  dataType: number;
+}
+
+export interface RootObject {
+  name: string;
+  isRequired: number;
+  paramAttr: ParamAttr;
+  dataType: number;
+  description: string;
+  childList: ChildList[];
+}
+
+/**
+ * @description Merge specified key
+ * @param {RootObject[]} baseArr baseArr
+ * @param {RootObject[]} newDataArr newDataArr
+ * @param {string} mergerKey specified key
+ * @param {string} childKey childList correspondence key
+ * @param {boolean} childKey isChild
+ * @return {RootObject[]} assginArr
+ */
+
+export const pcMerge = (
+  baseArr: RootObject[],
+  newDataArr: RootObject[],
+  mergerKey: string,
+  childKey: string,
+  isChild: boolean
+): RootObject[] => {
+  let handleData = !isChild ? cloneDeep(baseArr) : baseArr;
+  for (let item of newDataArr) {
+    //If you can't find this name, just push it
+    if (handleData.findIndex(ele => ele.name === item.name) === -1) handleData.push(item);
+    else {
+      for (let ele of handleData) {
+        if (item.name === ele.name) {
+          //Assigns the specified key
+          ele[mergerKey] = item[mergerKey];
+          if (item[childKey] && item[childKey].length !== 0) {
+            if (ele[childKey]) {
+              //Subtree recursion
+              pcMerge(ele[childKey], item[childKey], mergerKey, childKey, true);
+            } else {
+              ele[childKey] = item[childKey];
+            }
+          }
+        }
+      }
+    }
+  }
+  return handleData;
+};

From 6feb1a454ed8c9af03e9e9ec196adf0d2de2dc6d Mon Sep 17 00:00:00 2001
From: sunzhouyang <sunzhouyang@eolink.com>
Date: Tue, 14 Mar 2023 14:22:37 +0800
Subject: [PATCH 5/5] style: Modify file name

---
 .../modules/api-shared/params-import/params-import.component.ts | 2 +-
 .../browser/src/app/utils/{eo-merge.ts => pc-merge.ts}          | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename src/workbench/browser/src/app/utils/{eo-merge.ts => pc-merge.ts} (100%)

diff --git a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
index 67c0f014b..3c080dd7c 100644
--- a/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
+++ b/src/workbench/browser/src/app/modules/api-shared/params-import/params-import.component.ts
@@ -1,6 +1,6 @@
 import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
 import { EoNgFeedbackMessageService } from 'eo-ng-feedback';
-import { pcMerge } from 'eo/workbench/browser/src/app/utils/eo-merge';
+import { pcMerge } from 'eo/workbench/browser/src/app/utils/pc-merge';
 import { cloneDeep, toArray, merge, isEmpty } from 'lodash-es';
 import { computed, observable, makeObservable, reaction } from 'mobx';
 import qs from 'qs';
diff --git a/src/workbench/browser/src/app/utils/eo-merge.ts b/src/workbench/browser/src/app/utils/pc-merge.ts
similarity index 100%
rename from src/workbench/browser/src/app/utils/eo-merge.ts
rename to src/workbench/browser/src/app/utils/pc-merge.ts
