Skip to content

feat: replace CpsDialogConfig class with interface + InjectionToken#700

Open
fateeand wants to merge 3 commits into
next-majorfrom
571-replace-cpsdialogconfig-class-with-interface-injectiontoken-to-reduce-bundle-size
Open

feat: replace CpsDialogConfig class with interface + InjectionToken#700
fateeand wants to merge 3 commits into
next-majorfrom
571-replace-cpsdialogconfig-class-with-interface-injectiontoken-to-reduce-bundle-size

Conversation

@fateeand

@fateeand fateeand commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This PR targets the next-major branch, rather than master, as it is part of the next major version update.

Summary

CpsDialogConfig was a TypeScript class used both as a type annotation and — because Angular allows implicit class-based DI tokens — as the actual runtime provider token for injecting dialog config into CpsDialogComponent and CpsConfirmationComponent. Being referenced as a DI token meant it couldn't be erased at compile time, so it emitted a real (empty) runtime constructor purely to support token identity.

This PR:

  • Converts CpsDialogConfig to a plain interface (zero runtime cost — confirmed via the production FESM bundle, class CpsDialogConfig no longer appears anywhere in build output).
  • Introduces CPS_DIALOG_CONFIG, a dedicated InjectionToken<CpsDialogConfig>, and repoints all internal DI usages (the CpsDialogService provider registration, and constructor injection in CpsDialogComponent / CpsConfirmationComponent) to use it instead of the class.

⚠️ Breaking changes

Consumers who provided or injected CpsDialogConfig as an Angular DI token must switch to CPS_DIALOG_CONFIG:

- { provide: CpsDialogConfig, useValue: config }
+ { provide: CPS_DIALOG_CONFIG, useValue: config }
- constructor(private config: CpsDialogConfig) {}
+ constructor(@Inject(CPS_DIALOG_CONFIG) private config: CpsDialogConfig) {}

Plain type annotations (config: CpsDialogConfig) and object literals passed to CpsDialogService.open() / openConfirmationDialog() are unaffected — this only breaks consumers who used CpsDialogConfig as a DI token.

BREAKING CHANGE: CpsDialogConfig is now an interface instead of a class and can no longer be used as an Angular DI token. Inject CPS_DIALOG_CONFIG instead.

Other changes: docs-site fixes

While verifying the new token rendered correctly on the API docs site, found and fixed a few pre-existing bugs in the shared docs infrastructure (api-generator/api-generator.js and projects/composition):

  • ServiceDocsViewerComponent (backs standalone-service pages like /dialog/api) had no "Tokens" rendering block at all, even though the data model already supported it — added one, matching the pattern already used by ComponentDocsViewerComponent.
  • Extended the same "Tokens" support to component-level tokens (ComponentDocsViewerComponent), and tagged CPS_RADIO_GROUP / ICONS_PATH with @group Tokens so they now show up on /radio-group/api and /icon/api too.
  • typesMap (used to turn type names into clickable deep links) never included components or services, only interfaces/types/enums/classes — extended it to cover both, guarded by cross-referencing real routes in app-routing.module.ts so services that are only ever embedded into another page (e.g. CpsCronValidationService, shown only on /scheduler/api) don't get linked to a non-existent route.
  • DetectTypePipe's generic-type regex only handled one level of nesting with no unions, so types like InjectionToken<CpsDialogConfig<any>> silently fell back to unlinked plain text. Replaced it with a general identifier scanner that links any recognized type name found anywhere inside an arbitrarily nested expression.

Release notes:

  • Replace CpsDialogConfig class with interface + InjectionToken to reduce bundle size

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report for library

St.
Category Percentage Covered / Total
🟡 Statements 67.88% 5645/8316
🔴 Branches 57.33% 2449/4272
🟡 Functions 67.97% 1059/1558
🟡 Lines 68.91% 5274/7654

Test suite run success

2188 tests passing in 63 suites.

