Skip to content

Commit

Permalink
fix: uninstall default and import problem (#267)
Browse files Browse the repository at this point in the history
* fix: uninstall default and import
---------

Co-authored-by: sunzhouyang <[email protected]>
  • Loading branch information
yZaio and sunzhouyang authored Mar 14, 2023
1 parent d68904a commit 6cbe019
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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/pc-merge';
import { cloneDeep, toArray, merge, isEmpty } from 'lodash-es';
import { computed, observable, makeObservable, reaction } from 'mobx';
import qs from 'qs';
Expand Down Expand Up @@ -182,7 +183,7 @@ 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) => pcMerge(base, data, 'paramAttr.example', 'childList', false)
};

const endParse = (data, type) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const defaultExtensions = ['postcat-export-openapi', 'postcat-import-openapi'];
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ 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 { 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';

import { ExtensionCommonService } from './extension-store.service';
import { WebExtensionService } from './webExtension.service';

const defaultExtensions = ['postcat-export-openapi', 'postcat-import-openapi'];
@Injectable({
providedIn: 'root'
})
Expand All @@ -31,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');
Expand All @@ -42,14 +44,16 @@ export class ExtensionService {
});
return;
}

//* Web Installl
const installedName = [];
//Get extensions
[...this.webExtensionService.installedList, ...defaultExtensions.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++) {
Expand Down
62 changes: 62 additions & 0 deletions src/workbench/browser/src/app/utils/pc-merge.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 6cbe019

Please sign in to comment.