Skip to content

Commit

Permalink
refactor(Backoffice): ♻️ remove tableConfig$ BehaviorSubject, use sig…
Browse files Browse the repository at this point in the history
…nal instead
  • Loading branch information
juamber-rgs committed Jan 28, 2024
1 parent 7b533a9 commit 63548b6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -70,8 +70,7 @@ export class CertificateGroupListComponent implements OnInit, OnDestroy, EntityL
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<CertificateGroup> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<CertificateGroup> | undefined>(undefined);

action$ = this.store.select(certificateGroupReducer.getAction);

Expand Down Expand Up @@ -160,7 +159,7 @@ export class CertificateGroupListComponent implements OnInit, OnDestroy, EntityL
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<app-generic-table
[entities]="(entities$ | async)!"
[loading]="(loading$ | async)!"
[count]="(count$ | async)!"
[config]="(tableConfig$ | async)!"
[entities]="entities()"
[loading]="loading()"
[count]="count()"
[config]="tableConfig()!"
(lazyLoadEvent)="onLazyLoadEvent($event)"
(tableEvent)="onTableEvent($event)"
></app-generic-table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class CertificateTypeListComponent implements OnInit, OnDestroy, EntityLi
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<CertificateType> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<CertificateType> | undefined>(undefined);

action$ = this.store.select(certificateTypeReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class CertificateTypeListComponent implements OnInit, OnDestroy, EntityLi
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class CertificateListComponent implements OnInit, OnDestroy, EntityList<C
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<Certificate> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<Certificate> | undefined>(undefined);

action$ = this.store.select(certificateReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class CertificateListComponent implements OnInit, OnDestroy, EntityList<C
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class CompanyListComponent implements OnInit, OnDestroy, EntityList<Compa
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<Company> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<Company> | undefined>(undefined);

action$ = this.store.select(companyReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class CompanyListComponent implements OnInit, OnDestroy, EntityList<Compa
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Observable, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Observable, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class LanguageListComponent implements OnInit, OnDestroy, EntityList<Lang
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<Language> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<Language> | undefined>(undefined);

action$ = this.store.select(languageReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class LanguageListComponent implements OnInit, OnDestroy, EntityList<Lang
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class PositionListComponent implements OnInit, OnDestroy, EntityList<Posi
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<Position> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<Position> | undefined>(undefined);

action$ = this.store.select(positionReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class PositionListComponent implements OnInit, OnDestroy, EntityList<Posi
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { ResolveFn, Router } from '@angular/router';

import { TitleCasePipe } from '@angular/common';
Expand All @@ -7,7 +7,7 @@ import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -72,8 +72,7 @@ export class SkillTypeListComponent implements OnInit, OnDestroy, EntityList<Ski
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<SkillType> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<SkillType> | undefined>(undefined);

action$ = this.store.select(skillTypeReducer.getAction);

Expand Down Expand Up @@ -164,7 +163,7 @@ export class SkillTypeListComponent implements OnInit, OnDestroy, EntityList<Ski
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleCasePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResolveFn, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { Subject, filter, map, startWith, switchMap, takeUntil } from 'rxjs';
import { appRootTitle } from 'src/app/app.component';
import {
GenericFieldType,
Expand Down Expand Up @@ -71,8 +71,7 @@ export class SkillListComponent implements OnInit, OnDestroy, EntityList<Skill>
initialValue: 0,
});

tableConfig$ = new BehaviorSubject<GenericTableConfig<Skill> | undefined>(undefined);
tableConfig = toSignal(this.tableConfig$);
tableConfig = signal<GenericTableConfig<Skill> | undefined>(undefined);

action$ = this.store.select(skillReducer.getAction);

Expand Down Expand Up @@ -163,7 +162,7 @@ export class SkillListComponent implements OnInit, OnDestroy, EntityList<Skill>
optionButtons.push({ action: 'edit', icon: 'pi pi-pencil' });
optionButtons.push({ action: 'delete', icon: 'pi pi-trash' });

this.tableConfig$.next({
this.tableConfig.set({
...defaultGenericTableConfig,
title: this.titleCasePipe.transform(
this.translateSrv.instant(`tables.${this.names.name(Naming.CAMEL_CASE, NumberMode.SINGULAR)}.plural`),
Expand Down
3 changes: 1 addition & 2 deletions src/app/shared/models/entity-list.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Signal } from '@angular/core';
import { TableLazyLoadEvent } from 'primeng/table';
import { BehaviorSubject, Observable } from 'rxjs';
import { Observable } from 'rxjs';
import { GenericTableConfig, TableEvent } from 'src/app/shared/components/generic-table/models/generic-table.models';
import { CommonNames, Naming, NumberMode } from 'src/app/shared/state/common/common.names';
import { Action } from '../state/common/common-state';
Expand All @@ -16,7 +16,6 @@ export interface EntityList<T extends Resource> {
count$: Observable<number>;
count: Signal<number>;

tableConfig$: BehaviorSubject<GenericTableConfig<T> | undefined>;
tableConfig: Signal<GenericTableConfig<T> | undefined>;

action$: Observable<Action | undefined>;
Expand Down

0 comments on commit 63548b6

Please sign in to comment.