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

feat: P002271-6012 delete mfe info #49

Merged
merged 14 commits into from
Jan 18, 2024
3 changes: 1 addition & 2 deletions libs/accelerator/src/lib/topic/syncable-topic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ describe('Syncable Topic', () => {
it('should get correct value', async () => {
expect(testSyncableTopic1.getValue()).toEqual(undefined)

testSyncableTopic1.publish('value1')
await testSyncableTopic1.isInitialized
await testSyncableTopic1.publish('value1')

expect(testSyncableTopic1.getValue()).toEqual('value1')
expect(testSyncableTopic2.getValue()).toEqual('value1')
Expand Down
12 changes: 12 additions & 0 deletions libs/accelerator/src/lib/topic/topic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,16 @@ describe('Topic', () => {
expect(v).toEqual(6)
expect(values1).toEqual(['value1'])
})

it('should check isInitialized', (done) => {
let initialized = false
testTopic1.isInitialized.then(() => (initialized = true))

expect(initialized).toBe(false)

testTopic1.publish('test')
setTimeout(() => {
KimFFVII marked this conversation as resolved.
Show resolved Hide resolved
expect(initialized).toBe(true)
}, done())
})
})
12 changes: 11 additions & 1 deletion libs/accelerator/src/lib/topic/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Topic<T> implements Subscribable<T> {
protected isInit = false
private resolveInitPromise!: (value: void | PromiseLike<void>) => void
private eventListener = (m: MessageEvent<TopicMessage>) => this.onMessage(m)
private publishPromiseResolver: Record<number, () => void> = {}

constructor(private name: string, private version: number) {
this.isInitializedPromise = new Promise<void>((resolve) => {
Expand Down Expand Up @@ -132,9 +133,13 @@ export class Topic<T> implements Subscribable<T> {
return (<any>this.asObservable()).pipe(...operations)
}

publish(value: T) {
publish(value: T): Promise<void> {
const message = new TopicDataMessage<T>(TopicMessageType.TopicNext, this.name, this.version, value)
const promise = new Promise<void>((resolve) => {
this.publishPromiseResolver[message.timestamp] = resolve
})
window.postMessage(message, '*')
return promise
}

destroy() {
Expand All @@ -152,6 +157,11 @@ export class Topic<T> implements Subscribable<T> {
this.isInit = true
this.data.next(<TopicDataMessage<T>>m.data)
this.resolveInitPromise()
const publishPromiseResolver = this.publishPromiseResolver[m.data.timestamp]
if (publishPromiseResolver) {
publishPromiseResolver()
delete this.publishPromiseResolver[m.data.timestamp]
}
}
break
case TopicMessageType.TopicGet:
Expand Down
5 changes: 2 additions & 3 deletions libs/keycloak-auth/src/lib/keycloak-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ export class KeycloakAuthService implements IAuthService {
return this.keycloakService.login().then(() => 'login')
}
})
.then(() => {
this.appStateService.isAuthenticated$.publish()
return this.appStateService.isAuthenticated$.isInitialized
.then(async () => {
await this.appStateService.isAuthenticated$.publish()
})
.then(() => true)
.catch((err) => {
Expand Down
1 change: 1 addition & 0 deletions libs/portal-integration-angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ export * from './lib/core/utils/colorutils'
export * from './lib/core/utils/translate.combined.loader'
export * from './lib/core/utils/image-logo-url.utils'
export * from './lib/core/utils/async-translate-loader.utils'
export * from './lib/core/utils/create-translate-loader.utils'
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InjectionToken } from '@angular/core'
import { MfeInfo } from '../model/mfe-info.model'
import { IAuthService } from './iauth.service'

export interface LibConfig {
Expand All @@ -18,14 +17,6 @@ export const APP_CONFIG = new InjectionToken<LibConfig>('APP_CONFIG')

export const AUTH_SERVICE = new InjectionToken<IAuthService>('AUTH_SERVICE')

// export const MFE_NAME = new InjectionToken<string>('OCX_MFE_NAME')

export const MFE_INFO_FN = new InjectionToken<mfeInfoProducer>('OCX_MFE_INFO_FN')

export const MFE_INFO = new InjectionToken<MfeInfo>('OCX_MFE_INFO')

export type mfeInfoProducer = () => MfeInfo

export const SANITY_CHECK = new InjectionToken<string>('OCXSANITY_CHECK')

export const APPLICATION_NAME = new InjectionToken<string>('APPLICATION_NAME')
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ describe('AnnouncementBannerComponent', () => {
}).compileComponents()

const appStateService = getTestBed().inject(AppStateService)
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
id: 'i-am-test-portal',
portalName: 'test',
baseUrl: '',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized

announcementsApiService = getTestBed().inject(AnnouncementsApiService)
jest.spyOn(announcementsApiService, 'getAnnouncementById').mockReturnValue(getAnnouncementByIdMock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import { HttpClientModule } from '@angular/common/http'
import { AppStateService } from '../../../services/app-state.service'

async function initFactory(appStateService: AppStateService) {
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
baseUrl: '/demo',
portalName: 'Demo',
id: 'Demo',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized

return () => {
appStateService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<div class="flex justify-content-center mb-3">
<img
class="image"
src="{{ item.imagePath }}"
(error)="imgError($event)"
src="{{ item.imagePath || (fallbackImagePath$ | async) }}"
(error)="imgError(item)"
alt="{{resolveFieldData(item, titleLineId)|| ''}}"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@angular/core'
import { DataSortDirection } from '../../../model/data-sort-direction'
import { MenuItem } from 'primeng/api'
import { MFE_INFO } from '../../../api/injection-tokens'
import { MfeInfo } from '../../../model/mfe-info.model'
import { DataAction } from '../../../model/data-action'
import { TranslateService } from '@ngx-translate/core'
Expand All @@ -24,6 +23,7 @@ import { BehaviorSubject, combineLatest, map, mergeMap, Observable } from 'rxjs'
import { DataSortBase } from '../data-sort-base/data-sort-base'
import { Router } from '@angular/router'
import { UserService } from '../../../services/user.service'
import { AppStateService } from '../../../services/app-state.service'

export type ListGridData = {
id: string | number
Expand Down Expand Up @@ -164,17 +164,21 @@ export class DataListGridComponent extends DataSortBase implements OnInit, DoChe
observedOutputs = 0

displayedItems$: Observable<unknown[]> | undefined
fallbackImagePath$!: Observable<string>

constructor(
@Inject(LOCALE_ID) locale: string,
@Inject(MFE_INFO) private mfeInfo: MfeInfo,
translateService: TranslateService,
private userService: UserService,
private router: Router,
private injector: Injector
private injector: Injector,
private appStateService: AppStateService
) {
super(locale, translateService)
this.name = this.name || this.router.url.replace(/[^A-Za-z0-9]/, '_')
this.fallbackImagePath$ = this.appStateService.currentMfe$.pipe(
map((currentMfe) => this.getFallbackImagePath(currentMfe))
)
}

ngDoCheck(): void {
Expand Down Expand Up @@ -213,10 +217,8 @@ export class DataListGridComponent extends DataSortBase implements OnInit, DoChe
this.editItem.emit(element)
}

imgError(event: Event) {
if (!!this.fallbackImage && (<any>event?.target)?.src != this.fallbackImage) {
;(<any>event.target).src = this.getFallbackImagePath(this.mfeInfo)
}
imgError(item: ListGridData) {
item.imagePath = ''
}

getFallbackImagePath(mfeInfo: MfeInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { DataViewComponent } from './data-view.component'
import { MockAuthModule } from '../../../mock-auth/mock-auth.module'
import { DataListGridComponent } from '../data-list-grid/data-list-grid.component'
import { DataViewModule } from 'primeng/dataview'
import { MFE_INFO } from '../../../api/injection-tokens'
import { TranslateTestingModule } from 'ngx-translate-testing'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { DataTableComponent } from '../data-table/data-table.component'
Expand All @@ -17,17 +16,6 @@ describe('DataViewComponent', () => {
await TestBed.configureTestingModule({
declarations: [DataViewComponent, DataListGridComponent, DataTableComponent],
imports: [DataViewModule, MockAuthModule, TranslateTestingModule.withTranslations({}), HttpClientTestingModule],
providers: [
{
provide: MFE_INFO,
useValue: {
baseHref: '/base/path',
mountPath: '/base/path',
remoteBaseUrl: 'http://localhost:4200',
shellName: 'shell',
},
},
],
}).compileComponents()

fixture = TestBed.createComponent(DataViewComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'
import { ChartModule } from 'primeng/chart'
import { MessageModule } from 'primeng/message'
import { MockAuthModule } from '../../../mock-auth/mock-auth.module'
import { MFE_INFO } from '../../../api/injection-tokens'
import { DiagramHarness, TestbedHarnessEnvironment } from '../../../../../testing'
import { TranslateService } from '@ngx-translate/core'

Expand Down Expand Up @@ -43,17 +42,6 @@ describe('DiagramComponent', () => {
}),
HttpClientTestingModule,
],
providers: [
{
provide: MFE_INFO,
useValue: {
baseHref: '/base/path',
mountPath: '/base/path',
remoteBaseUrl: 'http://localhost:4200',
shellName: 'shell',
},
},
],
}).compileComponents()

fixture = TestBed.createComponent(DiagramComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'
import { GroupByCountDiagramComponent } from './group-by-count-diagram.component'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { TranslateTestingModule } from 'ngx-translate-testing'
import { MFE_INFO } from '../../../api/injection-tokens'
import { MockAuthModule } from '../../../mock-auth/mock-auth.module'
import { ColumnType } from '../../../model/column-type.model'
import { MessageModule } from 'primeng/message'
Expand Down Expand Up @@ -158,17 +157,6 @@ describe('GroupByCountDiagramComponent', () => {
}),
HttpClientTestingModule,
],
providers: [
{
provide: MFE_INFO,
useValue: {
baseHref: '/base/path',
mountPath: '/base/path',
remoteBaseUrl: 'http://localhost:4200',
shellName: 'shell',
},
},
],
}).compileComponents()

fixture = TestBed.createComponent(GroupByCountDiagramComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { HarnessLoader, parallel, TestElement } from '@angular/cdk/testing'
import { PortalCoreModule } from '../../portal-core.module'
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'
import { ColumnType } from '../../../model/column-type.model'
import { MFE_INFO } from '../../../api/injection-tokens'
import {
DataViewHarness,
ColumnGroupSelectionHarness,
Expand Down Expand Up @@ -234,15 +233,6 @@ describe('InteractiveDataViewComponent', () => {
HttpClientModule,
],
providers: [
{
provide: MFE_INFO,
useValue: {
baseHref: '/base/path',
mountPath: '/base/path',
remoteBaseUrl: 'http://localhost:4200',
shellName: 'shell',
},
},
{ provide: UserService, useClass: MockUserService },
],
}).compileComponents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ describe('PageHeaderComponent', () => {
}).compileComponents()

const appStateService = getTestBed().inject(AppStateService)
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
id: 'i-am-test-portal',
portalName: 'test',
baseUrl: '',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized
})

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ function initFactory(breadcrumbService: BreadcrumbService, appStateService: AppS
{ label: 'Level 1', routerLink: 'something' },
{ label: 'Level 2', url: '/' },
])
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
baseUrl: '/demo',
portalName: 'Demo',
id: 'Demo',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ describe('PortalFooterComponent', () => {
}).compileComponents()

const appStateService = getTestBed().inject(AppStateService)
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
id: 'i-am-test-portal',
portalName: 'test',
baseUrl: '',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized
}))

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import { mockedGetMenu } from '../../../../../mocks/menuMapper'
import { AppStateService } from '../../../services/app-state.service'

async function initFactory(appStateService: AppStateService) {
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
baseUrl: '/demo',
portalName: 'Demo',
id: 'Demo',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized

return () => {
appStateService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ describe('PortalViewportComponent', () => {

beforeEach(async () => {
const appStateService = getTestBed().inject(AppStateService)
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
id: 'i-am-test-portal',
portalName: 'test',
baseUrl: '',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized

fixture = TestBed.createComponent(PortalViewportComponent)
component = fixture.componentInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ describe('SearchCriteriaComponent', () => {
component = fixture.componentInstance

const appStateService = getTestBed().inject(AppStateService)
appStateService.currentPortal$.publish({
await appStateService.currentPortal$.publish({
id: 'i-am-test-portal',
portalName: 'test',
baseUrl: '',
microfrontendRegistrations: [],
})
await appStateService.currentPortal$.isInitialized

fixture.detectChanges()
})
Expand Down
Loading
Loading