Skip to content

Commit f8c973b

Browse files
committed
feat(eap): add PrintableDescription component
- With support for the diff view
1 parent 4d25f34 commit f8c973b

File tree

16 files changed

+251
-71
lines changed

16 files changed

+251
-71
lines changed

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@togglecorp/toggle-request": "^1.0.0-beta.3",
4949
"@turf/bbox": "^6.5.0",
5050
"@turf/buffer": "^6.5.0",
51+
"diff": "^8.0.2",
5152
"exceljs": "^4.3.0",
5253
"file-saver": "^2.0.5",
5354
"html-to-image": "^1.11.11",

app/src/components/PerExportModal/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import {
1414

1515
import Link from '#components/Link';
1616
import { type components } from '#generated/types';
17-
import { useRequest } from '#utils/restRequest';
17+
import {
18+
type GoApiBody,
19+
useRequest,
20+
} from '#utils/restRequest';
1821

1922
import i18n from './i18n.json';
2023

2124
type ExportStatusEnum = components<'read'>['schemas']['ExportStatusEnum'];
25+
type ExportBody = GoApiBody<'/api/v2/pdf-export/', 'POST'>;
2226

2327
const EXPORT_STATUS_PENDING = 0 satisfies ExportStatusEnum;
2428
const EXPORT_STATUS_COMPLETED = 1 satisfies ExportStatusEnum;
@@ -45,8 +49,10 @@ function PerExportModal(props: Props) {
4549
export_id: Number(perId),
4650
export_type: 'per' as const,
4751
per_country: Number(countryId),
48-
is_pga: false,
49-
}),
52+
is_pga: undefined,
53+
version: undefined,
54+
diff: undefined,
55+
} satisfies ExportBody),
5056
[perId, countryId],
5157
);
5258

app/src/components/domain/DrefExportModal/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type TypeOfDrefEnum,
2525
} from '#utils/constants';
2626
import {
27+
type GoApiBody,
2728
useLazyRequest,
2829
useRequest,
2930
} from '#utils/restRequest';
@@ -33,6 +34,7 @@ import styles from './styles.module.css';
3334

3435
type ExportTypeEnum = components<'read'>['schemas']['ExportTypeEnum'];
3536
type ExportStatusEnum = components<'read'>['schemas']['ExportStatusEnum'];
37+
type ExportBody = GoApiBody<'/api/v2/pdf-export/', 'POST'>;
3638

