Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to remove OOO events by clicking on a button #15502

Merged
merged 29 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0e5ebf4
WIP on displaying OOO list message
tgolen Jan 18, 2023
a19105b
Display the events in a list
tgolen Jan 20, 2023
4923aae
Display remove button
tgolen Jan 20, 2023
f44a60f
Add a Chronos action file to remove events
tgolen Jan 20, 2023
8f21977
Add API method
tgolen Jan 20, 2023
aa7e49c
Move everything to one component
tgolen Jan 23, 2023
81229e9
Start making API call and setup optimistic data
tgolen Jan 24, 2023
46672c5
Show an empty list message
tgolen Jan 24, 2023
f0f6af6
Filter events properly
tgolen Jan 25, 2023
c70e0e0
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Jan 25, 2023
eb13610
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Jan 26, 2023
0954811
WIP on removing OOO events
tgolen Jan 27, 2023
4b6aa45
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Feb 25, 2023
ce05ade
Remove debug code
tgolen Feb 25, 2023
f830a12
Fix the date display
tgolen Feb 25, 2023
c3e9561
Fix optimistic data
tgolen Feb 25, 2023
619d163
Add offline with feedback
tgolen Feb 26, 2023
fbbd9f9
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Feb 28, 2023
3bf5348
Add some protection for possibly null properties
tgolen Feb 28, 2023
7cf132e
Simplify parameters
tgolen Feb 28, 2023
ad8f011
Add translations and localized formats
tgolen Feb 28, 2023
ad4b91a
Translate all text
tgolen Feb 28, 2023
442aa76
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Feb 28, 2023
0f2b048
Correct styles for mobile
tgolen Feb 28, 2023
bedbeeb
Fix lint problems
tgolen Feb 28, 2023
3d9d7e2
Replace missing translation
tgolen Feb 28, 2023
699cf1c
Correct JS docs and use reject()
tgolen Mar 1, 2023
c45211a
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Mar 7, 2023
541e0c7
Merge branch 'main' into tgolen-chronos-ooo-list-remove
tgolen Mar 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ const CONST = {
CREATED: 'CREATED',
IOU: 'IOU',
RENAMED: 'RENAMED',
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
},
},
ARCHIVE_REASON: {
Expand Down
82 changes: 82 additions & 0 deletions src/components/ReportActionItem/ChronosOOOListActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import styles from '../../styles/styles';
import Text from '../Text';
import Button from '../Button';
import * as Chronos from '../../libs/actions/Chronos';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import DateUtils from '../../libs/DateUtils';
import OfflineWithFeedback from '../OfflineWithFeedback';

const propTypes = {
/** The ID of the report */
reportID: PropTypes.string.isRequired,

/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,

...withLocalizePropTypes,
};

const ChronosOOOListActions = (props) => {
const events = lodashGet(props.action, 'originalMessage.events', []);

if (!events.length) {
return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.pt, styles.ml18]}>
<Text>You haven&apos;t created any events</Text>
tgolen marked this conversation as resolved.
Show resolved Hide resolved
</View>
);
}

return (
<OfflineWithFeedback
pendingAction={lodashGet(props.action, 'pendingAction', null)}
tgolen marked this conversation as resolved.
Show resolved Hide resolved
>
<View style={[styles.chatItemMessage]}>
{_.map(events, (event) => {
const start = DateUtils.getLocalMomentFromDatetime(props.preferredLocale, lodashGet(event, 'start.date', ''));
const end = DateUtils.getLocalMomentFromDatetime(props.preferredLocale, lodashGet(event, 'end.date', ''));
return (
<View key={event.id} style={[styles.flexRow, styles.pt, styles.ml18, styles.pr4, styles.alignItemsCenter]}>
<Text style={[styles.flexShrink1]}>
{event.lengthInDays > 0 ? (
props.translate('chronos.oooEventSummaryFullDay', {
summary: event.summary,
dayCount: event.lengthInDays,
date: end.format('dddd LL'),
})
) : (
props.translate('chronos.oooEventSummaryPartialDay', {
summary: event.summary,
timePeriod: `${start.format('LT')} - ${end.format('LT')}`,
date: end.format('dddd LL'),
})
)}
</Text>
<Button
tgolen marked this conversation as resolved.
Show resolved Hide resolved
small
style={[styles.pl2]}
onPress={() => Chronos.removeEvent(props.reportID, props.action.reportActionID, event.id, events)}
ContentComponent={() => (
<Text style={styles.buttonSmallText}>
{props.translate('common.remove')}
</Text>
)}
/>
</View>
);
})}
</View>
</OfflineWithFeedback>
);
};

