Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

portalicious: export duplicates #6005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,32 @@
[exportType]="ExportType.allPeopleAffected"
/>
</app-confirmation-dialog>
<app-confirmation-dialog
#exportDuplicatesDialog
header="Export duplicate registrations"
i18n-header="@@export-duplicate"
headerIcon="pi pi-upload"
[mutation]="exportRegistrationsMutation"
[mutationData]="{
type: ExportType.duplicates,
}"
>
<p i18n>
You're about to download an Excel file for all duplicate registrations.
</p>
<p
i18n
class="mt-2"
>
Checking duplicates is based on:
</p>
<ul class="mt-1 list-disc pl-4">
@for (attribute of duplicateExportAttributes.data(); track attribute) {
<li>{{ attribute }}</li>
}
</ul>
<app-latest-export-date
[projectId]="projectId()"
[exportType]="ExportType.allPeopleAffected"
/>
</app-confirmation-dialog>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
ViewChild,
} from '@angular/core';

import { injectMutation } from '@tanstack/angular-query-experimental';
import {
injectMutation,
injectQuery,
} from '@tanstack/angular-query-experimental';
import { MenuItem } from 'primeng/api';
import { SplitButtonModule } from 'primeng/splitbutton';

Expand Down Expand Up @@ -50,13 +53,21 @@ export class ExportRegistrationsComponent {
private exportSelectedDialog: ConfirmationDialogComponent;
@ViewChild('exportAllDialog')
private exportAllDialog: ConfirmationDialogComponent;
@ViewChild('exportDuplicatesDialog')
private exportDuplicatesDialog: ConfirmationDialogComponent;

exportSelectedActionData = signal<
ActionDataWithPaginateQuery<Registration> | undefined
>(undefined);

ExportType = ExportType;

duplicateExportAttributes = injectQuery(() => ({
queryKey: [this.projectId],
queryFn: () =>
this.exportService.getDuplicateCheckAttributes(this.projectId),
}));

exportRegistrationsMutation = injectMutation(() => ({
mutationFn: async (exportOptions: {
type: 'pa-data-changes' | ExportType;
Expand Down Expand Up @@ -111,10 +122,7 @@ export class ExportRegistrationsComponent {
{
label: $localize`:@@export-duplicate:Export duplicate registrations`,
command: () => {
this.toastService.showToast({
detail: 'That has not been implemented yet...',
severity: 'warn',
});
this.exportDuplicatesDialog.askForConfirmation();
},
},
{
Expand Down
41 changes: 41 additions & 0 deletions interfaces/Portalicious/src/app/services/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ExportType } from '@121-service/src/metrics/enum/export-type.enum';

import { EventApiService } from '~/domains/event/event.api.service';
import { MetricApiService } from '~/domains/metric/metric.api.service';
import { ProjectApiService } from '~/domains/project/project.api.service';
import {
PaginateQuery,
PaginateQueryService,
Expand All @@ -20,6 +21,7 @@ export class ExportService {
private paginateQueryService = inject(PaginateQueryService);
private eventApiService = inject(EventApiService);
private metricApiService = inject(MetricApiService);
private projectApiService = inject(ProjectApiService);

private generateExportParams({
type,
Expand Down Expand Up @@ -117,4 +119,43 @@ export class ExportService {

return { exportResult, filename };
}

private toAtributesForDuplicateCheckFilter(
attributes: {
name: string;
duplicateCheck: boolean;
}[],
) {
return attributes
.filter((attribute) => attribute.duplicateCheck)
.map((attribute) => attribute.name);
}

async getDuplicateCheckAttributes(
projectId: Signal<number>,
): Promise<string[]> {
// TODO: AB#30519 This is a temporary solution until we have a better way to get all project attribute with the `duplicateCheck` flag included.
// Ideally we will delete this function and just replace the call to `getDuplicateCheckAttributes` with a call to `getProjectAttributes`.
const project = await this.queryClient.fetchQuery(
this.projectApiService.getProject(projectId)(),
);

const {
programQuestions,
programCustomAttributes,
financialServiceProviders,
} = project;

const fspAttributes = financialServiceProviders
.map((fsp) => fsp.questions)
.flat();

const allAttributeNames: string[] = [
...this.toAtributesForDuplicateCheckFilter(programQuestions),
...this.toAtributesForDuplicateCheckFilter(programCustomAttributes),
...this.toAtributesForDuplicateCheckFilter(fspAttributes),
];

return [...new Set(allAttributeNames)].sort((a, b) => a.localeCompare(b));
}
}
8 changes: 8 additions & 0 deletions interfaces/Portalicious/src/locale/messages.nl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,14 @@
<source>There has been no export yet.</source>
<target state="new">There has been no export yet.</target>
</trans-unit>
<trans-unit id="771623267264728975" datatype="html">
<source>You&apos;re about to download an Excel file for all duplicate registrations.</source>
<target state="new">You&apos;re about to download an Excel file for all duplicate registrations.</target>
</trans-unit>
<trans-unit id="9109328074966219188" datatype="html">
<source>Checking duplicates is based on:</source>
<target state="new">Checking duplicates is based on:</target>
</trans-unit>
</body>
</file>
</xliff>
6 changes: 6 additions & 0 deletions interfaces/Portalicious/src/locale/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,12 @@
<trans-unit id="4452017686076766931" datatype="html">
<source>Latest export has been done on: <x equiv-text="{{ latestExport.data()?.created | date: &apos;medium&apos; }}" id="INTERPOLATION"/></source>
</trans-unit>
<trans-unit id="771623267264728975" datatype="html">
<source>You&apos;re about to download an Excel file for all duplicate registrations.</source>
</trans-unit>
<trans-unit id="9109328074966219188" datatype="html">
<source>Checking duplicates is based on:</source>
</trans-unit>
</body>
</file>
</xliff>
Loading