3739
const EXPORT_STATUS_PENDING = 0 satisfies ExportStatusEnum;
3840
const EXPORT_STATUS_COMPLETED = 1 satisfies ExportStatusEnum;
@@ -83,9 +85,11 @@ function DrefExportModal(props: Props) {
8385
export_id: id,
8486
export_type: type,
8587
is_pga: includePga,
86-
selector: '#pdf-preview-ready',
88+
// selector: '#pdf-preview-ready',
8789
per_country: undefined,
88-
};
90+
version: undefined,
91+
diff: undefined,
92+
} satisfies ExportBody;
8993
},
9094
[
9195
id,

app/src/components/domain/EapExportModal/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface Props {
4141
eapType: EapType;
4242
version?: number;
4343
onClose: () => void;
44+
diff?: boolean;
4445
}
4546

4647
function EapExportModal(props: Props) {
@@ -49,6 +50,7 @@ function EapExportModal(props: Props) {
4950
eapType,
5051
onClose,
5152
version,
53+
diff,
5254
} = props;
5355

5456
const strings = useTranslation(i18n);
@@ -59,13 +61,14 @@ function EapExportModal(props: Props) {
5961
const exportTriggerBody = useMemo<ExportBody>(
6062
() => ({
6163
export_id: eapId,
62-
export_type: eapType === EAP_TYPE_SIMPLIFIED ? 'simplified-eap' : 'full-eap',
64+
export_type: eapType === EAP_TYPE_SIMPLIFIED ? 'simplified' : 'full',
6365
selector: '#pdf-preview-ready',
64-
is_pga: false,
66+
is_pga: undefined,
6567
per_country: undefined,
6668
version,
69+
diff,
6770
}),
68-
[eapId, eapType, version],
71+
[eapId, eapType, version, diff],
6972
);
7073

7174
const {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
Fragment,
3+
useMemo,
4+
} from 'react';
5+
import {
6+
_cs,
7+
isNotDefined,
8+
} from '@togglecorp/fujs';
9+
import { diffSentences } from 'diff';
10+
11+
import styles from './styles.module.css';
12+
13+
interface Props {
14+
value?: string | null;
15+
className?: string;
16+
prevValue?: string | null;
17+
}
18+
19+
function PrintableDescription(props: Props) {
20+
const {
21+
className,
22+
value,
23+
prevValue,
24+
} = props;
25+
26+
const diff = useMemo(() => {
27+
if (isNotDefined(value) || isNotDefined(prevValue)) {
28+
return undefined;
29+
}
30+
31+
return diffSentences(prevValue, value);
32+
}, [value, prevValue]);
33+
34+
if (isNotDefined(diff)) {
35+
return (
36+
<div className={_cs(styles.printableDescription, className)}>
37+
{value}
38+
</div>
39+
);
40+
}
41+
42+
return (
43+
<div
44+
className={_cs(
45+
styles.printableDescription,
46+
styles.withDiffView,
47+
className,
48+
)}
49+
>
50+
{diff.map((part, index) => {
51+
const { added, removed, value: partValue } = part;
52+
53+
if (added) {
54+
return (
55+
<span
56+
className={styles.added}
57+
// eslint-disable-next-line react/no-array-index-key
58+
key={index}
59+
>
60+
{partValue}
61+
</span>
62+
);
63+
}
64+
65+
if (removed) {
66+
return (
67+
<span
68+
className={styles.removed}
69+
// eslint-disable-next-line react/no-array-index-key
70+
key={index}
71+
>
72+
{partValue}
73+
</span>
74+
);
75+
}
76+
77+
return (
78+
// eslint-disable-next-line react/no-array-index-key
79+
<Fragment key={index}>
80+
{partValue}
81+
</Fragment>
82+
);
83+
})}
84+
</div>
85+
);
86+
}
87+
88+
export default PrintableDescription;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.printable-description {
2+
text-align: justify;
3+
white-space: pre-wrap;
4+
overflow-wrap: break-word;
5+
6+
&.with-diff-view {
7+
.added {
8+
background-color: color-mix(in srgb, var(--go-ui-color-green) 10%, transparent);
9+
color: var(--go-ui-color-green);
10+
}
11+
12+
.removed {
13+
background-color: color-mix(in srgb, var(--go-ui-color-red) 10%, transparent);
14+
text-decoration: line-through;
15+
color: var(--go-ui-color-red);
16+
}
17+
}
18+
}

app/src/utils/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,3 @@ export const EAP_STATUS_TECHNICALLY_VALIDATED = 40 satisfies EapStatus;
222222
export const EAP_STATUS_APPROVED = 50 satisfies EapStatus;
223223
export const EAP_STATUS_PFA_SIGNED = 60 satisfies EapStatus;
224224
export const EAP_STATUS_ACTIVATED = 70 satisfies EapStatus;
225-

app/src/views/AccountMyFormsEap/EapTableActions/i18n.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"namespace":"accountMyFormsEap",
33
"strings":{
4-
"eapViewLabel": "View",
5-
"eapEditLabel": "Edit",
64
"eapStartFullLink": "Start Full EAP",
75
"eapStartSimplifiedLink": "Start sEAP",
86
"eapEditFullLink": "Edit Full EAP",

app/src/views/AccountMyFormsEap/i18n.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"eapLastUpdated": "Last Updated",
77
"eapName": "Name/Phase",
88
"eapType": "EAP Type",
9-
"eapStatus": "Status",
10-
"eapRegistration": "EAP Registration"
9+
"eapStatus": "Status"
1110
}
1211
}

app/src/views/AccountMyFormsEap/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,31 +251,31 @@ export function Component() {
251251

252252
const detailColumns = useMemo(
253253
() => ([
254-
createExpansionIndicatorColumn<EapExpandedListItem, string>(
254+
createExpansionIndicatorColumn<EapExpandedListItem, string | number>(
255255
true,
256256
(row) => !!row.disabled,
257257
),
258-
createDateColumn<EapExpandedListItem, string>(
258+
createDateColumn<EapExpandedListItem, string | number>(
259259
'created_at',
260260
strings.eapLastUpdated,
261261
(row) => row.lastUpdated,
262262
),
263-
createStringColumn<EapExpandedListItem, string>(
263+
createStringColumn<EapExpandedListItem, string | number>(
264264
'title',
265265
'',
266266
(row) => row.label,
267267
{ withLightText: (item) => !!item.disabled },
268268
),
269-
createEmptyColumn<EapExpandedItem, string>(),
270-
createElementColumn<EapExpandedListItem, string, EapTableActionProps>(
269+
createEmptyColumn<EapExpandedListItem, string | number>(),
270+
createElementColumn<EapExpandedListItem, string | number, EapTableActionProps>(
271271
'actions',
272272
'',
273273
EapTableActions,
274274
(_, row) => ({
275275
expandedListItem: row,
276276
}),
277277
),
278-
createEmptyColumn<EapExpandedItem, string>(),
278+
createEmptyColumn<EapExpandedListItem, string | number>(),
279279
]),
280280
[strings.eapLastUpdated],
281281
);

0 commit comments

Comments
 (0)