This document details the Zastrozzi CDP Common Library. This library provides shared functionality and state management features used throughout our project. It leverages NgRx for managing common state (via actions, effects, reducers, selectors, and facades), exposes shared models and enums, and includes utility features such as the Utility Dock for presenting overlay panels.
The Zastrozzi CDP Common Library provides core building blocks that are shared across the application. These include:
This library is intended for integration with other modules in our project, ensuring a consistent foundation for shared functionality.
A high-level overview of the CDP Common library layout (located in /packages/cdp/common):
.eslintrc.json, jest.config.ts, ng-package.json, package.json, project.jsontsconfig.json, tsconfig.lib.json, tsconfig.lib.prod.json, tsconfig.spec.jsonindex.ts – Re-exports the module and public APIs.test-setup.ts – Jest test configuration.identifiers.ts – Defines namespaced keys such as CDPCommon and UTILITY_DOCK_STATE_FEATURE_KEY.CDPCommonUtilityDockFacade.state.ts and index.ts – Aggregate and re-export the state pieces.utility-dock.panel-type which define available panel types.forRoot() method.CDP_COMMON_ACTION_IDENTIFIER – A prefix for CDP Common actions.UTILITY_DOCK_STATE_FEATURE_KEY – The state key used for the Utility Dock.The CDP Common library includes actions for managing the Utility Dock, found in utility-dock.actions.ts:
{ panelType: Model.UtilityDockPanelType }{ panelType: Model.UtilityDockPanelType }{ panelType: Model.UtilityDockPanelType }switchMap, map, catchError) to process actions and dispatch further updates based on side effects.createReducer and on to update state immutably.Facades encapsulate NgRx interactions and expose a clean API. The main facade in this library is the CDPCommonUtilityDockFacade.
utilityDockPanels$: Emits all utility dock panels from state.anyUtilityDockPanelIsExpanded$: Indicates if any dock panel is currently expanded.utilityDockPanelById$(id: string): Returns an observable for a specific dock panel by id.utilityDockPanel$(panelType: Model.UtilityDockPanelType): Streams the state of a specific dock panel based on its type.utilityDockPanelIsExpanded$(panelType: Model.UtilityDockPanelType): Emits the expansion state for a given panel type.openUtilityDockPanel(panelType: Model.UtilityDockPanelType): voidopenUtilityDockPanel action to open the dock panel.closeUtilityDockPanel(panelType: Model.UtilityDockPanelType): voidcloseUtilityDockPanel action to close the dock panel.toggleUtilityDockPanel(panelType: Model.UtilityDockPanelType): voidtoggleUtilityDockPanel action to toggle the state.addUtilityDockPanelOverlay(panelType: Model.UtilityDockPanelType): booleanremoveUtilityDockPanelOverlay(panelType: Model.UtilityDockPanelType): voidgetUtilityDockPanelOverlay(panelType: Model.UtilityDockPanelType): Nullable<Model.UtilityDockPanelOverlayRef<any>>Note: The facade uses Angular’s dependency injection to access the Store and Overlay services, enabling it to dispatch actions and manage UI overlays.
model/ folder, these include:
model/enums folder (e.g. utility-dock.panel-type.ts), which define available panel types for the Utility Dock. nx build cdp.common
nx test cdp.common
import { CDPCommonModule } from '@zwp/cdp.common';
@NgModule({
imports: [CDPCommonModule.forRoot()]
})
export class AppModule {}
import { Component } from '@angular/core';
import { CDPCommonUtilityDockFacade } from '@zwp/cdp.common';
@Component({
selector: 'app-utility-dock-demo',
template: `
<button (click)="openDock()">Open Utility Dock</button>
`
})
export class UtilityDockDemoComponent {
constructor(private utilityDockFacade: CDPCommonUtilityDockFacade) {}
openDock() {
this.utilityDockFacade.openUtilityDockPanel('SomePanelType' as any);
}
}
The Zastrozzi CDP Common Library provides a robust, shared foundation for common functionality across our project. With comprehensive NgRx state management for features like the Utility Dock, well-organized models and enums, and a high-level facade to simplify UI integrations, this library creates a consistent, maintainable architecture for shared application features.