import { Component, OnInit } from '@angular/core'; import { ImpersonationService } from '@features/impersonation/impersonation.service'; import { ImpersonationLogRecord } from '@features/impersonation/impersonation.typing'; import { AdminClientService } from '@features/platform-admin/clients/admin-client.service'; import { DebounceFactory, PaginationOptions, TableDataFactory, TopLevelFilter, TopLevelFilterOption } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; @Component({ selector: 'gc-impersonation-log-table', templateUrl: './impersonation-log-table.component.html', styleUrls: ['./impersonation-log-table.component.scss'] }) export class ImpersonationLogTableComponent implements OnInit { tableDataFactory: TableDataFactory; clientOptions: TopLevelFilterOption[] = this.clients.map(client => { return { label: client.name, value: client.clientId }; }); topLevelFilters: TopLevelFilter[] = [ new TopLevelFilter( 'checkboxDropdown', 'clientId', [], this.i18n.translate( 'ADMIN:textAllClientsSelected', {}, 'All clients selected' ), { selectOptions: this.clientOptions, filterObjectName: this.i18n.translate( 'common:labelClient', {}, 'Client' ).toLowerCase(), filterObjectNamePlural: this.i18n.translate( 'common:textClients', {}, 'Clients' ).toLowerCase() } ), new TopLevelFilter( 'text', 'impersonatedUserName', '', this.i18n.translate( 'ADMIN:textSearchGrantManager', {}, 'Search for grant manager' ), undefined, undefined, [{ column: 'impersonatedUserName', filterType: 'cn' }, { column: 'impersonatedUserEmail', filterType: 'cn' }] ) ]; get clients () { return this.adminClientService.clients || []; } constructor ( private impersonationService: ImpersonationService, private i18n: I18nService, private adminClientService: AdminClientService ) { } ngOnInit () { this.tableDataFactory = DebounceFactory.createSimple( async (options: PaginationOptions) => { const response = await this.impersonationService.getImpersonationHistory(options); return { success: true, data: { recordCount: response.recordCount, records: response.records } }; } ); } }