Skip to content

Commit

Permalink
feat(dh): implement downloading of actors (#1957)
Browse files Browse the repository at this point in the history
* feat(dh): allow file name to be passed to export CSV util function

* refactor(dh): rename export CSV util function

* feat(dh): turn function args to an object for utility function

* feat(dh): implement downloading of actors
  • Loading branch information
dzhavat authored Aug 16, 2023
1 parent db8d820 commit e1fc794
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ <h3>{{ t("actors") }}</h3>
<span class="watt-chip-label">{{ dataSource.data.length }}</span>

<watt-search [label]="'shared.search' | transloco" (search)="searchInput$.next($event)" />

<watt-button icon="download" variant="text" (click)="download()">{{
"shared.download" | transloco
}}</watt-button>
</watt-card-title>

<dh-actors-filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { NgIf } from '@angular/common';
import { TranslocoModule } from '@ngneat/transloco';
import { TranslocoModule, translate } from '@ngneat/transloco';
import { BehaviorSubject, Observable, Subscription, combineLatest, debounceTime, map } from 'rxjs';
import { Apollo } from 'apollo-angular';

Expand All @@ -25,8 +25,9 @@ import { WATT_TABLE, WattTableColumnDef, WattTableDataSource } from '@energinet-
import { GetActorsDocument } from '@energinet-datahub/dh/shared/domain/graphql';
import { WattPaginatorComponent } from '@energinet-datahub/watt/paginator';
import { WattEmptyStateComponent } from '@energinet-datahub/watt/empty-state';
import { DhEmDashFallbackPipe } from '@energinet-datahub/dh/shared/ui-util';
import { DhEmDashFallbackPipe, exportToCSV } from '@energinet-datahub/dh/shared/ui-util';
import { WattSearchComponent } from '@energinet-datahub/watt/search';
import { WattButtonComponent } from '@energinet-datahub/watt/button';

import { DhActorsFiltersComponent } from './filters/dh-actors-filters.component';
import { ActorsFilters, AllFiltersCombined } from './actors-filters';
Expand Down Expand Up @@ -75,6 +76,7 @@ import { dhToJSON } from './dh-json-util';
WattSearchComponent,
WattPaginatorComponent,
WattEmptyStateComponent,
WattButtonComponent,
],
})
export class DhActorsOverviewComponent implements OnInit, OnDestroy {
Expand Down Expand Up @@ -139,4 +141,36 @@ export class DhActorsOverviewComponent implements OnInit, OnDestroy {
this.subscription?.unsubscribe();
this.subscription = null;
}

download(): void {
if (!this.dataSource.sort) {
return;
}

const dataSorted = this.dataSource.sortData(this.dataSource.filteredData, this.dataSource.sort);

const actorsOverviewPath = 'marketParticipant.actorsOverview';

const headers = [
`"ID"`,
`"${translate(actorsOverviewPath + '.columns.glnOrEic')}"`,
`"${translate(actorsOverviewPath + '.columns.name')}"`,
`"${translate(actorsOverviewPath + '.columns.marketRole')}"`,
`"${translate(actorsOverviewPath + '.columns.status')}"`,
];

const lines = dataSorted.map((actor) => [
`"${actor.id}"`,
`"${actor.glnOrEicNumber}"`,
`"${actor.name}"`,
`"${
actor.marketRole == null
? ''
: translate('marketParticipant.marketRoles.' + actor.marketRole)
}"`,
`"${actor.status == null ? '' : translate(actorsOverviewPath + '.status.' + actor.status)}"`,
]);

exportToCSV({ headers, lines, fileName: 'actors' });
}
}

0 comments on commit e1fc794

Please sign in to comment.