From bbc9ea183f148a61d6ec05f5550e4cc3b30a90bb Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 29 Aug 2024 15:34:17 +0530 Subject: [PATCH 1/3] refactor: page registry providers for columns, tabs and routes --- .../dashboard/dashboard-routing.module.ts | 4 +- .../pages/dashboard/dashboard.component.ts | 20 ++-- .../timesheet/layout/layout.component.ts | 14 +-- .../timesheet/timesheet-routing.module.ts | 3 +- .../job-employee/job-employee.component.ts | 96 +++++++++---------- .../lib/common/component-registry.types.ts | 41 +++----- .../page-data-table-registry.service.ts | 50 +++++----- .../page-data-table-registry.types.ts | 49 ++++++++-- .../page/page-route-registry.service.ts | 8 +- .../page/page-route-registry.types.ts | 23 ++++- .../page/page-tab-registry.service.ts | 29 +++--- .../services/page/page-tab-registry.types.ts | 31 +++++- .../dynamic-tabs/dynamic-tabs.component.ts | 8 +- 13 files changed, 213 insertions(+), 163 deletions(-) diff --git a/apps/gauzy/src/app/pages/dashboard/dashboard-routing.module.ts b/apps/gauzy/src/app/pages/dashboard/dashboard-routing.module.ts index f0cb4df902b..ba0eafe635b 100644 --- a/apps/gauzy/src/app/pages/dashboard/dashboard-routing.module.ts +++ b/apps/gauzy/src/app/pages/dashboard/dashboard-routing.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -import { PermissionsGuard, TabsetRegistryIdEnum } from '@gauzy/ui-core/core'; +import { PermissionsGuard } from '@gauzy/ui-core/core'; import { PermissionsEnum } from '@gauzy/contracts'; import { DateRangePickerResolver } from '@gauzy/ui-core/shared'; import { DashboardComponent } from './dashboard.component'; @@ -14,7 +14,7 @@ const routes: Routes = [ { path: '', component: DashboardComponent, - data: { tabsetId: TabsetRegistryIdEnum.Dashboard }, + data: { tabsetId: 'dashboard' }, children: [ { path: '', diff --git a/apps/gauzy/src/app/pages/dashboard/dashboard.component.ts b/apps/gauzy/src/app/pages/dashboard/dashboard.component.ts index 84fc0a22dd3..9f5023499ae 100644 --- a/apps/gauzy/src/app/pages/dashboard/dashboard.component.ts +++ b/apps/gauzy/src/app/pages/dashboard/dashboard.component.ts @@ -5,7 +5,7 @@ import { NbRouteTab } from '@nebular/theme'; import { TranslateService } from '@ngx-translate/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { ISelectedEmployee, PermissionsEnum } from '@gauzy/contracts'; -import { PageTabRegistryService, Store, TabsetRegistryId, TabsetRegistryIdEnum } from '@gauzy/ui-core/core'; +import { PageTabRegistryService, Store, PageTabsetRegistryId } from '@gauzy/ui-core/core'; import { TranslationBaseComponent } from '@gauzy/ui-core/i18n'; import { DynamicTabsComponent } from '@gauzy/ui-core/shared'; @@ -16,7 +16,7 @@ import { DynamicTabsComponent } from '@gauzy/ui-core/shared'; }) export class DashboardComponent extends TranslationBaseComponent implements AfterContentChecked, OnInit, OnDestroy { public tabs: NbRouteTab[] = []; - public tabsetId: TabsetRegistryId = this._route.snapshot.data.tabsetId; // The identifier for the tabset + public tabsetId: PageTabsetRegistryId = this._route.snapshot.data.tabsetId; // The identifier for the tabset public selectedEmployee: ISelectedEmployee; @ViewChild('dynamicTabs') dynamicTabsComponent!: DynamicTabsComponent; @@ -72,7 +72,7 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte if (this._store.hasAnyPermission(PermissionsEnum.ADMIN_DASHBOARD_VIEW, PermissionsEnum.TEAM_DASHBOARD)) { // Register the teams tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Dashboard, // The identifier for the tabset + tabsetId: 'dashboard', // The identifier for the tabset tabId: 'teams', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: this.getRoute('teams'), // The route for the tab @@ -93,7 +93,7 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte ) { // Register the project management tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Dashboard, // The identifier for the tabset + tabsetId: 'dashboard', // The identifier for the tabset tabId: 'project-management', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: this.getRoute('project-management'), // The route for the tab @@ -111,7 +111,7 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte ) { // Register the time tracking tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Dashboard, // The identifier for the tabset + tabsetId: 'dashboard', // The identifier for the tabset tabId: 'time-tracking', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: this.getRoute('time-tracking'), // The route for the tab @@ -130,15 +130,15 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte */ registerAccountingTabs(): void { // Remove the specified page tabs for the current tenant - this._pageTabRegistryService.removePageTab(TabsetRegistryIdEnum.Dashboard, 'accounting'); - this._pageTabRegistryService.removePageTab(TabsetRegistryIdEnum.Dashboard, 'hr'); + this._pageTabRegistryService.removePageTab('dashboard', 'accounting'); + this._pageTabRegistryService.removePageTab('dashboard', 'hr'); // Check if the user has permission to view accounting if (this._store.hasAnyPermission(PermissionsEnum.ADMIN_DASHBOARD_VIEW, PermissionsEnum.ACCOUNTING_DASHBOARD)) { if (!this.selectedEmployee || !this.selectedEmployee.id) { // Register the accounting tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Dashboard, // The identifier for the tabset + tabsetId: 'dashboard', // The identifier for the tabset tabId: 'accounting', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: this.getRoute('accounting'), // The route for the tab @@ -161,7 +161,7 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte if (this.selectedEmployee && this.selectedEmployee.id) { // Register the human resources tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Dashboard, // The identifier for the tabset + tabsetId: 'dashboard', // The identifier for the tabset tabId: 'hr', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: this.getRoute('hr'), // The route for the tab @@ -183,6 +183,6 @@ export class DashboardComponent extends TranslationBaseComponent implements Afte */ ngOnDestroy() { // Delete the dashboard tabset from the registry - this._pageTabRegistryService.deleteTabset(TabsetRegistryIdEnum.Dashboard); + this._pageTabRegistryService.deleteTabset('dashboard'); } } diff --git a/apps/gauzy/src/app/pages/employees/timesheet/layout/layout.component.ts b/apps/gauzy/src/app/pages/employees/timesheet/layout/layout.component.ts index 841dd087dbc..20183f89c25 100644 --- a/apps/gauzy/src/app/pages/employees/timesheet/layout/layout.component.ts +++ b/apps/gauzy/src/app/pages/employees/timesheet/layout/layout.component.ts @@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router'; import { NbRouteTab } from '@nebular/theme'; import { TranslateService } from '@ngx-translate/core'; import { PermissionsEnum } from '@gauzy/contracts'; -import { PageTabRegistryService, Store, TabsetRegistryId, TabsetRegistryIdEnum } from '@gauzy/ui-core/core'; +import { PageTabRegistryService, Store, PageTabsetRegistryId } from '@gauzy/ui-core/core'; import { TranslationBaseComponent } from '@gauzy/ui-core/i18n'; @Component({ @@ -13,7 +13,7 @@ import { TranslationBaseComponent } from '@gauzy/ui-core/i18n'; }) export class TimesheetLayoutComponent extends TranslationBaseComponent implements OnInit, OnDestroy { public tabs: NbRouteTab[] = []; - public tabsetId: TabsetRegistryId = this._route.snapshot.data.tabsetId; // The identifier for the tabset + public tabsetId: PageTabsetRegistryId = this._route.snapshot.data.tabsetId; // The identifier for the tabset constructor( public readonly translateService: TranslateService, @@ -47,7 +47,7 @@ export class TimesheetLayoutComponent extends TranslationBaseComponent implement if (this._store.hasAnyPermission(...permissions)) { // Register the daily timesheet tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Timesheet, // The identifier for the tabset + tabsetId: 'timesheet', // The identifier for the tabset tabId: 'daily', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: '/pages/employees/timesheets/daily', // The route for the tab @@ -59,7 +59,7 @@ export class TimesheetLayoutComponent extends TranslationBaseComponent implement // Register the weekly timesheet tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Timesheet, // The identifier for the tabset + tabsetId: 'timesheet', // The identifier for the tabset tabId: 'weekly', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: '/pages/employees/timesheets/weekly', // The route for the tab @@ -71,7 +71,7 @@ export class TimesheetLayoutComponent extends TranslationBaseComponent implement // Register the calendar timesheet tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Timesheet, // The identifier for the tabset + tabsetId: 'timesheet', // The identifier for the tabset tabId: 'calendar', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: '/pages/employees/timesheets/calendar', // The route for the tab @@ -86,7 +86,7 @@ export class TimesheetLayoutComponent extends TranslationBaseComponent implement if (this._store.hasPermission(PermissionsEnum.CAN_APPROVE_TIMESHEET)) { // Register the approvals tab this._pageTabRegistryService.registerPageTab({ - tabsetId: TabsetRegistryIdEnum.Timesheet, // The identifier for the tabset + tabsetId: 'timesheet', // The identifier for the tabset tabId: 'approvals', // The identifier for the tab tabsetType: 'route', // The type of tabset to use route: '/pages/employees/timesheets/approvals', // The route for the tab @@ -100,6 +100,6 @@ export class TimesheetLayoutComponent extends TranslationBaseComponent implement ngOnDestroy(): void { // Delete the timesheet tabset from the registry - this._pageTabRegistryService.deleteTabset(TabsetRegistryIdEnum.Timesheet); + this._pageTabRegistryService.deleteTabset('timesheet'); } } diff --git a/apps/gauzy/src/app/pages/employees/timesheet/timesheet-routing.module.ts b/apps/gauzy/src/app/pages/employees/timesheet/timesheet-routing.module.ts index 698e3c3fe52..8c9892246b2 100644 --- a/apps/gauzy/src/app/pages/employees/timesheet/timesheet-routing.module.ts +++ b/apps/gauzy/src/app/pages/employees/timesheet/timesheet-routing.module.ts @@ -1,13 +1,12 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -import { TabsetRegistryIdEnum } from '@gauzy/ui-core/core'; import { TimesheetLayoutComponent } from './layout/layout.component'; const routes: Routes = [ { path: '', component: TimesheetLayoutComponent, - data: { tabsetId: TabsetRegistryIdEnum.Timesheet }, + data: { tabsetId: 'timesheet' }, children: [ { path: '', diff --git a/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts b/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts index 0b163fcc501..05d0df8028f 100644 --- a/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts +++ b/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts @@ -143,14 +143,14 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen registerDataTableColumns(_pageDataTableRegistryService: PageDataTableRegistryService): void { // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'name', - order: 0, - title: 'JOB_EMPLOYEE.EMPLOYEE', - type: 'custom', - width: '20%', - isSortable: true, - isEditable: true, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'name', // The identifier for the column + order: 0, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.EMPLOYEE'), // The title of the column + type: 'custom', // The type of the column + width: '20%', // The width of the column + isSortable: true, // Indicates whether the column is sortable + isEditable: true, // Indicates whether the column is editable renderComponent: EmployeeLinksComponent, valuePrepareFunction: (_: any, cell: Cell) => this.prepareEmployeeValue(_, cell), componentInitFunction: (instance: EmployeeLinksComponent, cell: Cell) => { @@ -163,40 +163,40 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'availableJobs', - order: 1, - title: 'JOB_EMPLOYEE.AVAILABLE_JOBS', - type: 'text', - width: '10%', - isSortable: false, - isEditable: false, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'availableJobs', // The identifier for the column + order: 1, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.AVAILABLE_JOBS'), // The title of the column + type: 'text', // The type of the column + width: '10%', // The width of the column + isSortable: false, // Indicates whether the column is sortable + isEditable: false, // Indicates whether the column is editable valuePrepareFunction: (rawValue: any) => rawValue || 0 }); // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'appliedJobs', - order: 2, - title: 'JOB_EMPLOYEE.APPLIED_JOBS', - type: 'text', - width: '10%', - isSortable: false, - isEditable: false, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'appliedJobs', // The identifier for the column + order: 2, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.APPLIED_JOBS'), // The title of the column + type: 'text', // The type of the column + width: '10%', // The width of the column + isSortable: false, // Indicates whether the column is sortable + isEditable: false, // Indicates whether the column is editable valuePrepareFunction: (rawValue: any) => rawValue || 0 }); // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'billRateValue', - order: 3, - title: 'JOB_EMPLOYEE.BILLING_RATE', - type: 'text', - width: '10%', - isSortable: false, - isEditable: true, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'billRateValue', // The identifier for the column + order: 3, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.BILLING_RATE'), // The title of the column + type: 'text', // The type of the column + width: '10%', // The width of the column + isSortable: false, // Indicates whether the column is sortable + isEditable: true, // Indicates whether the column is editable editor: { type: 'custom', component: NumberEditorComponent @@ -211,14 +211,14 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'minimumBillingRate', - order: 4, - title: 'JOB_EMPLOYEE.MINIMUM_BILLING_RATE', - type: 'text', - width: '20%', - isSortable: false, - isEditable: true, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'minimumBillingRate', // The identifier for the column + order: 4, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.MINIMUM_BILLING_RATE'), // The title of the column + type: 'text', // The type of the column + width: '20%', // The width of the column + isSortable: false, // Indicates whether the column is sortable + isEditable: true, // Indicates whether the column is editable editor: { type: 'custom', component: NumberEditorComponent @@ -231,14 +231,14 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - location: 'job-employee', - columnId: 'isJobSearchActive', - order: 5, - title: 'JOB_EMPLOYEE.JOB_SEARCH_STATUS', - type: 'custom', - width: '20%', - isSortable: false, - isEditable: false, + datatableId: 'job-employee', // The identifier for the data table location + columnId: 'isJobSearchActive', // The identifier for the column + order: 5, // The order of the column in the table + title: () => this.getTranslation('JOB_EMPLOYEE.JOB_SEARCH_STATUS'), // The title of the column + type: 'custom', // The type of the column + width: '20%', // The width of the column + isSortable: false, // Indicates whether the column is sortable + isEditable: false, // Indicates whether the column is editable renderComponent: SmartTableToggleComponent, componentInitFunction: (instance: SmartTableToggleComponent, cell: Cell) => { // Get the employee data from the cell diff --git a/packages/ui-core/core/src/lib/common/component-registry.types.ts b/packages/ui-core/core/src/lib/common/component-registry.types.ts index 6580da4301f..debaf7e29d6 100644 --- a/packages/ui-core/core/src/lib/common/component-registry.types.ts +++ b/packages/ui-core/core/src/lib/common/component-registry.types.ts @@ -14,13 +14,9 @@ */ export type ComponentRegistryLocationId = 'table' | 'tab' | 'route'; -// Define sub-page types for 'jobs', 'employees' and 'sales' -export type JobsSubPageLocationRegistryId = 'job-employee'; -export type SalesSubPageLocationRegistryId = 'proposals'; - /** * @description - * Type representing the possible page locations for dynamic routes, tabs, and table columns. + * Type representing the possible page locations for dynamic routes. * * This type is used to identify different sections of the application where dynamic * routes and tabs can be registered. Each value corresponds to a specific page or @@ -32,16 +28,10 @@ export type SalesSubPageLocationRegistryId = 'proposals'; * - 'pages': The main pages section of the application. * - 'dashboard': The main dashboard page of the application. * - 'jobs': The jobs or job search section of the application. - * - 'job-employee': A sub-page under the jobs section. + * - 'sales': The sales or proposals section of the application. + * - 'proposals': A sub-page under the sales section. */ -export type PageLocationRegistryId = - | 'auth' - | 'pages' - | 'dashboard' - | 'jobs' - | JobsSubPageLocationRegistryId - | 'sales' - | SalesSubPageLocationRegistryId; +export type PageRouteRegistryId = 'auth' | 'pages' | 'dashboard' | 'jobs' | 'sales' | 'proposals'; /** * @description @@ -56,21 +46,18 @@ export type PageLocationRegistryId = * - 'timesheet': A timesheet tab. * - 'time-activity': A time and activity tab. */ -export type TabsetRegistryId = 'timesheet' | 'time-activity' | 'dashboard'; +export type PageTabsetRegistryId = 'dashboard' | 'timesheet' | 'time-activity'; /** - * Enum representing the possible dynamic tabs for pages. + * @description + * Type representing the possible page data table locations for dynamic table columns. * - * This enum is used to identify different types of tabs that can be registered - * for dynamic pages. Each value corresponds to a specific - * tab type in the application. This allows for flexible and dynamic registration - * based on the context and requirements of the application. + * This type is used to identify different sections of the application where dynamic + * columns can be registered. Each value corresponds to a specific page or + * section in the application. This allows for flexible and dynamic routing based + * on the context and requirements of the application. * - * @readonly - * @enum {string} + * Possible values: + * - 'job-employee': A sub-page under the jobs section. */ -export enum TabsetRegistryIdEnum { - Timesheet = 'timesheet', // The identifier for the timesheet tabset - TimeActivity = 'time-activity', // The identifier for the time and activity tabset - Dashboard = 'dashboard' // The identifier for the dashboard tabset -} +export type PageDataTableRegistryId = 'job-employee'; diff --git a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts b/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts index 0cd06dd561b..5b2c30eca57 100644 --- a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts +++ b/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts @@ -1,8 +1,10 @@ import { Injectable } from '@angular/core'; import { Cell, IColumn, IColumns } from 'angular2-smart-table'; -import { I18nService } from '@gauzy/ui-core/i18n'; -import { PageLocationRegistryId } from '../../../common/component-registry.types'; -import { IPageDataTableRegistry, PageDataTableRegistryConfig } from './page-data-table-registry.types'; +import { + IPageDataTableRegistry, + PageDataTableLocationRegistryId, + PageDataTableRegistryConfig +} from './page-data-table-registry.types'; @Injectable({ providedIn: 'root' @@ -11,11 +13,9 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { /** * Registry for storing page data table column configurations. * - * This Map stores arrays of PageDataTableRegistryConfig objects, keyed by PageLocationRegistryId. + * This Map stores arrays of PageDataTableRegistryConfig objects, keyed by PageDataTableLocationRegistryId. */ - private readonly registry = new Map(); - - constructor(readonly _i18nService: I18nService) {} + private readonly registry = new Map(); /** * Register a column configurations. @@ -29,20 +29,16 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * @throws Will throw an error if a column with the same location and id has already been registered. */ public registerPageDataTableColumn(config: PageDataTableRegistryConfig): void { - if (!config.location) { - throw new Error('Page data table column configuration must have a location property'); + if (!config.datatableId) { + throw new Error('A data table column configuration must have a datatableId property'); } - // Set the isTranslatable flag to false by default - config.isTranslatable = config.isTranslatable ?? true; - // Get all registered columns for the specified location - const columns = this.registry.get(config.location) || []; + const columns = this.registry.get(config.datatableId) || []; // Find the index of the column with the same location and columnId const existing = columns.findIndex( - (route: PageDataTableRegistryConfig) => - route.location === config.location && route.columnId === config.columnId + (column: PageDataTableRegistryConfig) => column.datatableId === config.datatableId && column.columnId === config.columnId ); if (existing !== -1) { @@ -54,7 +50,7 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { } // Update the registry with the new list of columns for the specified location - this.registry.set(config.location, columns); + this.registry.set(config.datatableId, columns); } /** @@ -76,20 +72,20 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * Retrieves the data table column configurations associated with a specific registry ID. * * This method fetches an array of `PageDataTableRegistryConfig` objects that are associated with the provided - * `PageLocationRegistryId`. If any configurations are found, they are sorted based on their `order` property in + * `PageDataTableLocationRegistryId`. If any configurations are found, they are sorted based on their `order` property in * ascending order. If no configurations are found, an empty array is returned. * * @param location - The identifier used to look up the data table column configurations. * @returns An array of `PageDataTableRegistryConfig` objects sorted by the `order` property, or an empty array if none are found. */ - private getDataTableColumnsByOrder(location: PageLocationRegistryId): PageDataTableRegistryConfig[] { + private getDataTableColumnsByOrder(location: PageDataTableLocationRegistryId): PageDataTableRegistryConfig[] { return this.registry.get(location)?.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)) || []; } /** * Retrieves a list of unique columns for a specific page location, based on the provided location. * - * This method fetches all registered data table columns for the specified `PageLocationRegistryId`, + * This method fetches all registered data table columns for the specified `PageDataTableLocationRegistryId`, * removes any duplicate columns based on their location and ID, and maps the remaining configurations * to an array of `IColumn` objects. * @@ -100,25 +96,25 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * @param registryId - The identifier used to look up the data table column configurations for a specific page location. * @returns An array of `IColumn` objects representing the unique columns for the specified page location. */ - public getPageDataTableColumns(location: PageLocationRegistryId): IColumns { + public getPageDataTableColumns(datatableId: PageDataTableLocationRegistryId): IColumns { // Get all registered columns for the specified location - let columns = this.getDataTableColumnsByOrder(location); + let columns = this.getDataTableColumnsByOrder(datatableId); // Use a Set to track unique location-id combinations - const locationIds = new Set(); + const datatableIds = new Set(); // Filter the configurations to remove duplicates based on the unique identifier columns = columns.filter((config: PageDataTableRegistryConfig) => { // Create a unique identifier for the combination of location and id - const identifier = `${config.location}-${config.columnId}`; + const identifier = `${config.datatableId}-${config.columnId}`; // Check if the unique identifier is already in the Set - if (locationIds.has(identifier)) { + if (datatableIds.has(identifier)) { return false; // Duplicate found, filter it out } // Add the unique identifier to the Set - locationIds.add(identifier); + datatableIds.add(identifier); return true; // Not a duplicate, keep it }); @@ -126,7 +122,9 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { return columns.reduce((acc: IColumns, config: PageDataTableRegistryConfig) => { // Create and return a new IColumn object const column: IColumn = { - title: config.isTranslatable ? this._i18nService.getTranslation(config.title) : config.title, + ...(config.title && { + title: typeof config.title === 'function' ? config.title() : config.title + }), type: config.type, width: config.width, isSortable: config.isSortable ?? false, diff --git a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts b/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts index a551b1c3e79..9298f6edabe 100644 --- a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts +++ b/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts @@ -1,27 +1,40 @@ import { IColumn } from 'angular2-smart-table'; -import { PageLocationRegistryId } from '../../../common/component-registry.types'; + +/** + * @description + * Type representing the possible page data table locations for dynamic table columns. + * + * This type is used to identify different sections of the application where dynamic + * columns can be registered. Each value corresponds to a specific page or + * section in the application. This allows for flexible and dynamic routing based + * on the context and requirements of the application. + * + * Possible values: + * - 'job-employee': A sub-page under the jobs section. + */ +export type PageDataTableLocationRegistryId = 'job-employee'; /** * Page route configuration with additional table columns options. */ -export interface PageDataTableRegistryConfig extends IColumn { +export interface PageDataTableRegistryConfig extends Omit { /** * @description * The location identifier for the page route. */ - location: PageLocationRegistryId; + datatableId: PageDataTableLocationRegistryId; /** * @description - * The translatable key for the column title. + * The column identifier for the column. This is used to identify the column in the table for specific page location. */ - isTranslatable?: boolean; + columnId: string; /** * @description - * The column identifier for the column. This is used to identify the column in the table for specific page location. + * The translatable key for the tab title. */ - columnId: string; + title?: string | (() => string); /** * @description @@ -41,6 +54,24 @@ export interface PageDataTableRegistryConfig extends IColumn { * Registry for page data table columns. */ export interface IPageDataTableRegistry { - registerPageDataTableColumn(config: PageDataTableRegistryConfig): void; // Register a column configuration. - registerPageDataTableColumns(configs: PageDataTableRegistryConfig[]): void; // Register multiple column configurations. + /** + * Register a column configuration. + * + * This method adds a single column configuration to the registry. If the column ID + * already exists, an error will be thrown, but the column will still be registered. + * + * @param config + */ + registerPageDataTableColumn(config: PageDataTableRegistryConfig): void; + + /** + * Register multiple column configurations. + * + * This method adds multiple column configurations to the registry. If any column + * within the provided configurations already exists, an error will be thrown for that + * specific column, but other columns will still be registered. + * + * @param configs An array of configuration objects for the columns to be registered. + */ + registerPageDataTableColumns(configs: PageDataTableRegistryConfig[]): void; } diff --git a/packages/ui-core/core/src/lib/services/page/page-route-registry.service.ts b/packages/ui-core/core/src/lib/services/page/page-route-registry.service.ts index 9ee53aa5624..92dbe5589f3 100644 --- a/packages/ui-core/core/src/lib/services/page/page-route-registry.service.ts +++ b/packages/ui-core/core/src/lib/services/page/page-route-registry.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { Route } from '@angular/router'; -import { PageLocationRegistryId } from '../../common/component-registry.types'; +import { PageRouteRegistryId } from '../../common/component-registry.types'; import { IPageRouteRegistry, PageRouteRegistryConfig } from './page-route-registry.types'; @Injectable({ @@ -10,9 +10,9 @@ export class PageRouteRegistryService implements IPageRouteRegistry { /** * Registry for storing page route configurations. * - * This Map stores arrays of PageRouteRegistryConfig objects, keyed by PageLocationRegistryId. + * This Map stores arrays of PageRouteRegistryConfig objects, keyed by PageRouteRegistryId. */ - private readonly registry = new Map(); + private readonly registry = new Map(); /** * Register a single page route configuration. @@ -78,7 +78,7 @@ export class PageRouteRegistryService implements IPageRouteRegistry { * @param location The page location identifier. * @returns The array of registered routes for the specified location. */ - getPageLocationRoutes(location: PageLocationRegistryId): Route[] { + getPageLocationRoutes(location: PageRouteRegistryId): Route[] { // Get all registered routes for the specified location let configs = this.registry.get(location) || []; diff --git a/packages/ui-core/core/src/lib/services/page/page-route-registry.types.ts b/packages/ui-core/core/src/lib/services/page/page-route-registry.types.ts index fd2265628ae..23c547e0c3c 100644 --- a/packages/ui-core/core/src/lib/services/page/page-route-registry.types.ts +++ b/packages/ui-core/core/src/lib/services/page/page-route-registry.types.ts @@ -1,6 +1,6 @@ import { Type } from '@angular/core'; import { Route } from '@angular/router'; -import { PageLocationRegistryId } from '../../common/component-registry.types'; +import { PageRouteRegistryId } from '../../common/component-registry.types'; /** * Page route configuration with additional route options. @@ -9,7 +9,7 @@ export interface PageRouteRegistryConfig extends Route { /** * The location identifier for the page route. */ - location: PageLocationRegistryId; + location: PageRouteRegistryId; /** * The path to navigate to when the page is selected. @@ -37,6 +37,21 @@ export interface PageRouteRegistryConfig extends Route { * Page registry service interface. */ export interface IPageRouteRegistry { - registerPageRoute(config: PageRouteRegistryConfig): void; // Register a single page route configuration. - registerPageRoutes(configs: PageRouteRegistryConfig[]): void; // Register multiple page route configurations. + /** + * Register a single page route configuration. + * + * This method is used to register a single page route configuration. + * + * @param config + */ + registerPageRoute(config: PageRouteRegistryConfig): void; + + /** + * Register multiple page route configurations. + * + * This method is used to register multiple page route configurations. + * + * @param configs + */ + registerPageRoutes(configs: PageRouteRegistryConfig[]): void; } diff --git a/packages/ui-core/core/src/lib/services/page/page-tab-registry.service.ts b/packages/ui-core/core/src/lib/services/page/page-tab-registry.service.ts index fead8566e5a..2d818d7bf3f 100644 --- a/packages/ui-core/core/src/lib/services/page/page-tab-registry.service.ts +++ b/packages/ui-core/core/src/lib/services/page/page-tab-registry.service.ts @@ -1,5 +1,5 @@ import { Injectable, Type } from '@angular/core'; -import { TabsetRegistryId } from '../../common/component-registry.types'; +import { PageTabsetRegistryId } from '../../common/component-registry.types'; import { IPageTabRegistry, PageTabRegistryConfig } from './page-tab-registry.types'; @Injectable({ @@ -9,21 +9,20 @@ export class PageTabRegistryService implements IPageTabRegistry { /** * Registry for storing page tab configurations. * - * This Map stores arrays of PageTabRegistryConfig objects, keyed by TabsetRegistryId. + * This Map stores arrays of PageTabRegistryConfig objects, keyed by PageTabsetRegistryId. */ - private readonly registry = new Map(); + private readonly registry = new Map(); /** * Retrieves the current tab registry. * - * This method returns the internal map that stores the page tab configurations, - * keyed by their tabset identifiers. + * This method returns a map of tab configurations, organized by their tabset identifiers. * - * @returns A Map where the keys are tabset identifiers and the values are arrays - * of page tab configurations associated with each tabset. + * @returns A `Map` where each key is a `PageTabsetRegistryId` and each value is an array of + * `PageTabRegistryConfig` objects associated with that tabset. */ - public getRegistry(): Map { - return this.registry; + public getRegistry(): ReadonlyMap { + return new Map(this.registry); // Return a new Map to ensure immutability } /** @@ -54,7 +53,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * @param config The configuration object representing the new tab to add. * @param tabsetId The identifier of the tab set to which the new tab should be added. */ - public addPageTab(config: PageTabRegistryConfig, tabsetId: TabsetRegistryId): void { + public addPageTab(config: PageTabRegistryConfig, tabsetId: PageTabsetRegistryId): void { // Check if the configuration has a location property if (!config.tabsetId) { throw new Error('Page tab configuration must have a tabsetId property'); @@ -94,7 +93,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * @param tabsetId The identifier of the tab set from which the tab should be removed. * @param tabId The identifier of the tab to remove. */ - public removePageTab(tabsetId: TabsetRegistryId, tabId: string): void { + public removePageTab(tabsetId: PageTabsetRegistryId, tabId: string): void { // Retrieve the list of tabs for the specified tabset, or initialize as an empty array if not found const tabs = this.registry.get(tabsetId) || []; @@ -141,7 +140,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * @param tabsetId The identifier for the tabset. * @returns An array of `PageTabRegistryConfig` objects, sorted by their `order` property. */ - private getPageTabsByOrder(tabsetId: TabsetRegistryId): PageTabRegistryConfig[] { + private getPageTabsByOrder(tabsetId: PageTabsetRegistryId): PageTabRegistryConfig[] { // Retrieve the tabs for the specified tabsetId from the registry const tabs = this.registry.get(tabsetId) || []; @@ -159,7 +158,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * @param tabsetId The identifier for the tabset whose tabs are to be retrieved. * @returns An array of unique page tabs for the specified tabset. */ - public getPageTabset(tabsetId: TabsetRegistryId): PageTabRegistryConfig[] { + public getPageTabset(tabsetId: PageTabsetRegistryId): PageTabRegistryConfig[] { // Get all registered tabs for the specified tabset, ordered as required const tabs = this.getPageTabsByOrder(tabsetId); @@ -186,7 +185,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * * @param tabsetId The identifier for the tabset to delete. */ - public deleteTabset(tabsetId: TabsetRegistryId): void { + public deleteTabset(tabsetId: PageTabsetRegistryId): void { // Check if the tabset exists in the registry if (!this.registry.has(tabsetId)) { console.warn(`Tabset with id "${tabsetId}" does not exist in the registry.`); @@ -210,7 +209,7 @@ export class PageTabRegistryService implements IPageTabRegistry { * @param tabId The identifier of the tab whose component is to be retrieved. * @returns The component associated with the specified tab ID, or `undefined` if the tab or component is not found. */ - public getComponentForTab(tabsetId: TabsetRegistryId, tabId: string): Type | undefined { + public getComponentForTab(tabsetId: PageTabsetRegistryId, tabId: string): Type | undefined { // Retrieve the list of tabs for the specified tabsetId const tabs = this.getPageTabset(tabsetId); diff --git a/packages/ui-core/core/src/lib/services/page/page-tab-registry.types.ts b/packages/ui-core/core/src/lib/services/page/page-tab-registry.types.ts index 6f8a59fe55b..a06a6ecc9ab 100644 --- a/packages/ui-core/core/src/lib/services/page/page-tab-registry.types.ts +++ b/packages/ui-core/core/src/lib/services/page/page-tab-registry.types.ts @@ -1,6 +1,6 @@ import { Type } from '@angular/core'; import { NbRouteTab } from '@nebular/theme'; -import { TabsetRegistryId } from '../../common/component-registry.types'; +import { PageTabsetRegistryId } from '../../common/component-registry.types'; /** * Page tab configuration options. @@ -10,7 +10,7 @@ export interface PageTabRegistryConfig extends NbRouteTab { * @description * The tabset identifier for the page tabset. */ - tabsetId: TabsetRegistryId; + tabsetId: PageTabsetRegistryId; /** * @description @@ -64,9 +64,30 @@ export interface PageTabRegistryConfig extends NbRouteTab { } /** - * Page registry service interface. + * Tab registry service interface. + * + * This interface defines the contract for services that manage tab registrations, + * including methods for registering single and multiple tabs. */ export interface IPageTabRegistry { - registerPageTab(config: PageTabRegistryConfig): void; // Register a single page tab configuration. - registerPageTabs(configs: PageTabRegistryConfig[]): void; // Register multiple page tab configurations. + /** + * Registers a single tab with the service. + * + * This method adds a single tab configuration to the registry. If the tab ID + * already exists, an error will be thrown, but the tab will still be registered. + * + * @param config The configuration object for the tab to be registered. + */ + registerPageTab(config: PageTabRegistryConfig): void; + + /** + * Registers multiple tabs with the service. + * + * This method adds multiple tab configurations to the registry. If any tab + * within the provided configurations already exists, an error will be thrown for that + * specific tab, but other tabs will still be registered. + * + * @param configs An array of configuration objects for the tabs to be registered. + */ + registerPageTabs(configs: PageTabRegistryConfig[]): void; } diff --git a/packages/ui-core/shared/src/lib/components/dynamic-tabs/dynamic-tabs.component.ts b/packages/ui-core/shared/src/lib/components/dynamic-tabs/dynamic-tabs.component.ts index 569e3e78b60..33106d93839 100644 --- a/packages/ui-core/shared/src/lib/components/dynamic-tabs/dynamic-tabs.component.ts +++ b/packages/ui-core/shared/src/lib/components/dynamic-tabs/dynamic-tabs.component.ts @@ -4,7 +4,7 @@ import { TranslateService } from '@ngx-translate/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { tap } from 'rxjs/operators'; import { Subject } from 'rxjs/internal/Subject'; -import { PageTabRegistryConfig, PageTabRegistryService, TabsetRegistryId } from '@gauzy/ui-core/core'; +import { PageTabRegistryConfig, PageTabRegistryService, PageTabsetRegistryId } from '@gauzy/ui-core/core'; @UntilDestroy() @Component({ @@ -17,7 +17,7 @@ export class DynamicTabsComponent implements OnInit, OnDestroy { public tabs: NbRouteTab[] = []; // Define the structure of tabs according to your needs public reload$ = new Subject(); // Subject to trigger reload of tabs - @Input() tabsetId!: TabsetRegistryId; + @Input() tabsetId!: PageTabsetRegistryId; /** * Determines if all tabs in the tabset have the tabsetType set to 'route'. @@ -80,7 +80,7 @@ export class DynamicTabsComponent implements OnInit, OnDestroy { * @param tabsetId The identifier for the tabset. * @returns An array of PageTabRegistryConfig objects for the specified tabset, excluding tabs with hide set to true. */ - private getRegisteredTabs(tabsetId: TabsetRegistryId): PageTabRegistryConfig[] { + private getRegisteredTabs(tabsetId: PageTabsetRegistryId): PageTabRegistryConfig[] { return this._pageTabRegistryService.getPageTabset(tabsetId).filter((tab: PageTabRegistryConfig) => !tab.hide); } @@ -96,7 +96,7 @@ export class DynamicTabsComponent implements OnInit, OnDestroy { * @param tabsetId The identifier for the tabset. * @returns An array of NbRouteTab objects representing the registered tabs. */ - getRegisteredNbTabs(tabsetId: TabsetRegistryId): NbRouteTab[] { + getRegisteredNbTabs(tabsetId: PageTabsetRegistryId): NbRouteTab[] { // Map each tab configuration to an NbRouteTab object return this.getRegisteredTabs(tabsetId).map((tab: PageTabRegistryConfig): NbRouteTab => { // Create a new route object From 4085a9aeb34d00a3794c3dee560142aa61b600e9 Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 29 Aug 2024 15:44:52 +0530 Subject: [PATCH 2/3] fix: data table registery service --- .../core/src/lib/services/page/index.ts | 8 +++---- .../page-data-table-registry.service.ts | 22 +++++++++---------- .../page-data-table-registry.types.ts | 17 ++------------ 3 files changed, 16 insertions(+), 31 deletions(-) rename packages/ui-core/core/src/lib/services/page/{data-table => }/page-data-table-registry.service.ts (88%) rename packages/ui-core/core/src/lib/services/page/{data-table => }/page-data-table-registry.types.ts (74%) diff --git a/packages/ui-core/core/src/lib/services/page/index.ts b/packages/ui-core/core/src/lib/services/page/index.ts index cf6909867eb..d6ad7858543 100644 --- a/packages/ui-core/core/src/lib/services/page/index.ts +++ b/packages/ui-core/core/src/lib/services/page/index.ts @@ -1,6 +1,6 @@ -export * from './data-table/page-data-table-registry.service'; -export * from './data-table/page-data-table-registry.types'; -export * from './page-route-registry.service'; -export * from './page-route-registry.types'; +export * from './page-data-table-registry.service'; +export * from './page-data-table-registry.types'; export * from './page-tab-registry.service'; export * from './page-tab-registry.types'; +export * from './page-route-registry.service'; +export * from './page-route-registry.types'; diff --git a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts similarity index 88% rename from packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts rename to packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts index 5b2c30eca57..ba74133cb8d 100644 --- a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.service.ts +++ b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts @@ -1,10 +1,7 @@ import { Injectable } from '@angular/core'; import { Cell, IColumn, IColumns } from 'angular2-smart-table'; -import { - IPageDataTableRegistry, - PageDataTableLocationRegistryId, - PageDataTableRegistryConfig -} from './page-data-table-registry.types'; +import { PageDataTableRegistryId } from '../../common/component-registry.types'; +import { IPageDataTableRegistry, PageDataTableRegistryConfig } from './page-data-table-registry.types'; @Injectable({ providedIn: 'root' @@ -13,9 +10,9 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { /** * Registry for storing page data table column configurations. * - * This Map stores arrays of PageDataTableRegistryConfig objects, keyed by PageDataTableLocationRegistryId. + * This Map stores arrays of PageDataTableRegistryConfig objects, keyed by PageDataTableRegistryId. */ - private readonly registry = new Map(); + private readonly registry = new Map(); /** * Register a column configurations. @@ -38,7 +35,8 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { // Find the index of the column with the same location and columnId const existing = columns.findIndex( - (column: PageDataTableRegistryConfig) => column.datatableId === config.datatableId && column.columnId === config.columnId + (column: PageDataTableRegistryConfig) => + column.datatableId === config.datatableId && column.columnId === config.columnId ); if (existing !== -1) { @@ -72,20 +70,20 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * Retrieves the data table column configurations associated with a specific registry ID. * * This method fetches an array of `PageDataTableRegistryConfig` objects that are associated with the provided - * `PageDataTableLocationRegistryId`. If any configurations are found, they are sorted based on their `order` property in + * `PageDataTableRegistryId`. If any configurations are found, they are sorted based on their `order` property in * ascending order. If no configurations are found, an empty array is returned. * * @param location - The identifier used to look up the data table column configurations. * @returns An array of `PageDataTableRegistryConfig` objects sorted by the `order` property, or an empty array if none are found. */ - private getDataTableColumnsByOrder(location: PageDataTableLocationRegistryId): PageDataTableRegistryConfig[] { + private getDataTableColumnsByOrder(location: PageDataTableRegistryId): PageDataTableRegistryConfig[] { return this.registry.get(location)?.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)) || []; } /** * Retrieves a list of unique columns for a specific page location, based on the provided location. * - * This method fetches all registered data table columns for the specified `PageDataTableLocationRegistryId`, + * This method fetches all registered data table columns for the specified `PageDataTableRegistryId`, * removes any duplicate columns based on their location and ID, and maps the remaining configurations * to an array of `IColumn` objects. * @@ -96,7 +94,7 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * @param registryId - The identifier used to look up the data table column configurations for a specific page location. * @returns An array of `IColumn` objects representing the unique columns for the specified page location. */ - public getPageDataTableColumns(datatableId: PageDataTableLocationRegistryId): IColumns { + public getPageDataTableColumns(datatableId: PageDataTableRegistryId): IColumns { // Get all registered columns for the specified location let columns = this.getDataTableColumnsByOrder(datatableId); diff --git a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts similarity index 74% rename from packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts rename to packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts index 9298f6edabe..2d9ee496174 100644 --- a/packages/ui-core/core/src/lib/services/page/data-table/page-data-table-registry.types.ts +++ b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts @@ -1,18 +1,5 @@ import { IColumn } from 'angular2-smart-table'; - -/** - * @description - * Type representing the possible page data table locations for dynamic table columns. - * - * This type is used to identify different sections of the application where dynamic - * columns can be registered. Each value corresponds to a specific page or - * section in the application. This allows for flexible and dynamic routing based - * on the context and requirements of the application. - * - * Possible values: - * - 'job-employee': A sub-page under the jobs section. - */ -export type PageDataTableLocationRegistryId = 'job-employee'; +import { PageDataTableRegistryId } from '../../common/component-registry.types'; /** * Page route configuration with additional table columns options. @@ -22,7 +9,7 @@ export interface PageDataTableRegistryConfig extends Omit { * @description * The location identifier for the page route. */ - datatableId: PageDataTableLocationRegistryId; + datatableId: PageDataTableRegistryId; /** * @description From 29a4b2daea2e270db9d0f5bfef88b3f26d39dfe3 Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Thu, 29 Aug 2024 15:52:24 +0530 Subject: [PATCH 3/3] fix(cspell): typo spelling :-) --- .../job-employee/job-employee.component.ts | 12 +++++----- .../page/page-data-table-registry.service.ts | 22 +++++++++---------- .../page/page-data-table-registry.types.ts | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts b/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts index 05d0df8028f..a36bbbe3509 100644 --- a/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts +++ b/packages/plugins/job-employee-ui/src/lib/components/job-employee/job-employee.component.ts @@ -143,7 +143,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen registerDataTableColumns(_pageDataTableRegistryService: PageDataTableRegistryService): void { // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'name', // The identifier for the column order: 0, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.EMPLOYEE'), // The title of the column @@ -163,7 +163,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'availableJobs', // The identifier for the column order: 1, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.AVAILABLE_JOBS'), // The title of the column @@ -176,7 +176,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'appliedJobs', // The identifier for the column order: 2, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.APPLIED_JOBS'), // The title of the column @@ -189,7 +189,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'billRateValue', // The identifier for the column order: 3, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.BILLING_RATE'), // The title of the column @@ -211,7 +211,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'minimumBillingRate', // The identifier for the column order: 4, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.MINIMUM_BILLING_RATE'), // The title of the column @@ -231,7 +231,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen // Register the data table column _pageDataTableRegistryService.registerPageDataTableColumn({ - datatableId: 'job-employee', // The identifier for the data table location + dataTableId: 'job-employee', // The identifier for the data table location columnId: 'isJobSearchActive', // The identifier for the column order: 5, // The order of the column in the table title: () => this.getTranslation('JOB_EMPLOYEE.JOB_SEARCH_STATUS'), // The title of the column diff --git a/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts index ba74133cb8d..3219f7a3b63 100644 --- a/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts +++ b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.service.ts @@ -26,17 +26,17 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * @throws Will throw an error if a column with the same location and id has already been registered. */ public registerPageDataTableColumn(config: PageDataTableRegistryConfig): void { - if (!config.datatableId) { - throw new Error('A data table column configuration must have a datatableId property'); + if (!config.dataTableId) { + throw new Error('A data table column configuration must have a dataTableId property'); } // Get all registered columns for the specified location - const columns = this.registry.get(config.datatableId) || []; + const columns = this.registry.get(config.dataTableId) || []; // Find the index of the column with the same location and columnId const existing = columns.findIndex( (column: PageDataTableRegistryConfig) => - column.datatableId === config.datatableId && column.columnId === config.columnId + column.dataTableId === config.dataTableId && column.columnId === config.columnId ); if (existing !== -1) { @@ -48,7 +48,7 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { } // Update the registry with the new list of columns for the specified location - this.registry.set(config.datatableId, columns); + this.registry.set(config.dataTableId, columns); } /** @@ -94,25 +94,25 @@ export class PageDataTableRegistryService implements IPageDataTableRegistry { * @param registryId - The identifier used to look up the data table column configurations for a specific page location. * @returns An array of `IColumn` objects representing the unique columns for the specified page location. */ - public getPageDataTableColumns(datatableId: PageDataTableRegistryId): IColumns { + public getPageDataTableColumns(dataTableId: PageDataTableRegistryId): IColumns { // Get all registered columns for the specified location - let columns = this.getDataTableColumnsByOrder(datatableId); + let columns = this.getDataTableColumnsByOrder(dataTableId); // Use a Set to track unique location-id combinations - const datatableIds = new Set(); + const dataTableIds = new Set(); // Filter the configurations to remove duplicates based on the unique identifier columns = columns.filter((config: PageDataTableRegistryConfig) => { // Create a unique identifier for the combination of location and id - const identifier = `${config.datatableId}-${config.columnId}`; + const identifier = `${config.dataTableId}-${config.columnId}`; // Check if the unique identifier is already in the Set - if (datatableIds.has(identifier)) { + if (dataTableIds.has(identifier)) { return false; // Duplicate found, filter it out } // Add the unique identifier to the Set - datatableIds.add(identifier); + dataTableIds.add(identifier); return true; // Not a duplicate, keep it }); diff --git a/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts index 2d9ee496174..84ae01fa308 100644 --- a/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts +++ b/packages/ui-core/core/src/lib/services/page/page-data-table-registry.types.ts @@ -9,7 +9,7 @@ export interface PageDataTableRegistryConfig extends Omit { * @description * The location identifier for the page route. */ - datatableId: PageDataTableRegistryId; + dataTableId: PageDataTableRegistryId; /** * @description