Report generated by 🧪jest coverage report action from d2c5cfe

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the runtime cost of CpsDialogConfig by converting it from a DI-token-able class into a pure TypeScript interface, and introduces a dedicated CPS_DIALOG_CONFIG InjectionToken for dialog config injection. It also improves the composition docs site to render and deep-link injection tokens and more complex type expressions.

Changes:

  • Replace CpsDialogConfig class with an interface and add CPS_DIALOG_CONFIG InjectionToken<CpsDialogConfig>, updating internal providers/injection sites accordingly.
  • Update unit tests and composition examples to provide/inject dialog config via CPS_DIALOG_CONFIG and to stop instantiating new CpsDialogConfig().
  • Extend docs-site generation/rendering to support “Tokens” blocks and improve type-link detection (including nested generics/unions) and link coverage.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/cps-ui-kit/src/lib/services/cps-dialog/utils/cps-dialog-config.ts Convert config to interface and add CPS_DIALOG_CONFIG InjectionToken.
projects/cps-ui-kit/src/lib/services/cps-dialog/internal/components/cps-dialog/cps-dialog.component.ts Inject config via @Inject(CPS_DIALOG_CONFIG) instead of class token.
projects/cps-ui-kit/src/lib/services/cps-dialog/internal/components/cps-dialog/cps-dialog.component.spec.ts Update test providers/config creation to use token + plain object.
projects/cps-ui-kit/src/lib/services/cps-dialog/internal/components/cps-confirmation/cps-confirmation.component.ts Inject config via token in confirmation dialog component.
projects/cps-ui-kit/src/lib/services/cps-dialog/internal/components/cps-confirmation/cps-confirmation.component.spec.ts Update confirmation test provider to use token.
projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.ts Provide config via CPS_DIALOG_CONFIG when creating dialog component.
projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.spec.ts Update service tests to pass plain config objects (no class instantiation).
projects/cps-ui-kit/src/lib/components/cps-radio-group/cps-radio-group.component.ts Add @group Tokens metadata for CPS_RADIO_GROUP docs rendering.
projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts Add @group Tokens metadata for ICONS_PATH docs rendering.
projects/composition/src/app/pipes/detect-type.pipe.ts Replace generic-regex linking with identifier scanning for nested/union types.
projects/composition/src/app/components/shared/api-type/api-type.component.scss Adjust spacing so union separators render cleanly with new segmentation.
projects/composition/src/app/components/service-docs-viewer/service-docs-viewer.component.html Render “Tokens” section for services when present.
projects/composition/src/app/components/dialog-content/dialog-content.component.ts Inject dialog config using CPS_DIALOG_CONFIG in composition example.
projects/composition/src/app/components/component-docs-viewer/component-docs-viewer.component.ts Extend component viewer model to accept tokens data.
projects/composition/src/app/components/component-docs-viewer/component-docs-viewer.component.html Render “Tokens” section for components when present.
projects/composition/src/app/api-data/types_map.json Expand typesMap entries to include more components/services for deep links.
projects/composition/src/app/api-data/cps-radio-group.json Add generated token docs block for radio group page.
projects/composition/src/app/api-data/cps-icon.json Add generated token docs block for icon page.
projects/composition/src/app/api-data/cps-dialog.json Add generated token docs block for dialog page.
projects/composition/src/app/api-data/cps-cron-validation.json Normalize token description text to shared “component or service” wording.
api-generator/api-generator.js Add tokens static message and route-aware service linkability for typesMap.
.github/workflows/check_pr_title_cc.yml Run PR title check workflow on next-major as well as master.

Comment thread projects/cps-ui-kit/src/lib/services/cps-dialog/cps-dialog.service.ts Outdated
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Playwright test results

passed  112 passed

Details

stats  112 tests across 4 suites
duration  3 minutes, 15 seconds
commit  d2c5cfe
info  For details, download the Playwright report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace CpsDialogConfig class with interface + InjectionToken to reduce bundle size

2 participants