import { Component, Input, OnChanges, OnInit } from '@angular/core'; import { OrgForDash } from '@core/typings/organization.typing'; import { NonprofitService } from '@features/nonprofit/nonprofit.service'; import { APIResult, DebounceFactory, PaginationOptions, SimpleDebounceFactory, TableCSVFactory, TableDataFactory, TopLevelFilter } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; @Component({ selector: 'gc-organizations-list', templateUrl: './organizations-list.component.html', styleUrls: ['./organizations-list.component.scss'] }) export class OrganizationsListComponent implements OnInit, OnChanges { @Input() cycleIds: number[]; @Input() key = ''; orgListFilters: TopLevelFilter[] = []; orgListFactory: TableDataFactory; orgListCsvFactory: TableCSVFactory; constructor ( private i18n: I18nService, private nonprofitService: NonprofitService ) { } get isNomination () { return location.pathname.includes('nomination'); } ngOnInit () { this.setOrgListFactoryAndFilters(); } ngOnChanges () { if (this.orgListFactory) { this.orgListFactory.reset.emit(); } } setOrgListFactoryAndFilters () { this.orgListFilters = [ new TopLevelFilter( 'text', 'organizationInfo.name', '', this.i18n.translate( 'APPLICANT:textSearchByOrganizationNameOrRequestAmt', {}, 'Search by organization name or request amount' ), undefined, undefined, [{ column: 'organizationInfo.name', filterType: 'cn' }, { column: 'amountRequested', filterType: 'eq' }] ) ]; this.orgListFactory = this.getOrgListFactory(false); this.orgListCsvFactory = this.getOrgListFactory(true); } getOrgListFactory ( isCsv: C ): SimpleDebounceFactory< PaginationOptions, C extends true ? string : APIResult> { return DebounceFactory.createSimple( async (options: PaginationOptions) => { options.rowsPerPage = 10; const result = await this.nonprofitService.getOrgListForInsights( options, this.cycleIds, isCsv ); return result; } ); } }