File tree Expand file tree Collapse file tree
app/src/components/printable Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
133interface Props {
144 value ?: string | null ;
15- className ?: string ;
165 withDiff ?: boolean ;
176 prevValue ?: string | null ;
187}
198
209function 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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
133interface Props {
144 value ?: string | null ;
15- className ?: string ;
165 withDiff ?: boolean ;
176 prevValue ?: string | null ;
187}
198
209function 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
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments