Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uninstall default and import problem #267

Merged
merged 6 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: import problem and optimize
  • Loading branch information
sunzhouyang committed Mar 14, 2023
commit ce9afa4a6b9153bfb2ae17ddaad0541092cfda2e
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/eo-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,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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ 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';

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

const uninstallDefaultExtensions = StorageUtil.get('uninstall_default_ext_list');

@Injectable({
providedIn: 'root'
})
Expand All @@ -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');
Expand All @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
62 changes: 62 additions & 0 deletions src/workbench/browser/src/app/utils/eo-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;
};