Skip to content

Commit 82558a1

Browse files
authored
Merge pull request #20730 from mkarkachov/fix/issue-19623
Fix: pencil icon disappear in LHN for announce
2 parents 41eb9ba + a9dcf2d commit 82558a1

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/components/LHNOptionsList/OptionRowLHN.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import _ from 'underscore';
2-
import React from 'react';
2+
import React, {useEffect} from 'react';
33
import PropTypes from 'prop-types';
44
import {View, StyleSheet} from 'react-native';
5+
import lodashGet from 'lodash/get';
56
import * as optionRowStyles from '../../styles/optionRowStyles';
67
import styles from '../../styles/styles';
78
import * as StyleUtils from '../../styles/StyleUtils';
@@ -12,6 +13,7 @@ import Hoverable from '../Hoverable';
1213
import DisplayNames from '../DisplayNames';
1314
import colors from '../../styles/colors';
1415
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
16+
import {withReportCommentDrafts} from '../OnyxProvider';
1517
import Text from '../Text';
1618
import SubscriptAvatar from '../SubscriptAvatar';
1719
import CONST from '../../CONST';
@@ -23,12 +25,18 @@ import PressableWithSecondaryInteraction from '../PressableWithSecondaryInteract
2325
import * as ReportActionContextMenu from '../../pages/home/report/ContextMenu/ReportActionContextMenu';
2426
import * as ContextMenuActions from '../../pages/home/report/ContextMenu/ContextMenuActions';
2527
import * as OptionsListUtils from '../../libs/OptionsListUtils';
28+
import compose from '../../libs/compose';
29+
import ONYXKEYS from '../../ONYXKEYS';
30+
import * as Report from '../../libs/actions/Report';
2631

2732
const propTypes = {
2833
/** Style for hovered state */
2934
// eslint-disable-next-line react/forbid-prop-types
3035
hoverStyle: PropTypes.object,
3136

37+
/** The comment left by the user */
38+
comment: PropTypes.string,
39+
3240
/** The ID of the report that the option is for */
3341
reportID: PropTypes.string.isRequired,
3442

@@ -52,11 +60,20 @@ const defaultProps = {
5260
onSelectRow: () => {},
5361
isFocused: false,
5462
style: null,
63+
comment: '',
5564
};
5665

5766
function OptionRowLHN(props) {
5867
const optionItem = SidebarUtils.getOptionData(props.reportID);
5968

69+
useEffect(() => {
70+
if (!optionItem || optionItem.hasDraftComment || !props.comment || props.comment.length <= 0 || props.isFocused) {
71+
return;
72+
}
73+
Report.setReportWithDraft(props.reportID, true);
74+
// eslint-disable-next-line react-hooks/exhaustive-deps
75+
}, []);
76+
6077
if (!optionItem) {
6178
return null;
6279
}
@@ -254,4 +271,13 @@ OptionRowLHN.propTypes = propTypes;
254271
OptionRowLHN.defaultProps = defaultProps;
255272
OptionRowLHN.displayName = 'OptionRowLHN';
256273

257-
export default withLocalize(OptionRowLHN);
274+
export default compose(
275+
withLocalize,
276+
withReportCommentDrafts({
277+
propName: 'comment',
278+
transformValue: (drafts, props) => {
279+
const draftKey = `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${props.reportID}`;
280+
return lodashGet(drafts, draftKey, '');
281+
},
282+
}),
283+
)(OptionRowLHN);

src/components/OnyxProvider.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const [withCurrentDate, CurrentDateProvider] = createOnyxContext(ONYXKEYS.CURREN
1212
const [withReportActionsDrafts, ReportActionsDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
1313
const [withBlockedFromConcierge, BlockedFromConciergeProvider] = createOnyxContext(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
1414
const [withBetas, BetasProvider] = createOnyxContext(ONYXKEYS.BETAS);
15+
const [withReportCommentDrafts, ReportCommentDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
1516

1617
const propTypes = {
1718
/** Rendered child component */
@@ -20,7 +21,17 @@ const propTypes = {
2021

2122
function OnyxProvider(props) {
2223
return (
23-
<ComposeProviders components={[NetworkProvider, PersonalDetailsProvider, ReportActionsDraftsProvider, CurrentDateProvider, BlockedFromConciergeProvider, BetasProvider]}>
24+
<ComposeProviders
25+
components={[
26+
NetworkProvider,
27+
PersonalDetailsProvider,
28+
ReportActionsDraftsProvider,
29+
CurrentDateProvider,
30+
BlockedFromConciergeProvider,
31+
BetasProvider,
32+
ReportCommentDraftsProvider,
33+
]}
34+
>
2435
{props.children}
2536
</ComposeProviders>
2637
);
@@ -31,4 +42,4 @@ OnyxProvider.propTypes = propTypes;
3142

3243
export default OnyxProvider;
3344

34-
export {withNetwork, withPersonalDetails, withReportActionsDrafts, withCurrentDate, withBlockedFromConcierge, withBetas, NetworkContext};
45+
export {withNetwork, withPersonalDetails, withReportActionsDrafts, withCurrentDate, withBlockedFromConcierge, withBetas, NetworkContext, withReportCommentDrafts};

src/pages/home/report/ReportActionCompose.js

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ class ReportActionCompose extends React.Component {
245245
showPopoverMenu: this.showPopoverMenu,
246246
});
247247
}
248+
249+
if (this.props.comment.length !== 0) {
250+
Report.setReportWithDraft(this.props.reportID, true);
251+
}
248252
}
249253

250254
componentDidUpdate(prevProps) {

0 commit comments

Comments
 (0)