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

Download notification documents bff api - pn-10889 #1199

Merged
merged 7 commits into from
May 13, 2024
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 @@ -6,22 +6,14 @@ import { styled } from '@mui/material/styles';
import { TimelineNotification } from '@pagopa/mui-italia';

import { useIsMobile } from '../../hooks';
import {
LegalFactId,
NotificationDetailOtherDocument,
NotificationDetailRecipient,
NotificationStatusHistory,
} from '../../models';
import { LegalFactId, NotificationDetailRecipient, NotificationStatusHistory } from '../../models';
import NotificationDetailTimelineStep from './NotificationDetailTimelineStep';

type Props = {
recipients: Array<NotificationDetailRecipient>;
statusHistory: Array<NotificationStatusHistory>;
title: string;
// legalFact can be either a LegalFactId, or a NotificationDetailOtherDocument
// (generated from details.generatedAarUrl in ANALOG_FAILURE_WORKFLOW timeline elements).
// Cfr. comment in the definition of INotificationDetailTimeline in src/models/NotificationDetail.ts.
clickHandler: (legalFactId: LegalFactId | NotificationDetailOtherDocument) => void;
clickHandler: (legalFactId: LegalFactId) => void;
historyButtonLabel: string;
showMoreButtonLabel: string;
showLessButtonLabel: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { useIsMobile } from '../../hooks';
import {
INotificationDetailTimeline,
LegalFactId,
NotificationDetailOtherDocument,
NotificationDetailRecipient,
NotificationStatus,
NotificationStatusHistory,
Expand All @@ -35,10 +34,7 @@ import {
type Props = {
timelineStep: NotificationStatusHistory;
recipients: Array<NotificationDetailRecipient>;
// legalFact can be either a LegalFactId, or a NotificationDetailOtherDocument
// (generated from details.generatedAarUrl in ANALOG_FAILURE_WORKFLOW timeline elements).
// Cfr. comment in the definition of INotificationDetailTimeline in src/models/NotificationDetail.ts.
clickHandler: (legalFactId: LegalFactId | NotificationDetailOtherDocument) => void;
clickHandler: (legalFactId: LegalFactId) => void;
position?: 'first' | 'last' | 'middle';
showMoreButtonLabel?: string;
showLessButtonLabel?: string;
Expand Down Expand Up @@ -130,7 +126,7 @@ const NotificationDetailTimelineStep = ({
const [collapsed, setCollapsed] = useState(true);
/* eslint-disable functional/no-let */
let legalFactsIds: Array<{
file: LegalFactId | NotificationDetailOtherDocument;
file: LegalFactId;
step: INotificationDetailTimeline;
}> = [];
let visibleSteps: Array<INotificationDetailTimeline> = [];
Expand All @@ -145,7 +141,7 @@ const NotificationDetailTimelineStep = ({
return arr.concat(s.legalFactsIds.map((lf) => ({ file: lf, step: s })));
}
return arr;
}, [] as Array<{ file: LegalFactId | NotificationDetailOtherDocument; step: INotificationDetailTimeline }>);
}, [] as Array<{ file: LegalFactId; step: INotificationDetailTimeline }>);

visibleSteps = timelineStep.steps.filter((s) => !s.hidden);
/* eslint-enable functional/immutable-data */
Expand Down Expand Up @@ -200,23 +196,15 @@ const NotificationDetailTimelineStep = ({
legalFactsIds.length > 0 &&
legalFactsIds.map((lf) => (
<ButtonNaked
key={
(lf.file as LegalFactId).key ||
(lf.file as NotificationDetailOtherDocument).documentId
}
key={lf.file.key}
startIcon={<AttachFileIcon />}
onClick={() => clickHandler(lf.file)}
color="primary"
sx={{ marginTop: '10px', textAlign: 'left' }}
data-testid="download-legalfact"
disabled={disableDownloads}
>
{getLegalFactLabel(
lf.step,
(lf.file as LegalFactId).category ||
(lf.file as NotificationDetailOtherDocument).documentType,
(lf.file as LegalFactId).key || ''
)}
{getLegalFactLabel(lf.step, lf.file.category, lf.file.key || '')}
</ButtonNaked>
))}
</Box>
Expand Down Expand Up @@ -300,18 +288,10 @@ const NotificationDetailTimelineStep = ({
color={disableDownloads ? 'text.disabled' : 'primary'}
sx={{ cursor: disableDownloads ? 'default' : 'pointer' }}
onClick={() => clickHandler(lf)}
key={
(lf as LegalFactId).key ||
(lf as NotificationDetailOtherDocument).documentId
}
key={lf.key}
data-testid="download-legalfact-micro"
>
{getLegalFactLabel(
s,
(lf as LegalFactId).category ||
(lf as NotificationDetailOtherDocument).documentType,
(lf as LegalFactId).key || ''
)}
{getLegalFactLabel(s, lf.category, lf.key || '')}
</Typography>
))}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { vi } from 'vitest';

import { notificationDTO } from '../../../__mocks__/NotificationDetail.mock';
import {
INotificationDetailTimeline,
LegalFactId,
NotificationDetailOtherDocument,
NotificationStatus,
} from '../../../models';
import { INotificationDetailTimeline, LegalFactId, NotificationStatus } from '../../../models';
import { fireEvent, render, theme } from '../../../test-utils';
import {
formatDay,
Expand All @@ -31,7 +26,7 @@ const getLegalFacts = (collapsed: boolean = true) =>
return arr.concat(s.legalFactsIds.map((lf) => ({ file: lf, step: s })));
}
return arr;
}, [] as Array<{ file: LegalFactId | NotificationDetailOtherDocument; step: INotificationDetailTimeline }>);
}, [] as Array<{ file: LegalFactId; step: INotificationDetailTimeline }>);

