Skip to content

Commit

Permalink
feat: dialog service allows providing component type
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy committed Feb 5, 2024
1 parent de9922f commit 5e42fba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe('PortalDialogService', () => {
it('should display dialog with custom component if provided', async () => {
jest.spyOn(pDialogService, 'open')

fixture.componentInstance.show('title', { type: TestWithInputsComponent }, 'button1', 'button2')
fixture.componentInstance.show('title', TestWithInputsComponent, 'button1', 'button2')

const dialogHarness = await rootLoader.getHarness(ButtonDialogHarness)
const headerDiv = await dialogHarness.getHarness(DivHarness.with({ class: 'testHeader' }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export class PortalDialogService {
*/
openDialog<T>(
title: TranslationKey | null,
componentOrMessage: Component<T> | TranslationKey | DialogMessage,
componentOrMessage: Type<any> | Type<DialogResult<T>> | Component<T> | TranslationKey | DialogMessage,
primaryButtonTranslationKeyOrDetails: TranslationKey | ButtonDialogButtonDetails,
secondaryButtonTranslationKeyOrDetails?: TranslationKey | ButtonDialogButtonDetails,
showXButton: boolean = true
Expand Down Expand Up @@ -393,7 +393,9 @@ export class PortalDialogService {
return buttonDetails
}

private getComponentToRender(componentOrMessage: Component<any> | TranslationKey | DialogMessage): Component<any> {
private getComponentToRender(
componentOrMessage: Type<any> | Type<DialogResult<any>> | Component<any> | TranslationKey | DialogMessage
): Component<any> {
if (this.isTranslationKey(componentOrMessage)) {
return {
type: DialogMessageContentComponent,
Expand All @@ -413,6 +415,10 @@ export class PortalDialogService {
messageParameters: this.isString(componentOrMessage.message) ? {} : componentOrMessage.message.parameters,
},
}
} else if (this.isType(componentOrMessage)) {
return {
type: componentOrMessage,
}
}
return componentOrMessage
}
Expand All @@ -428,4 +434,8 @@ export class PortalDialogService {
private isDialogMessage(obj: any): obj is DialogMessage {
return 'message' in obj && 'icon' in obj
}

private isType(obj: any): obj is Type<any> {
return obj instanceof Type
}
}

0 comments on commit 5e42fba

Please sign in to comment.