Skip to content

Commit

Permalink
Enables Prettier formatting in TS files (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
walmazacn authored Jul 5, 2024
1 parent 9e30e36 commit 7ed726c
Show file tree
Hide file tree
Showing 28 changed files with 527 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ import { LuigiMockEngine } from '@luigi-project/testing-utilities';
* global message event of the window object and mocking the callback.
* In the normal workflow this message would picked up by Luigi Core which then sends the response back.
*/
export class LuigiMockModule { }
export class LuigiMockModule {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
ActivatedRouteSnapshot,
DetachedRouteHandle
} from '@angular/router';
import {LuigiRouteStrategy} from "./luigi-route-strategy";
import { ActivatedRouteSnapshot, DetachedRouteHandle } from '@angular/router';
import { LuigiRouteStrategy } from './luigi-route-strategy';

export class LuigiReuseRouteStrategy extends LuigiRouteStrategy {
private handlers: { [key: string]: DetachedRouteHandle } = {};
Expand All @@ -14,9 +11,7 @@ export class LuigiReuseRouteStrategy extends LuigiRouteStrategy {
let shouldReuse = false;
console.debug('checking if this route should be re used or not', route);
if (route.routeConfig.data) {
route.routeConfig.data.reuse
? (shouldReuse = true)
: (shouldReuse = false);
route.routeConfig.data.reuse ? (shouldReuse = true) : (shouldReuse = false);
}

return shouldReuse;
Expand All @@ -43,10 +38,7 @@ export class LuigiReuseRouteStrategy extends LuigiRouteStrategy {
return this.handlers[this.getUrl(route)];
}

shouldReuseRoute(
future: ActivatedRouteSnapshot,
current: ActivatedRouteSnapshot
): boolean {
shouldReuseRoute(future: ActivatedRouteSnapshot, current: ActivatedRouteSnapshot): boolean {
const defaultReuse = future.routeConfig === current.routeConfig;
return defaultReuse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ describe('LuigiAutoRoutingService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [LuigiContextService, LuigiAutoRoutingService],
imports: [
RouterTestingModule.withRoutes([]),
LuigiAngularSupportModule
],
imports: [RouterTestingModule.withRoutes([]), LuigiAngularSupportModule]
});
service = TestBed.inject(LuigiAutoRoutingService);
});
Expand Down Expand Up @@ -62,10 +59,7 @@ describe('LuigiAutoRoutingService', () => {

describe('doSubscription', () => {
it('doSubscription should take a NavigationEnd event and not do anything if the navigation was to no route with Luigi data', () => {
const doSubscriptionSpy = spyOn(
LuigiAutoRoutingService.prototype,
'doSubscription'
).and.callThrough();
const doSubscriptionSpy = spyOn(LuigiAutoRoutingService.prototype, 'doSubscription').and.callThrough();
const navigateSpy = jasmine.createSpy('navigate');
const linkManagerSpy = spyOn(Client, 'linkManager').and.returnValue(({
withoutSync: () => navigateSpy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Injectable, OnDestroy } from '@angular/core';
import { ActivatedRouteSnapshot, NavigationEnd, ParamMap, Router, RouterEvent, convertToParamMap } from '@angular/router';
import {
ActivatedRouteSnapshot,
NavigationEnd,
ParamMap,
Router,
RouterEvent,
convertToParamMap
} from '@angular/router';
import { linkManager, uxManager, isLuigiClientInitialized } from '@luigi-project/client';
import { OperatorFunction, Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
Expand Down Expand Up @@ -107,9 +114,7 @@ export class LuigiAutoRoutingService implements OnDestroy {
}
}

getResolvedLuigiRoute(
current: ActivatedRouteSnapshot
): string | undefined {
getResolvedLuigiRoute(current: ActivatedRouteSnapshot): string | undefined {
let route: string | undefined = current.data.luigiRoute;
const allParams = this.getAllParamsFromParents(current);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';

declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LuigiMockEngine {
}

(window as any).luigiMockEnvironment = {
msgListener: function (e: any) {
msgListener: function(e: any) {
if (e.data.msg && (e.data.msg.startsWith('luigi.') || e.data.msg === 'storage')) {
if (e.data.msg === 'luigi.get-context') {
window.postMessage(
Expand Down Expand Up @@ -132,7 +132,7 @@ export class LuigiMockEngine {
window.postMessage(response, '*');
},
// storage
storage: () => { }
storage: () => {}
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class LuigiMockUtil {
private messages: any[];
private browser: any;
private win: any
private win: any;

constructor(browser: any, win?: any) {
this.messages = [];
Expand Down Expand Up @@ -54,7 +54,7 @@ export class LuigiMockUtil {
return undefined;
}
})
.filter((item) => item !== undefined);
.filter(item => item !== undefined);
} catch (error) {
console.debug('Failed to parse luigi mocked messages: ', error);
}
Expand Down Expand Up @@ -110,13 +110,13 @@ export class LuigiMockUtil {
*/
mockPathExists = (path: string, exists: boolean): void => {
const window = this.getGlobalThis();
const mockContext: Record<string, boolean | string> = {path, exists};
const mockContext: Record<string, boolean | string> = { path, exists };
/**
* Sets the path exists mock data in sessionStorage.
* @param {string} path - The path for which mock data is to be set.
* @param {boolean} exists - Boolean indicating whether the path exists.
* @returns {Object} - Object indicating session storage item.
*/
* Sets the path exists mock data in sessionStorage.
* @param {string} path - The path for which mock data is to be set.
* @param {boolean} exists - Boolean indicating whether the path exists.
* @returns {Object} - Object indicating session storage item.
*/
const setPathExistsMockData = (context: Record<string, boolean | string>): Record<string, any> => {
window.sessionStorage.clear();

Expand Down Expand Up @@ -212,4 +212,4 @@ export class LuigiMockUtil {
getMSG(): any[] {
return this.messages;
}
}
}
8 changes: 4 additions & 4 deletions container/src/constants/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ export namespace Events {
*/
export const SET_DIRTY_STATUS_REQUEST = 'set-dirty-status-request';

/**
/**
* A message emitted from the micro frontend when a request to set the view group data
*/
export const SET_VIEW_GROUP_DATA_REQUEST = 'set-viewgroup-data-request';
export const SET_VIEW_GROUP_DATA_REQUEST = 'set-viewgroup-data-request';

/**
* A message emitted from the micro frontend when a request to set the document title
*/
export const SET_DOCUMENT_TITLE_REQUEST = 'set-document-title-request';

/**
* A message emitted from the micro frontend when a request to open user settings
* A message emitted from the micro frontend when a request to open user settings
*/
export const OPEN_USER_SETTINGS_REQUEST = 'open-user-settings-request';

/**
* A message emitted from the micro frontend when a request to close user settings
* A message emitted from the micro frontend when a request to close user settings
*/
export const CLOSE_USER_SETTINGS_REQUEST = 'close-user-settings-request';

Expand Down
8 changes: 4 additions & 4 deletions container/src/constants/event-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ export interface ParamsEvent extends Event {}
/**
* PathExistsEvent interface is used to make it easier to use the linkManager().pathExists() promise based function
* on the core application side.
* It enforces the use of the callback function, since the latter is hardcoded to be 'callback'.
* It enforces the use of the callback function, since the latter is hardcoded to be 'callback'.
* This allows to send back the boolean value if the path exists or not.
* Example Usage:
* Example Usage:
* addEventListener('my-event-id' event: PathExistsEvent => {
* event.callback(true);
* }
* };
*/
export interface PathExistsEvent extends Event {
callback: (value: boolean) => void;
}
callback: (value: boolean) => void;
}
2 changes: 1 addition & 1 deletion container/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// <reference types="svelte" />
// This file is needed to avoid Typescript warnings about Svele Components being imported to main.ts
// This file is needed to avoid Typescript warnings about Svelte Components being imported to main.ts
16 changes: 8 additions & 8 deletions container/src/services/container.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ContainerService {
* @param {HTMLElement} component - The HTML element to check for visibility.
* @returns {boolean} Returns true if the element is visible, otherwise false.
*/
isVisible (component: HTMLElement): boolean {
isVisible(component: HTMLElement): boolean {
return !!(component.offsetWidth || component.offsetHeight || component.getClientRects().length);
}

Expand All @@ -20,7 +20,7 @@ export class ContainerService {
* @param msg the message to be sent
* @param msgName the optional message name
*/
sendCustomMessageToIframe (iframeHandle: any, msg: any, msgName?: string) {
sendCustomMessageToIframe(iframeHandle: any, msg: any, msgName?: string) {
const messageName = msgName || 'custom';
if (iframeHandle.iframe.contentWindow) {
const iframeUrl = new URL(iframeHandle.iframe.src);
Expand All @@ -40,7 +40,7 @@ export class ContainerService {
* @param {Function} callback
* @param {string} callbackName
*/
dispatch (msg: string, targetCnt: HTMLElement, data: any, callback?: Function, callbackName?: string): void {
dispatch(msg: string, targetCnt: HTMLElement, data: any, callback?: Function, callbackName?: string): void {
const customEvent = new CustomEvent(msg, { detail: data });
if (callback && GenericHelperFunctions.isFunction(callback) && callbackName) {
(customEvent as any)[callbackName] = data => {
Expand All @@ -56,7 +56,7 @@ export class ContainerService {
* @param event The event object representing the source of the container.
@returns {Object| undefined} The target container object or undefined if not found.
*/
getTargetContainer (event) {
getTargetContainer(event) {
let cnt;
globalThis.__luigi_container_manager.container.forEach(element => {
if (element.iframeHandle?.iframe && element.iframeHandle.iframe.contentWindow === event.source) {
Expand All @@ -69,11 +69,11 @@ export class ContainerService {

/**
* Initializes the Luigi Container Manager responsible for managing communication
* between microfrontends and dispatching events accordingly. Also adds 'message' listener to the window object with
* between microfrontends and dispatching events accordingly. Also adds 'message' listener to the window object with
* the defined messageListener list
* @returns __luigi_container_manager which has the added container array and message listeners
*/
getContainerManager () {
getContainerManager() {
if (!globalThis.__luigi_container_manager) {
globalThis.__luigi_container_manager = {
container: [],
Expand Down Expand Up @@ -191,9 +191,9 @@ export class ContainerService {
*
* @param {HTMLElement} thisComponent - The HTML element that represents the current rendered container (thisComponent)
*/
registerContainer (thisComponent: HTMLElement): void {
registerContainer(thisComponent: HTMLElement): void {
this.getContainerManager().container.push(thisComponent);
}
}

export const containerService = new ContainerService();
export const containerService = new ContainerService();
16 changes: 8 additions & 8 deletions container/src/services/iframe-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* @returns {string|undefined} The modified allow rules joined as a single string, or undefined if allowRules is falsy.
*/
export const getAllowRules = (allowRules: string[]) => {
if (!allowRules) return undefined;
const rules = allowRules;
rules.forEach((rule, index) => {
rules[index] = rule + (rule.indexOf(';') != -1 ? '' : ';');
rules[index] = (allowRules[index] as any).replaceAll('"', "'");
});
return rules.join(' ');
};
if (!allowRules) return undefined;
const rules = allowRules;
rules.forEach((rule, index) => {
rules[index] = rule + (rule.indexOf(';') != -1 ? '' : ';');
rules[index] = (allowRules[index] as any).replaceAll('"', "'");
});
return rules.join(' ');
};
Loading

0 comments on commit 7ed726c

Please sign in to comment.