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

[AAE-7241] fix eslint warnings for Extensions project #7491

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 1 addition & 12 deletions lib/extensions/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@
"eslint-plugin-rxjs"
],
"rules": {
"jsdoc/newline-after-description": "warn",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"no-underscore-dangle": "warn",
"no-shadow": "warn",
"quote-props": "warn",
"object-shorthand": "warn",
"prefer-const": "warn",
"arrow-body-style": "warn",
"@angular-eslint/no-output-native": "warn",
"space-before-function-paren": "warn",
"no-underscore-dangle": ["error", { "allowAfterThis": true }],

"@angular-eslint/component-selector": [
"error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('DynamicExtensionComponent', () => {
component.ngOnChanges({});
fixture.detectChanges();

expect((<any> componentFactoryResolver.resolveComponentFactory).calls.count()).toBe(1);
expect((componentFactoryResolver.resolveComponentFactory as any).calls.count()).toBe(1);
});

it('should pass through the data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export class DynamicExtensionComponent implements OnChanges, OnDestroy {
this.proxy('ngOnChanges', changes);
}

ngOnDestroy() {
if (this.componentCreated()) {
this.componentRef.destroy();
this.componentRef = null;
}
}

private loadComponent() {
const componentType = this.extensions.getComponentById<ExtensionComponent>(this.id);
if (componentType) {
Expand All @@ -76,13 +83,6 @@ export class DynamicExtensionComponent implements OnChanges, OnDestroy {
}
}

ngOnDestroy() {
if (this.componentCreated()) {
this.componentRef.destroy();
this.componentRef = null;
}
}

private updateInstance() {
if (this.componentCreated()) {
this.componentRef.instance.data = this.data;
Expand Down
5 changes: 3 additions & 2 deletions lib/extensions/src/lib/config/action.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { ExtensionElement } from './extension-element';

// eslint-disable-next-line no-shadow
export enum ContentActionType {
default = 'default',
button = 'button',
Expand All @@ -36,13 +37,13 @@ export interface ContentActionRef extends ExtensionElement {
data?: any;
color?: string;
actions?: {
click?: string;
[key: string]: string;
click?: string;
};
rules?: {
[key: string]: string;
enabled?: string;
visible?: string;
[key: string]: string;
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/extensions/src/lib/config/extension-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('Extension Utils', () => {
});

it('should not process special properties starting with $', () => {
const obj1 = { '$id': 'uid', aHello: 1 };
const obj2 = { '$schema': 'schema-id', bWorld: 2 };
const obj1 = { $id: 'uid', aHello: 1 };
const obj2 = { $schema: 'schema-id', bWorld: 2 };

const result = mergeObjects(obj1, obj2);

Expand Down
34 changes: 16 additions & 18 deletions lib/extensions/src/lib/config/extension-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { ContentActionRef, ContentActionType } from './action.extensions';

export function getValue(target: any, key: string): any {
export const getValue = (target: any, key: string): any => {
if (!target) {
return undefined;
}
Expand All @@ -42,27 +42,25 @@ export function getValue(target: any, key: string): any {
} while (keys.length);

return target;
}
};

export function filterEnabled(entry: { disabled?: boolean }): boolean {
return !entry.disabled;
}
export const filterEnabled = (entry: { disabled?: boolean }): boolean => !entry.disabled;

export function sortByOrder(
export const sortByOrder = (
a: { order?: number | undefined },
b: { order?: number | undefined }
) {
) => {
const left = a.order === undefined ? Number.MAX_SAFE_INTEGER : a.order;
const right = b.order === undefined ? Number.MAX_SAFE_INTEGER : b.order;
return left - right;
}
};

export function reduceSeparators(
export const reduceSeparators = (
acc: ContentActionRef[],
el: ContentActionRef,
i: number,
arr: ContentActionRef[]
): ContentActionRef[] {
): ContentActionRef[] => {
// remove leading separator
if (i === 0) {
if (arr[i].type === ContentActionType.separator) {
Expand All @@ -88,21 +86,21 @@ export function reduceSeparators(
}

return acc.concat(el);
}
};

export function reduceEmptyMenus(
export const reduceEmptyMenus = (
acc: ContentActionRef[],
el: ContentActionRef
): ContentActionRef[] {
): ContentActionRef[] => {
if (el.type === ContentActionType.menu) {
if ((el.children || []).length === 0) {
return acc;
}
}
return acc.concat(el);
}
};

export function mergeObjects(...objects: any[]): any {
export const mergeObjects = (...objects: any[]): any => {
const result = {};

objects.forEach((source) => {
Expand All @@ -129,9 +127,9 @@ export function mergeObjects(...objects: any[]): any {
});

return result;
}
};

export function mergeArrays(left: any[], right: any[]): any[] {
export const mergeArrays = (left: any[], right: any[]): any[] => {
const result = [];
const map = {};

Expand All @@ -155,4 +153,4 @@ export function mergeArrays(left: any[], right: any[]): any[] {
});

return Object.keys(map).map((key) => map[key]).concat(result);
}
};
2 changes: 1 addition & 1 deletion lib/extensions/src/lib/config/sidebar.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SidebarTabRef extends ExtensionElement {

icon?: string;
rules?: {
visible?: string;
[key: string]: string;
visible?: string;
};
}
2 changes: 1 addition & 1 deletion lib/extensions/src/lib/config/viewer.extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ViewerExtensionRef extends ExtensionElement {
component: string;

rules?: {
visible?: string;
[key: string]: string;
visible?: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { RuleParameter } from '../config/rule.extensions';
describe('Core Evaluators', () => {

const context: any = {
getEvaluator(key: string) {
getEvaluator: (key: string) => {
switch (key) {
case 'positive':
return () => true;
Expand Down
12 changes: 6 additions & 6 deletions lib/extensions/src/lib/evaluators/core.evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { RuleContext, RuleParameter } from '../config/rule.extensions';

export function not(context: RuleContext, ...args: RuleParameter[]): boolean {
export const not = (context: RuleContext, ...args: RuleParameter[]): boolean => {
if (!args || args.length === 0) {
return false;
}
Expand All @@ -31,9 +31,9 @@ export function not(context: RuleContext, ...args: RuleParameter[]): boolean {
}
return !evaluator(context, ...(arg.parameters || []));
});
}
};

export function every(context: RuleContext, ...args: RuleParameter[]): boolean {
export const every = (context: RuleContext, ...args: RuleParameter[]): boolean => {
if (!args || args.length === 0) {
return false;
}
Expand All @@ -47,9 +47,9 @@ export function every(context: RuleContext, ...args: RuleParameter[]): boolean {
}
return evaluator(context, ...(arg.parameters || []));
});
}
};

export function some(context: RuleContext, ...args: RuleParameter[]): boolean {
export const some = (context: RuleContext, ...args: RuleParameter[]): boolean => {
if (!args || args.length === 0) {
return false;
}
Expand All @@ -63,4 +63,4 @@ export function some(context: RuleContext, ...args: RuleParameter[]): boolean {
}
return evaluator(context, ...(arg.parameters || []));
});
}
};
4 changes: 1 addition & 3 deletions lib/extensions/src/lib/mock/app-extension.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import { ViewerExtensionRef } from '../config/viewer.extensions';
providedIn: 'root'
})
export class AppExtensionServiceMock {
private _references = new BehaviorSubject<ExtensionRef[]>([]);

references$: Observable<ExtensionRef[]>;
private _references = new BehaviorSubject<ExtensionRef[]>([]);

constructor() {
this.references$ = this._references.asObservable();
Expand All @@ -35,5 +34,4 @@ export class AppExtensionServiceMock {
getViewerExtensions(): ViewerExtensionRef[] {
return [];
}

}
6 changes: 3 additions & 3 deletions lib/extensions/src/lib/services/app-extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import { DocumentListPresetRef } from '../config/document-list.extensions';
providedIn: 'root'
})
export class AppExtensionService {
private _references = new BehaviorSubject<ExtensionRef[]>([]);

references$: Observable<ExtensionRef[]>;
private _references = new BehaviorSubject<ExtensionRef[]>([]);

constructor(protected extensionService: ExtensionService) {
this.references$ = this._references.asObservable();
Expand All @@ -46,13 +45,14 @@ export class AppExtensionService {

const references = (config.$references || [])
.filter((entry) => typeof entry === 'object')
.map((entry) => <ExtensionRef> entry);
.map((entry) => entry as ExtensionRef);
this._references.next(references);
}

/**
* Provides a collection of document list columns for the particular preset.
* The result is filtered by the **disabled** state.
*
* @param key Preset key.
*/
getDocumentListPreset(key: string): DocumentListPresetRef[] {
Expand Down
64 changes: 32 additions & 32 deletions lib/extensions/src/lib/services/extension-loader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,6 @@ export class ExtensionLoaderService {
});
}

protected getMetadata(config: ExtensionConfig): ExtensionRef {
const result: any = {};

Object
.keys(config)
.filter((key) => key.startsWith('$'))
.forEach((key) => {
result[key] = config[key];
});

return result;
}

protected loadConfig(
url: string,
order: number
): Promise<{ order: number; config: ExtensionConfig }> {
return new Promise((resolve) => {
this.http.get<ExtensionConfig>(url).subscribe(
(config) => {
resolve({
order,
config
});
},
() => {
resolve(null);
}
);
});
}

/**
* Retrieves configuration elements.
* Filters element by **enabled** and **order** attributes.
Expand Down Expand Up @@ -161,6 +129,38 @@ export class ExtensionLoaderService {
return [];
}

protected getMetadata(config: ExtensionConfig): ExtensionRef {
const result: any = {};

Object
.keys(config)
.filter((key) => key.startsWith('$'))
.forEach((key) => {
result[key] = config[key];
});

return result;
}

protected loadConfig(
url: string,
order: number
): Promise<{ order: number; config: ExtensionConfig }> {
return new Promise((resolve) => {
this.http.get<ExtensionConfig>(url).subscribe(
(config) => {
resolve({
order,
config
});
},
() => {
resolve(null);
}
);
});
}

protected setActionDefaults(action: ContentActionRef): ContentActionRef {
if (action) {
action.type = action.type || ContentActionType.default;
Expand Down
Loading