-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReportActionItemFragment.js
125 lines (112 loc) · 4.94 KB
/
ReportActionItemFragment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, {memo} from 'react';
import {ActivityIndicator, View} from 'react-native';
import PropTypes from 'prop-types';
import Str from 'expensify-common/lib/str';
import reportActionFragmentPropTypes from './reportActionFragmentPropTypes';
import styles from '../../../styles/styles';
import variables from '../../../styles/variables';
import themeColors from '../../../styles/themes/default';
import RenderHTML from '../../../components/RenderHTML';
import Text from '../../../components/Text';
import Tooltip from '../../../components/Tooltip';
import * as EmojiUtils from '../../../libs/EmojiUtils';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import canUseTouchScreen from '../../../libs/canUseTouchscreen';
import compose from '../../../libs/compose';
const propTypes = {
/** The message fragment needing to be displayed */
fragment: reportActionFragmentPropTypes.isRequired,
/** Text to be shown for tooltip When Fragment is report Actor */
tooltipText: PropTypes.string,
/** Is this fragment an attachment? */
isAttachment: PropTypes.bool,
/** Does this fragment belong to a reportAction that has not yet loaded? */
loading: PropTypes.bool,
/** Should this fragment be contained in a single line? */
isSingleLine: PropTypes.bool,
...windowDimensionsPropTypes,
/** localization props */
...withLocalizePropTypes,
};
const defaultProps = {
isAttachment: false,
loading: false,
isSingleLine: false,
tooltipText: '',
};
const ReportActionItemFragment = (props) => {
switch (props.fragment.type) {
case 'COMMENT':
// If this is an attachment placeholder, return the placeholder component
if (props.isAttachment && props.loading) {
return (
<View style={[styles.chatItemAttachmentPlaceholder]}>
<ActivityIndicator
size="large"
color={themeColors.textSupporting}
style={[styles.flex1]}
/>
</View>
);
}
// Only render HTML if we have html in the fragment
return props.fragment.html !== props.fragment.text
? (
<RenderHTML
html={`<comment>${props.fragment.html + (props.fragment.isEdited ? '<edited></edited>' : '')}</comment>`}
/>
) : (
<Text
selectable={!canUseTouchScreen() || !props.isSmallScreenWidth}
style={EmojiUtils.isSingleEmoji(props.fragment.text) ? styles.singleEmojiText : undefined}
>
{Str.htmlDecode(props.fragment.text)}
{props.fragment.isEdited && (
<Text
fontSize={variables.fontSizeSmall}
color={themeColors.textSupporting}
>
{/* Native devices do not support margin between nested Text */}
<Text style={styles.w1}>{' '}</Text>
{props.translate('reportActionCompose.edited')}
</Text>
)}
</Text>
);
case 'TEXT':
return (
<Tooltip text={props.tooltipText}>
<Text
selectable
numberOfLines={props.isSingleLine ? 1 : undefined}
style={[styles.chatItemMessageHeaderSender]}
>
{Str.htmlDecode(props.fragment.text)}
</Text>
</Tooltip>
);
case 'LINK':
return <Text>LINK</Text>;
case 'INTEGRATION_COMMENT':
return <Text>REPORT_LINK</Text>;
case 'REPORT_LINK':
return <Text>REPORT_LINK</Text>;
case 'POLICY_LINK':
return <Text>POLICY_LINK</Text>;
// If we have a message fragment type of OLD_MESSAGE this means we have not yet converted this over to the
// new data structure. So we simply set this message as inner html and render it like we did before.
// This wil allow us to convert messages over to the new structure without needing to do it all at once.
case 'OLD_MESSAGE':
return <Text>OLD_MESSAGE</Text>;
default:
return <Text>fragment.text</Text>;
}
};
ReportActionItemFragment.propTypes = propTypes;
ReportActionItemFragment.defaultProps = defaultProps;
ReportActionItemFragment.displayName = 'ReportActionItemFragment';
export default compose(
withWindowDimensions,
withLocalize,
)(memo(ReportActionItemFragment));