Skip to content

Commit

Permalink
Merge pull request #15207 from gedu/14893/edit_message_arrow_up
Browse files Browse the repository at this point in the history
14893: Edit message arrow up
  • Loading branch information
mountiny authored Mar 6, 2023
2 parents f95292a + ab82acd commit 593be0f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
6 changes: 6 additions & 0 deletions src/components/ArchivedReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import personalDetailsPropType from '../pages/personalDetailsPropType';
import ONYXKEYS from '../ONYXKEYS';
import * as ReportUtils from '../libs/ReportUtils';
import reportPropTypes from '../pages/reportPropTypes';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';
import styles from '../styles/styles';

const propTypes = {
Expand Down Expand Up @@ -90,5 +91,10 @@ export default compose(
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
reportClosedAction: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
canEvict: false,
selector: ReportActionsUtils.getLastClosedReportAction,
},
}),
)(ArchivedReportFooter);
4 changes: 3 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import reportPropTypes from '../reportPropTypes';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import ReportHeaderSkeletonView from '../../components/ReportHeaderSkeletonView';
import withViewportOffsetTop, {viewportOffsetTopPropTypes} from '../../components/withViewportOffsetTop';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';

const propTypes = {
/** Navigation route context info provided by react navigation */
Expand All @@ -51,7 +52,7 @@ const propTypes = {
report: reportPropTypes,

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),

/** Whether the composer is full size */
isComposerFullSize: PropTypes.bool,
Expand Down Expand Up @@ -324,6 +325,7 @@ export default compose(
reportActions: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getReportID(route)}`,
canEvict: false,
selector: ReportActionsUtils.getSortedReportActionsForDisplay,
},
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
Expand Down
15 changes: 7 additions & 8 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const propTypes = {
report: reportPropTypes,

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),

/** Is the report view covered by the drawer */
isDrawerOpen: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -108,7 +108,7 @@ const defaultProps = {
comment: '',
modal: {},
report: {},
reportActions: {},
reportActions: [],
blockedFromConcierge: {},
personalDetails: {},
...withCurrentUserPersonalDetailsDefaultProps,
Expand Down Expand Up @@ -447,14 +447,13 @@ class ReportActionCompose extends React.Component {
if (e.key === 'ArrowUp' && this.textInput.selectionStart === 0 && this.state.isCommentEmpty && !ReportUtils.chatIncludesChronos(this.props.report)) {
e.preventDefault();

const reportActionKey = _.find(
_.keys(this.props.reportActions).reverse(),
key => ReportUtils.canEditReportAction(this.props.reportActions[key]),
const lastReportAction = _.find(
this.props.reportActions,
action => ReportUtils.canEditReportAction(action),
);

if (reportActionKey !== -1 && this.props.reportActions[reportActionKey]) {
const {reportActionID, message} = this.props.reportActions[reportActionKey];
Report.saveReportActionDraft(this.props.reportID, reportActionID, _.last(message).html);
if (lastReportAction !== -1 && lastReportAction) {
Report.saveReportActionDraft(this.props.reportID, lastReportAction.reportActionID, _.last(lastReportAction.message).html);
}
}
}
Expand Down
26 changes: 11 additions & 15 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const propTypes = {
report: reportPropTypes.isRequired,

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),

/** The session of the logged in person */
session: PropTypes.shape({
Expand All @@ -49,7 +49,7 @@ const propTypes = {
};

const defaultProps = {
reportActions: {},
reportActions: [],
session: {},
};

Expand All @@ -62,12 +62,9 @@ class ReportActionsView extends React.Component {
this.unsubscribeVisibilityListener = null;
this.hasCachedActions = _.size(props.reportActions) > 0;

// We need this.sortedAndFilteredReportActions to be set before this.state is initialized because the function to calculate the newMarkerReportActionID uses the sorted report actions
this.sortedAndFilteredReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(props.reportActions);

this.state = {
isFloatingMessageCounterVisible: false,
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions),
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, props.reportActions),
};

this.currentScrollOffset = 0;
Expand Down Expand Up @@ -132,7 +129,6 @@ class ReportActionsView extends React.Component {

shouldComponentUpdate(nextProps, nextState) {
if (!_.isEqual(nextProps.reportActions, this.props.reportActions)) {
this.sortedAndFilteredReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(nextProps.reportActions);
this.mostRecentIOUReportActionID = ReportActionsUtils.getMostRecentIOUReportActionID(nextProps.reportActions);
return true;
}
Expand Down Expand Up @@ -203,16 +199,17 @@ class ReportActionsView extends React.Component {
if (didReportBecomeVisible) {
this.setState({
newMarkerReportActionID: ReportUtils.isUnread(this.props.report)
? ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions)
? ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions)
: '',
});
this.openReportIfNecessary();
}

// If the report action marking the unread point is deleted we need to recalculate which action should be the unread marker
if (this.state.newMarkerReportActionID && _.isEmpty(lodashGet(this.props.reportActions[this.state.newMarkerReportActionID], 'message[0].html'))) {
// If the report is unread, we want to check if the number of actions has decreased. If so, then it seems that one of them was deleted. In this case, if the deleted action was the
// one marking the unread point, we need to recalculate which action should be the unread marker.
if (ReportUtils.isUnread(this.props.report) && prevProps.reportActions.length > this.props.reportActions.length) {
this.setState({
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions),
newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions),
});
}

Expand All @@ -229,7 +226,7 @@ class ReportActionsView extends React.Component {
const didManuallyMarkReportAsUnread = (prevProps.report.lastReadTime !== this.props.report.lastReadTime)
&& ReportUtils.isUnread(this.props.report);
if (didManuallyMarkReportAsUnread) {
this.setState({newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.sortedAndFilteredReportActions)});
this.setState({newMarkerReportActionID: ReportUtils.getNewMarkerReportActionID(this.props.report, this.props.reportActions)});
}

// Ensures subscription event succeeds when the report/workspace room is created optimistically.
Expand Down Expand Up @@ -283,7 +280,7 @@ class ReportActionsView extends React.Component {
return;
}

const oldestReportAction = _.last(this.sortedAndFilteredReportActions);
const oldestReportAction = _.last(this.props.reportActions);

// Don't load more chats if we're already at the beginning of the chat history
if (oldestReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
Expand Down Expand Up @@ -347,7 +344,6 @@ class ReportActionsView extends React.Component {
if (!_.size(this.props.reportActions)) {
return null;
}

return (
<>
{!this.props.isComposerFullSize && (
Expand All @@ -360,7 +356,7 @@ class ReportActionsView extends React.Component {
report={this.props.report}
onScroll={this.trackScroll}
onLayout={this.recordTimeToMeasureItemLayout}
sortedReportActions={this.sortedAndFilteredReportActions}
sortedReportActions={this.props.reportActions}
mostRecentIOUReportActionID={this.mostRecentIOUReportActionID}
isLoadingMoreReportActions={this.props.report.isLoadingMoreReportActions}
loadMoreChats={this.loadMoreChats}
Expand Down
15 changes: 5 additions & 10 deletions src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {View, Keyboard} from 'react-native';

import CONST from '../../../CONST';
import ReportActionCompose from './ReportActionCompose';
import * as ReportUtils from '../../../libs/ReportUtils';
import SwipeableView from '../../../components/SwipeableView';
import OfflineIndicator from '../../../components/OfflineIndicator';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
Expand All @@ -17,14 +15,14 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../componen
import styles from '../../../styles/styles';
import reportActionPropTypes from './reportActionPropTypes';
import reportPropTypes from '../../reportPropTypes';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';
import * as ReportUtils from '../../../libs/ReportUtils';

const propTypes = {
/** Report object for the current report */
report: reportPropTypes,

/** Report actions for the current report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),

/** Offline status */
isOffline: PropTypes.bool.isRequired,
Expand All @@ -50,7 +48,7 @@ const propTypes = {

const defaultProps = {
report: {reportID: '0'},
reportActions: {},
reportActions: [],
onSubmitComment: () => {},
errors: {},
pendingAction: null,
Expand All @@ -68,18 +66,15 @@ class ReportFooter extends React.Component {

render() {
const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report);
let reportClosedAction;
if (isArchivedRoom) {
reportClosedAction = ReportActionsUtils.getLastClosedReportAction(this.props.reportActions);
}
const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors);

return (
<>
{(isArchivedRoom || hideComposer) && (
<View style={[styles.chatFooter, this.props.isSmallScreenWidth ? styles.mb5 : null]}>
{isArchivedRoom && (
<ArchivedReportFooter
reportClosedAction={reportClosedAction}
reportClosedAction={this.props.reportClosedAction}
report={this.props.report}
/>
)}
Expand Down

0 comments on commit 593be0f

Please sign in to comment.