Skip to content

Commit e3bf2e5

Browse files
committed
fix(export): update PrintableDescription and PrintableLabel components
1 parent 7767d96 commit e3bf2e5

4 files changed

Lines changed: 14 additions & 178 deletions

File tree

app/src/components/printable/PrintableDescription/index.tsx

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,24 @@
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';
1+
import DiffTextOutput from '../DiffTextOutput';
122

133
interface Props {
144
value?: string | null;
15-
className?: string;
165
withDiff?: boolean;
176
prevValue?: string | null;
187
}
198

209
function PrintableDescription(props: Props) {
2110
const {
22-
className,
2311
value,
2412
prevValue,
25-
withDiff = false,
13+
withDiff,
2614
} = props;
2715

28-
const diff = useMemo(() => {
29-
if (!withDiff) {
30-
return undefined;
31-
}
32-
33-
return diffSentences(prevValue ?? '', value ?? '');
34-
}, [withDiff, value, prevValue]);
35-
36-
if (isNotDefined(diff)) {
37-
return (
38-
<div className={_cs(styles.printableDescription, className)}>
39-
{value}
40-
</div>
41-
);
42-
}
43-
4416
return (
45-
<div
46-
className={_cs(
47-
styles.printableDescription,
48-
styles.withDiffView,
49-
className,
50-
)}
51-
>
52-
{diff.map((part, index) => {
53-
const { added, removed, value: partValue } = part;
54-
55-
if (added) {
56-
return (
57-
<span
58-
className={styles.added}
59-
// eslint-disable-next-line react/no-array-index-key
60-
key={index}
61-
>
62-
{partValue}
63-
</span>
64-
);
65-
}
66-
67-
if (removed) {
68-
return (
69-
<span
70-
className={styles.removed}
71-
// eslint-disable-next-line react/no-array-index-key
72-
key={index}
73-
>
74-
{partValue}
75-
</span>
76-
);
77-
}
78-
79-
return (
80-
// eslint-disable-next-line react/no-array-index-key
81-
<Fragment key={index}>
82-
{partValue}
83-
</Fragment>
84-
);
85-
})}
86-
</div>
17+
<DiffTextOutput
18+
value={value}
19+
prevValue={prevValue}
20+
withDiff={withDiff}
21+
/>
8722
);
8823
}
8924

app/src/components/printable/PrintableDescription/styles.module.css

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/src/components/printable/PrintableLabel/index.tsx

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,24 @@
1-
import {
2-
Fragment,
3-
useMemo,
4-
} from 'react';
5-
import {
6-
_cs,
7-
isNotDefined,
8-
} from '@togglecorp/fujs';
9-
import { diffWordsWithSpace } from 'diff';
10-
11-
import styles from './styles.module.css';
1+
import DiffTextOutput from '../DiffTextOutput';
122

133
interface Props {
144
value?: string | null;
15-
className?: string;
165
withDiff?: boolean;
176
prevValue?: string | null;
187
}
198

209
function PrintableLabel(props: Props) {
2110
const {
22-
className,
2311
value,
2412
prevValue,
25-
withDiff = false,
13+
withDiff,
2614
} = props;
2715

28-
const diff = useMemo(() => {
29-
if (!withDiff) {
30-
return undefined;
31-
}
32-
33-
return diffWordsWithSpace(prevValue ?? '', value ?? '');
34-
}, [withDiff, value, prevValue]);
35-
36-
if (isNotDefined(diff)) {
37-
return (
38-
<div className={_cs(styles.printableLabel, className)}>
39-
{value}
40-
</div>
41-
);
42-
}
43-
4416
return (
45-
<div
46-
className={_cs(
47-
styles.printableLabel,
48-
styles.withDiffView,
49-
className,
50-
)}
51-
>
52-
{diff.map((part, index) => {
53-
const { added, removed, value: partValue } = part;
54-
55-
if (added) {
56-
return (
57-
<span
58-
className={styles.added}
59-
// eslint-disable-next-line react/no-array-index-key
60-
key={index}
61-
>
62-
{partValue}
63-
</span>
64-
);
65-
}
66-
67-
if (removed) {
68-
return (
69-
<span
70-
className={styles.removed}
71-
// eslint-disable-next-line react/no-array-index-key
72-
key={index}
73-
>
74-
{partValue}
75-
</span>
76-
);
77-
}
78-
79-
return (
80-
// eslint-disable-next-line react/no-array-index-key
81-
<Fragment key={index}>
82-
{partValue}
83-
</Fragment>
84-
);
85-
})}
86-
</div>
17+
<DiffTextOutput
18+
value={value}
19+
prevValue={prevValue}
20+
withDiff={withDiff}
21+
/>
8722
);
8823
}
8924

app/src/components/printable/PrintableLabel/styles.module.css

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)