ChronosOOOListActions.propTypes = propTypes;
ChronosOOOListActions.displayName = 'ChronosOOOListActions';

export default withLocalize(ChronosOOOListActions);
4 changes: 4 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,10 @@ export default {
report: {
genericAddCommentFailureMessage: 'Unexpected error while posting the comment, please try again later',
},
chronos: {
oooEventSummaryFullDay: ({summary, dayCount, date}) => `${summary} for ${dayCount} ${dayCount === 1 ? 'day' : 'days'} until ${date}`,
oooEventSummaryPartialDay: ({summary, timePeriod, date}) => `${summary} from ${timePeriod} on ${date}`,
},
footer: {
features: 'Features',
expenseManagement: 'Expense Management',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,10 @@ export default {
report: {
genericAddCommentFailureMessage: 'Error inesperado al agregar el comentario, por favor inténtalo más tarde',
},
chronos: {
oooEventSummaryFullDay: ({summary, dayCount, date}) => `${summary} por ${dayCount} ${dayCount === 1 ? 'día' : 'días'} hasta el ${date}`,
oooEventSummaryPartialDay: ({summary, timePeriod, date}) => `${summary} de ${timePeriod} del ${date}`,
},
footer: {
features: 'Características',
expenseManagement: 'Gestión de Gastos',
Expand Down
62 changes: 62 additions & 0 deletions src/libs/actions/Chronos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import _ from 'underscore';
import CONST from '../../CONST';
import ONYXKEYS from '../../ONYXKEYS';
import * as API from '../API';

/**
* @param {String} reportID
* @param {String} reportActionID
* @param {String} eventID
* @param {Object[]} events
*/
const removeEvent = (reportID, reportActionID, eventID, events) => {
const optimisticData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
originalMessage: {
events: _.reject(events, event => event.id === eventID),
},
},
},
},
];

const successData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
pendingAction: null,
},
},
},
];

const failureData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[reportActionID]: {
originalMessage: {events},
pendingAction: null,
},
},
},
];

API.write('Chronos_RemoveOOOEvent', {
googleEventID: eventID,
reportActionID,
}, {optimisticData, successData, failureData});
};

export {
// eslint-disable-next-line import/prefer-default-export
removeEvent,
};
5 changes: 4 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import * as ReportActions from '../../../libs/actions/ReportActions';
import reportPropTypes from '../../reportPropTypes';
import {ShowContextMenuContext} from '../../../components/ShowContextMenuContext';
import focusTextInputAfterAnimation from '../../../libs/focusTextInputAfterAnimation';
import ChronosOOOListActions from '../../../components/ReportActionItem/ChronosOOOListActions';
import ReportActionItemReactions from '../../../components/Reactions/ReportActionItemReactions';
import * as Report from '../../../libs/actions/Report';

Expand Down Expand Up @@ -224,7 +225,9 @@ class ReportActionItem extends Component {
if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) {
return <RenameAction action={this.props.action} />;
}

if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CHRONOSOOOLIST) {
return <ChronosOOOListActions action={this.props.action} reportID={this.props.report.reportID} />;
}
return (
<PressableWithSecondaryInteraction
pointerEvents={this.props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ? 'none' : 'auto'}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utilities/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export default {
marginLeft: 40,
},

ml18: {
marginLeft: 72,
},

mln5: {
marginLeft: -20,
},
Expand Down