-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
OptionRowLHN.js
227 lines (211 loc) · 12.3 KB
/
OptionRowLHN.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {TouchableOpacity, View, StyleSheet} from 'react-native';
import * as optionRowStyles from '../../styles/optionRowStyles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import MultipleAvatars from '../MultipleAvatars';
import Hoverable from '../Hoverable';
import DisplayNames from '../DisplayNames';
import colors from '../../styles/colors';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Text from '../Text';
import SubscriptAvatar from '../SubscriptAvatar';
import CONST from '../../CONST';
import themeColors from '../../styles/themes/default';
import SidebarUtils from '../../libs/SidebarUtils';
import TextPill from '../TextPill';
import OfflineWithFeedback from '../OfflineWithFeedback';
const propTypes = {
/** Style for hovered state */
// eslint-disable-next-line react/forbid-prop-types
hoverStyle: PropTypes.object,
/** The ID of the report that the option is for */
reportID: PropTypes.string.isRequired,
/** Whether this option is currently in focus so we can modify its style */
isFocused: PropTypes.bool,
/** A function that is called when an option is selected. Selected option is passed as a param */
onSelectRow: PropTypes.func,
/** Toggle between compact and default view */
viewMode: PropTypes.oneOf(_.values(CONST.OPTION_MODE)),
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),
...withLocalizePropTypes,
};
const defaultProps = {
hoverStyle: styles.sidebarLinkHover,
viewMode: 'default',
onSelectRow: () => {},
isFocused: false,
style: null,
};
const OptionRowLHN = (props) => {
const optionItem = SidebarUtils.getOptionData(props.reportID);
if (!optionItem) {
return null;
}
let touchableRef = null;
const textStyle = props.isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText;
const textUnreadStyle = optionItem.isUnread ? [textStyle, styles.sidebarLinkTextBold] : [textStyle];
const displayNameStyle = StyleUtils.combineStyles([styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, ...textUnreadStyle], props.style);
const textPillStyle = props.isFocused ? [styles.ml1, StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.icon, 0.5)] : [styles.ml1];
const alternateTextStyle = StyleUtils.combineStyles(
props.viewMode === CONST.OPTION_MODE.COMPACT
? [textStyle, styles.optionAlternateText, styles.pre, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2]
: [textStyle, styles.optionAlternateText, styles.pre, styles.textLabelSupporting],
props.style,
);
const contentContainerStyles =
props.viewMode === CONST.OPTION_MODE.COMPACT ? [styles.flex1, styles.flexRow, styles.overflowHidden, optionRowStyles.compactContentContainerStyles] : [styles.flex1];
const sidebarInnerRowStyle = StyleSheet.flatten(
props.viewMode === CONST.OPTION_MODE.COMPACT
? [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRowCompact, styles.justifyContentCenter]
: [styles.chatLinkRowPressable, styles.flexGrow1, styles.optionItemAvatarNameWrapper, styles.optionRow, styles.justifyContentCenter],
);
const hoveredBackgroundColor = props.hoverStyle && props.hoverStyle.backgroundColor ? props.hoverStyle.backgroundColor : themeColors.sidebar;
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
const hasBrickError = optionItem.brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
const shouldShowGreenDotIndicator = !hasBrickError && (optionItem.isUnreadWithMention || (optionItem.hasOutstandingIOU && !optionItem.isIOUReportOwner));
// If the item is a thread within a workspace, we will show the subtitle as the second line instead of in a pill
const alternativeText = optionItem.isThread && optionItem.subtitle ? optionItem.subtitle : optionItem.alternateText;
return (
<OfflineWithFeedback
pendingAction={optionItem.pendingAction}
errors={optionItem.allReportErrors}
shouldShowErrorMessages={false}
>
<Hoverable>
{(hovered) => (
<TouchableOpacity
ref={(el) => (touchableRef = el)}
onPress={(e) => {
if (e) {
e.preventDefault();
}
props.onSelectRow(optionItem, touchableRef);
}}
activeOpacity={0.8}
style={[
styles.flexRow,
styles.alignItemsCenter,
styles.justifyContentBetween,
styles.sidebarLink,
styles.sidebarLinkInner,
StyleUtils.getBackgroundColorStyle(themeColors.sidebar),
props.isFocused ? styles.sidebarLinkActive : null,
hovered && !props.isFocused ? props.hoverStyle : null,
]}
>
<View
accessibilityHint={props.translate('accessibilityHints.navigatesToChat')}
style={sidebarInnerRowStyle}
>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
{!_.isEmpty(optionItem.icons) &&
(optionItem.shouldShowSubscript ? (
<SubscriptAvatar
backgroundColor={props.isFocused ? themeColors.activeComponentBG : themeColors.sidebar}
mainAvatar={optionItem.icons[0]}
secondaryAvatar={optionItem.icons[1]}
mainTooltip={optionItem.ownerEmail}
secondaryTooltip={optionItem.subtitle}
size={props.viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT}
/>
) : (
<MultipleAvatars
icons={optionItem.icons}
isFocusMode={props.viewMode === CONST.OPTION_MODE.COMPACT}
size={props.viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT}
secondAvatarStyle={[
StyleUtils.getBackgroundAndBorderStyle(themeColors.sidebar),
props.isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined,
hovered && !props.isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined,
]}
shouldShowTooltip={!optionItem.isChatRoom && !optionItem.isArchivedRoom}
/>
))}
<View style={contentContainerStyles}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}>
<DisplayNames
accessibilityLabel={props.translate('accessibilityHints.chatUserDisplayNames')}
fullTitle={optionItem.text}
displayNamesWithTooltips={optionItem.displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
textStyles={displayNameStyle}
shouldUseFullTitle={
optionItem.isChatRoom || optionItem.isPolicyExpenseChat || optionItem.isTaskReport || optionItem.isThread || optionItem.isMoneyRequestReport
}
/>
{optionItem.isChatRoom && !optionItem.isThread && (
<TextPill
style={textPillStyle}
accessibilityLabel={props.translate('accessibilityHints.workspaceName')}
text={optionItem.subtitle}
/>
)}
</View>
{alternativeText ? (
<Text
style={alternateTextStyle}
numberOfLines={1}
accessibilityLabel={props.translate('accessibilityHints.lastChatMessagePreview')}
>
{alternativeText}
</Text>
) : null}
</View>
{optionItem.descriptiveText ? (
<View style={[styles.flexWrap]}>
<Text style={[styles.textLabel]}>{optionItem.descriptiveText}</Text>
</View>
) : null}
{hasBrickError && (
<View style={[styles.alignItemsCenter, styles.justifyContentCenter]}>
<Icon
src={Expensicons.DotIndicator}
fill={colors.red}
/>
</View>
)}
</View>
</View>
<View
style={[styles.flexRow, styles.alignItemsCenter]}
accessible={false}
>
{shouldShowGreenDotIndicator && (
<Icon
src={Expensicons.DotIndicator}
fill={themeColors.success}
/>
)}
{optionItem.hasDraftComment && (
<View
style={styles.ml2}
accessibilityLabel={props.translate('sidebarScreen.draftedMessage')}
>
<Icon src={Expensicons.Pencil} />
</View>
)}
{!shouldShowGreenDotIndicator && optionItem.isPinned && (
<View
style={styles.ml2}
accessibilityLabel={props.translate('sidebarScreen.chatPinned')}
>
<Icon src={Expensicons.Pin} />
</View>
)}
</View>
</TouchableOpacity>
)}
</Hoverable>
</OfflineWithFeedback>
);
};
OptionRowLHN.propTypes = propTypes;
OptionRowLHN.defaultProps = defaultProps;
OptionRowLHN.displayName = 'OptionRowLHN';
export default withLocalize(OptionRowLHN);