Skip to content

Commit

Permalink
Add logs navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
teodor-ritense committed Nov 14, 2024
1 parent 360051b commit 49f073a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ export class CarbonListComponent implements OnInit, AfterViewInit, OnDestroy {
}

@Input() set items(value: CarbonListItem[]) {
console.log('items', value);
this._items$.next(value);
}

public currentOpenActionId: string | null = null;

private readonly _fields$ = new BehaviorSubject<ColumnConfig[]>([]);
@Input() set fields(value: ColumnConfig[]) {
console.log('fields', value);
this._fields$.next(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {CommonModule} from '@angular/common';
import {ChangeDetectionStrategy, ChangeDetectorRef, Component} from '@angular/core';
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy} from '@angular/core';
import {CarbonListModule, ColumnConfig, ViewType} from '@valtimo/components';
import {CaseChangeLogsService} from '../../services';
import {Observable, map} from 'rxjs';
import {Observable, combineLatest, map} from 'rxjs';
import {CaseChangeLog} from '../../models';

@Component({
Expand All @@ -13,15 +13,19 @@ import {CaseChangeLog} from '../../models';
standalone: true,
imports: [CommonModule, CarbonListModule],
})
export class DossierManagementChangeLogsComponent {
export class DossierManagementChangeLogsComponent implements OnDestroy {
public readonly caseChangeLogs$: Observable<(CaseChangeLog & {fullName: string})[] | null> =
this.caseChangeLogsService.caseChangeLogs$.pipe(
map((changeLogs: CaseChangeLog[] | null) =>
!!changeLogs
? changeLogs.map((changeLog: CaseChangeLog) => ({
...changeLog,
fullName: `${changeLog.user.firstName} ${changeLog.user.lastName}`,
}))
combineLatest([
this.caseChangeLogsService.activeLogSearch$,
this.caseChangeLogsService.caseChangeLogs$,
]).pipe(
map(([activeLogSearch, caseChangeLogs]) =>
!!caseChangeLogs
? this.mapLogs(
!!activeLogSearch
? caseChangeLogs.filter((log: CaseChangeLog) => log.user.id === activeLogSearch)
: caseChangeLogs
)
: null
)
);
Expand All @@ -44,4 +48,15 @@ export class DossierManagementChangeLogsComponent {
];

constructor(private readonly caseChangeLogsService: CaseChangeLogsService) {}

public ngOnDestroy(): void {
this.caseChangeLogsService.activeLogSearch$.next(null);
}

private mapLogs(logs: CaseChangeLog[]): (CaseChangeLog & {fullName: string})[] {
return logs.map((changeLog: CaseChangeLog) => ({
...changeLog,
fullName: `${changeLog.user.firstName} ${changeLog.user.lastName}`,
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<valtimo-carbon-list
hideToolbar="true"
[items]="collaborators$ | async"
[fields]="COLLABORATORS_FIELDS"
[fields]="collaboratorsFields$ | async"
[loading]="(collaborators$ | async) === null"
(rowClicked)="onRowClicked()"
(rowClicked)="onRowClicked($event)"
></valtimo-carbon-list>

<ng-template #goToLogs let-data="data">
<button cdsButton="ghost" (click)="onRowClicked(data.item)">Go to Changelogs</button>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
import {CommonModule} from '@angular/common';
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
TemplateRef,
ViewChild,
} from '@angular/core';
import {CarbonListModule, ColumnConfig, ViewType} from '@valtimo/components';
import {Observable, tap} from 'rxjs';
import {Collaborator} from '../../models';
import {BehaviorSubject, Observable, tap} from 'rxjs';
import {Collaborator, TabEnum} from '../../models';
import {CaseCollaboratorsService} from '../../services/case-collaborators.service';
import {ButtonModule} from 'carbon-components-angular';
import {CaseChangeLogsService, CaseMenuService, TabService} from '../../services';

@Component({
selector: 'valtimo-dossier-management-collaborators-list',
templateUrl: './dossier-management-collaborators-list.component.html',
styleUrl: './dossier-management-collaborators-list.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, CarbonListModule],
imports: [CommonModule, CarbonListModule, ButtonModule],
})
export class DossierManagementCollaboratorsListComponent {
export class DossierManagementCollaboratorsListComponent implements AfterViewInit {
@ViewChild('goToLogs') private _goToLogsTemplate: TemplateRef<any>;
public readonly collaborators$: Observable<Collaborator[] | null> =
this.caseCollaboratorsService.collaborators$;


public readonly COLLABORATORS_FIELDS: ColumnConfig[] = [
{
key: 'email',
label: 'User email',
viewType: ViewType.TEXT,
},
];
constructor(private readonly caseCollaboratorsService: CaseCollaboratorsService) {}
public readonly collaboratorsFields$ = new BehaviorSubject<ColumnConfig[]>([]);

public onRowClicked() {}
constructor(
private readonly caseCollaboratorsService: CaseCollaboratorsService,
private readonly caseChangeLogsService: CaseChangeLogsService,
private readonly caseMenuService: CaseMenuService,
private readonly tabService: TabService
) {}

public ngAfterViewInit(): void {
this.collaboratorsFields$.next([
{
key: 'email',
label: 'User email',
viewType: ViewType.TEXT,
},
{
key: 'fullName',
label: 'User name',
viewType: ViewType.TEXT,
},
{
key: '',
label: '',
viewType: ViewType.TEMPLATE,
template: this._goToLogsTemplate,
},
]);
}

public onRowClicked(collaborator: Collaborator) {
this.caseChangeLogsService.activeLogSearch$.next(collaborator.id);
this.caseMenuService.selectMenuItem(TabEnum.CASE_CHANGE_LOGS);
this.tabService.currentTab = TabEnum.CASE_CHANGE_LOGS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {CASE_CHANGE_LOGS} from '../mocks';
export class CaseChangeLogsService {
private readonly _caseChangeLogs$ = new BehaviorSubject<CaseChangeLog[]>(CASE_CHANGE_LOGS);

public readonly activeLogSearch$ = new BehaviorSubject<string | null>(null);

public readonly caseChangeLogs$: Observable<CaseChangeLog[] | null> = this._caseChangeLogs$.pipe(
debounceTime(2000),
debounceTime(1000),
startWith(null)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CaseCollaboratorsService {
private readonly _collaborators$ = new BehaviorSubject<NamedUser[]>(COLLABORATORS);

public readonly collaborators$: Observable<Collaborator[] | null> = this._collaborators$.pipe(
debounceTime(2000),
debounceTime(1000),
map((users: NamedUser[]) =>
users.map((user: NamedUser) => ({...user, fullName: `${user.firstName} ${user.lastName}`}))
),
Expand Down

0 comments on commit 49f073a

Please sign in to comment.