const checkDateItem = (index: number, dateItem: HTMLElement, date: string) => {
if (index === 0) {
Expand Down Expand Up @@ -74,9 +69,8 @@ describe('NotificationDetailTimelineStep', () => {
expect(el).toHaveTextContent(
getLegalFactLabel(
mockLegalFacts[index].step,
(mockLegalFacts[index].file as LegalFactId).category ||
(mockLegalFacts[index].file as NotificationDetailOtherDocument).documentType,
(mockLegalFacts[index].file as LegalFactId).key || ''
mockLegalFacts[index].file.category,
mockLegalFacts[index].file.key || ''
)
);
expect(el).toBeEnabled();
Expand Down Expand Up @@ -132,11 +126,7 @@ describe('NotificationDetailTimelineStep', () => {
if (step.legalFactsIds && step.legalFactsIds.length > 0) {
for (const lf of step.legalFactsIds) {
expect(microLegalFacts[counter]).toHaveTextContent(
getLegalFactLabel(
step,
(lf as LegalFactId).category || (lf as NotificationDetailOtherDocument).documentType,
(lf as LegalFactId).key || ''
)
getLegalFactLabel(step, lf.category, lf.key || '')
);
expect(microLegalFacts[counter]).toHaveStyle({
color: theme.palette.primary.main,
Expand Down
34 changes: 27 additions & 7 deletions packages/pn-commons/src/models/NotificationDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ export interface INotificationDetailTimeline {
// The link to the AAR (i.e. details.generatedAarUrl) included to ANALOG_FAILURE_WORKFLOW timeline elements
// must be handled analogously to legal facts,
// i.e. a link must be shown inside the graphic timeline.
// To achieve this, we add the NotificationDetailOtherDocument object corresponding to such links
// To achieve this, we add the LegalFactId object corresponding to such links
// to the legalFactsIds array for the ANALOG_FAILURE_WORKFLOW timeline elements.
// Consequently, each element of legalFactsIds can be either
// - a LegalFactId object coming from legalFactsIds in the API response, or
// - a NotificationDetailOtherDocument coming from details.generatedAarUrl in ANALOG_FAILURE_WORKFLOW timeline elements
// ------------------------------------------------
// Carlos Lombardi, 2023.05.02
// ------------------------------------------------
legalFactsIds?: Array<LegalFactId | NotificationDetailOtherDocument>;
legalFactsIds?: Array<LegalFactId>;
category: TimelineCategory;
details: NotificationDetailTimelineDetails;
hidden?: boolean;
Expand Down Expand Up @@ -112,6 +109,7 @@ interface BaseDetails {

export interface AnalogWorkflowDetails extends BaseDetails {
physicalAddress?: PhysicalAddress;
getGeneratedAarUrl?: string;
}

export interface SendCourtesyMessageDetails extends BaseDetails {
Expand Down Expand Up @@ -298,7 +296,6 @@ export enum RecipientType {
}

export enum LegalFactType {
AAR = 'AAR',
SENDER_ACK = 'SENDER_ACK',
DIGITAL_DELIVERY = 'DIGITAL_DELIVERY',
ANALOG_DELIVERY = 'ANALOG_DELIVERY',
Expand All @@ -309,7 +306,7 @@ export enum LegalFactType {

export interface LegalFactId {
key: string;
category: LegalFactType;
category: LegalFactType | 'AAR';
}

export interface NotificationDetailOtherDocument {
Expand Down Expand Up @@ -363,3 +360,26 @@ export interface ExtRegistriesPaymentDetails {
errorCode?: string;
url?: string;
}

/** Api models */
export enum NotificationDocumentType {
AAR = 'AAR',
ATTACHMENT = 'ATTACHMENT',
LEGAL_FACT = 'LEGAL_FACT',
}

export interface NotificationDocumentRequest {
iun: string;
documentType: NotificationDocumentType;
documentIdx?: number;
documentId?: string;
documentCategory?: LegalFactType;
mandateId?: string;
}

export interface NotificationDocumentResponse {
filename: string;
contentLength: number;
url: string;
retryAfter?: number;
}
6 changes: 6 additions & 0 deletions packages/pn-commons/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import {
NotificationDetailRecipient,
NotificationDetailTableRow,
NotificationDetailTimelineDetails,
NotificationDocumentRequest,
NotificationDocumentResponse,
NotificationDocumentType,
NotificationStatusHistory,
PagoPAPaymentFullDetails,
PaidDetails,
Expand Down Expand Up @@ -114,6 +117,7 @@ export {
EventPropertyType,
ConsentType,
ConsentActionType,
NotificationDocumentType,
};
export type {
AnalogWorkflowDetails,
Expand Down Expand Up @@ -183,4 +187,6 @@ export type {
EventType,
ActionMeta,
TosPrivacyConsent,
NotificationDocumentRequest,
NotificationDocumentResponse,
};
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ describe('timeline legal fact link text', () => {
legalFactsIds: [
{
key: 'legal-fact-1',
category: LegalFactType.AAR,
category: LegalFactType.PEC_RECEIPT,
},
],
};
const label = getLegalFactLabel(timelineElem, LegalFactType.AAR, 'legal-fact-1');
const label = getLegalFactLabel(timelineElem, LegalFactType.PEC_RECEIPT, 'legal-fact-1');
expect(label).toBe('notifiche - detail.timeline.analog-workflow-attachment-kind.Plico');
});

Expand All @@ -376,14 +376,18 @@ describe('timeline legal fact link text', () => {
legalFactsIds: [
{
key: 'legal-fact-1',
category: LegalFactType.AAR,
category: LegalFactType.DIGITAL_DELIVERY,
},
],
};
let label = getLegalFactLabel(timelineElem, LegalFactType.AAR, 'legal-fact-1');
let label = getLegalFactLabel(timelineElem, LegalFactType.DIGITAL_DELIVERY, 'legal-fact-1');
expect(label).toBe('notifiche - detail.timeline.analog-workflow-attachment-kind.23L');
// no attachments
label = getLegalFactLabel({ ...timelineElem, details: {} }, LegalFactType.AAR, 'legal-fact-1');
label = getLegalFactLabel(
{ ...timelineElem, details: {} },
LegalFactType.DIGITAL_DELIVERY,
'legal-fact-1'
);
expect(label).toBe('notifiche - detail.timeline.analog-workflow-attachment-kind.generic');
});

Expand All @@ -405,9 +409,11 @@ describe('timeline legal fact link text', () => {
'ANALOG_FAILURE_WORKFLOW.IUN_RTRD-UDGU-QTQY-202308-P-1.RECINDEX_1.SOURCE_SPECIAL.ATTEMPT_0',
timestamp: '2023-08-25T09:35:37.467148235Z',
category: TimelineCategory.ANALOG_FAILURE_WORKFLOW,
details: {},
details: {
getGeneratedAarUrl: 'https://aar-fake-url.com',
},
};
const label = getLegalFactLabel(timelineElem, LegalFactType.AAR);
const label = getLegalFactLabel(timelineElem);
expect(label).toBe('notifiche - detail.timeline.aar-document');
});

Expand Down
5 changes: 3 additions & 2 deletions packages/pn-commons/src/utility/notification.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import _ from 'lodash';

import {
AnalogWorkflowDetails,
ExtRegistriesPaymentDetails,
F24PaymentDetails,
INotificationDetailTimeline,
Expand Down Expand Up @@ -305,7 +306,7 @@ function legalFactTypeForAnalogEvent(
*/
export function getLegalFactLabel(
timelineStep: INotificationDetailTimeline,
legalFactType?: LegalFactType,
legalFactType?: LegalFactType | 'AAR',
legalFactKey?: string
): string {
const legalFactLabel = getLocalizedOrDefaultLabel(
Expand Down Expand Up @@ -387,7 +388,7 @@ export function getLegalFactLabel(
);
} else if (
timelineStep.category === TimelineCategory.ANALOG_FAILURE_WORKFLOW &&
legalFactType === LegalFactType.AAR
(timelineStep.details as AnalogWorkflowDetails).getGeneratedAarUrl
) {
return getLocalizedOrDefaultLabel(
'notifications',
Expand Down
Loading