Skip to content

Commit

Permalink
fix: improve new event workflow
Browse files Browse the repository at this point in the history
- finish button navigates to dashboard
- removed search button for event programs
- recently added event list:
   - clickable and navigates to edit event page
   - kept in memory until program is changed
   - existing entry updated after an event has been edited
  • Loading branch information
JoakimSM committed Jun 10, 2022
1 parent e55048e commit e78aad3
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const actionTypes = {
RESET_DATA_ENTRY: 'ResetDataEntryForNewEvent',
ADD_NEW_EVENT_NOTE: 'AddNewEventNote',
NEW_EVENT_OPEN_NEW_RELATIONSHIP: 'NewEventOpenNewRelationship',
ADD_NEW_EVENT_LIST_RECORD: 'NewEventListRecordAdd',
SAVE_NEW_EVENT_RELATIONSHIPS_IF_EXISTS: 'SaveNewEventRelationshipsIfExists',
START_SAVE_NEW_EVENT_RELATIONSHIPS: 'StartSaveNewEventRelationships',
NEW_EVENT_RELATIONSHIPS_SAVED: 'NewEventRelationshipsSaved',
Expand Down Expand Up @@ -131,6 +132,7 @@ export const startSaveNewEventAddAnother =
relationshipData: ?Object,
selections: Object,
clientId: string,
listData: Object,
) => {
const actionType = actionTypes.START_SAVE_NEW_EVENT_ADD_ANOTHER;
return actionCreator(actionTypes.START_SAVE_NEW_EVENT_ADD_ANOTHER)({ selections }, {
Expand All @@ -141,7 +143,7 @@ export const startSaveNewEventAddAnother =
data: serverData,
clientId,
},
commit: { type: actionTypes.SAVE_NEW_EVENT_RELATIONSHIPS_IF_EXISTS, meta: { selections, relationshipData, triggerAction: actionType } },
commit: { type: actionTypes.ADD_NEW_EVENT_LIST_RECORD, meta: { selections, relationshipData, triggerAction: actionType, listData } },
rollback: { type: actionTypes.SAVE_FAILED_FOR_NEW_EVENT_ADD_ANOTHER, meta: { selections, clientId } },
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import getDataEntryKey from '../../../../../DataEntry/common/getDataEntryKey';
import convertClientRelationshipToServer from '../../../../../../relationships/convertClientToServer';
import { getRelationshipNewTei } from '../../../../../Pages/NewRelationship/RegisterTei';

import {
newRecentlyAddedEvent,
} from '../../RecentlyAddedEventsList/recentlyAddedEventsList.actions';

import {
prependListItem,
} from '../../RecentlyAddedEventsList';

const dataEntryId = 'singleEvent';
const itemId = 'newEvent';
const dataEntryKey = getDataEntryKey(dataEntryId, itemId);
Expand Down Expand Up @@ -103,13 +111,32 @@ const saveNewEventRelationships = (relationshipData, selections, triggerAction)
return startSaveNewEventRelationships(serverRelationshipData, selections, triggerAction);
};

export const addNewEventListRecordEpic = (action$: InputObservable) =>
action$.pipe(
ofType(newEventDataEntryActionTypes.ADD_NEW_EVENT_LIST_RECORD),
map((action) => {
const { selections, relationshipData, triggerAction, listData: { clientEvent, clientEventValues, listId } } = action.meta;
const eventId = action.payload.response.importSummaries[0].reference;

return batchActions([
{
...action,
type: newEventDataEntryActionTypes.SAVE_NEW_EVENT_RELATIONSHIPS_IF_EXISTS,
meta: { selections, relationshipData, triggerAction },
},
newRecentlyAddedEvent({ ...clientEvent, eventId }, clientEventValues, selections.programId),
prependListItem(listId, eventId, selections.programId),
], newEventDataEntryActionTypes.SAVE_NEW_EVENT_RELATIONSHIPS_IF_EXISTS);
}));


export const saveNewEventRelationshipsIfExistsEpic = (action$: InputObservable) =>
action$.pipe(
ofType(newEventDataEntryActionTypes.SAVE_NEW_EVENT_RELATIONSHIPS_IF_EXISTS),
map(action => action.payload[0]),
map((action) => {
const meta = action.meta;
if (meta.relationshipData) {
if (meta.relationshipData && meta.relationshipData.length) {
const eventId = action.payload.response.importSummaries[0].reference;
const relationshipData = action.meta.relationshipData.map((r) => {
const clientRelationship = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ import {
} from '../actions/dataEntry.actions';

import {
newRecentlyAddedEvent,
} from '../../RecentlyAddedEventsList/recentlyAddedEventsList.actions';

import {
prependListItem,
removeListItem,
} from '../../RecentlyAddedEventsList';

import getDataEntryKey from '../../../../../DataEntry/common/getDataEntryKey';
import { getNewEventServerData, getNewEventClientValues } from './getConvertedNewSingleEvent';
import { listId } from '../../RecentlyAddedEventsList/RecentlyAddedEventsList.const';
Expand All @@ -45,16 +39,6 @@ export const saveNewEventAddAnotherEpic = (action$: InputObservable, store: Redu
const clientEventValues = { ...formClientValues, created: moment().toISOString() };
const relationshipData = state.dataEntriesRelationships[dataEntryKey];
return batchActions([
startSaveNewEventAddAnother(serverData, relationshipData, state.currentSelections, clientEvent.eventId),
newRecentlyAddedEvent(clientEvent, clientEventValues),
prependListItem(listId, clientEvent.eventId),
startSaveNewEventAddAnother(serverData, relationshipData, state.currentSelections, clientEvent.eventId, { clientEvent, clientEventValues, listId }),
], newEventDataEntryBatchActionTypes.SAVE_NEW_EVENT_ADD_ANOTHER_BATCH);
}));

export const saveNewEventAddAnotherFailedEpic = (action$: InputObservable) =>
action$.pipe(
ofType(newEventDataEntryActionTypes.SAVE_FAILED_FOR_NEW_EVENT_ADD_ANOTHER),
map((action) => {
const clientId = action.meta.clientId;
return removeListItem(listId, clientId);
}));
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const buttonDefinitions = {
text: i18n.t('Save and exit'),
onClick: () => { props.onSave(newEventSaveTypes.SAVEANDEXIT); },
}),
[buttonTypes.FINISH]: (props: Props) => ({
[buttonTypes.FINISH]: () => ({
key: buttonTypes.FINISH,
text: i18n.t('Finish'),
onClick: () => { props.onCancel(); },
onClick: () => {
window.location.href = '../';
},
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { withStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import i18n from '@dhis2/d2-i18n';
import { useHistory } from 'react-router';
import OfflineEventsList from '../../../../EventsList/OfflineEventsList/OfflineEventsList.component';
import { listId } from './RecentlyAddedEventsList.const';

Expand All @@ -25,6 +26,7 @@ const styles = (theme: Theme) => ({

const NewEventsList = (props: Props) => {
const { classes, ...passOnProps } = props;
const { push } = useHistory();
const eventsAdded = props.events ? Object.keys(props.events).length : 0;
if (eventsAdded === 0) {
return null;
Expand All @@ -42,6 +44,9 @@ const NewEventsList = (props: Props) => {
noItemsText={i18n.t('No events added')}
emptyListText={i18n.t('No events added')}
{...passOnProps}
onRowClick={({ eventId }) => {
push(`/viewEvent?viewEventId=${eventId}`);
}}
/>
</Paper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export const recentlyAddedEventsActionTypes = {
};

// $FlowFixMe[missing-annot] automated comment
export const newRecentlyAddedEvent = (event, eventValues) =>
actionCreator(recentlyAddedEventsActionTypes.NEW_RECENTLY_ADDED_EVENT)({ event, eventValues });
export const newRecentlyAddedEvent = (event, eventValues, programId) =>
actionCreator(recentlyAddedEventsActionTypes.NEW_RECENTLY_ADDED_EVENT)({ event, eventValues, programId });

export const prependListItem =
(listId: string, itemId: string) =>
actionCreator(recentlyAddedEventsActionTypes.LIST_ITEM_PREPEND)({ listId, itemId });
(listId: string, itemId: string, programId: string) =>
actionCreator(recentlyAddedEventsActionTypes.LIST_ITEM_PREPEND)({ listId, itemId, programId });

export const removeListItem =
(listId: string, itemId: string) =>
actionCreator(recentlyAddedEventsActionTypes.LIST_ITEM_REMOVE)({ listId, itemId });

export const resetList =
(listId: string, columnOrder: any, meta: any, selections: any) =>
actionCreator(recentlyAddedEventsActionTypes.LIST_RESET)({ listId, columnOrder, meta, selections });
(listId: string, columnOrder: any, meta: any, selections: any, programId: string) =>
actionCreator(recentlyAddedEventsActionTypes.LIST_RESET)({ listId, columnOrder, meta, selections, programId });
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export {
} from './DataEntryWrapper/DataEntry/epics/saveNewSingleEvent.epics';
export {
saveNewEventAddAnotherEpic,
saveNewEventAddAnotherFailedEpic,
} from './DataEntryWrapper/DataEntry/epics/saveNewSingleEventAddAnother.epics';

export {
Expand All @@ -39,4 +38,5 @@ export {
saveNewEventRelationshipsIfExistsEpic,
saveNewEventRelationshipFinishedEpic,
teiForNewEventRelationshipSavedEpic,
addNewEventListRecordEpic,
} from './DataEntryWrapper/DataEntry/epics/addRelationshipForNewSingleEvent.epics';
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const styles = theme => ({
color: theme.palette.text.secondary,
fontWeight: theme.typography.fontWeightMedium,
},
dataRow: {
cursor: 'pointer',
'&:hover': {
backgroundColor: '#F1FBFF',
},
},
});

type Column = {
Expand Down Expand Up @@ -150,7 +156,7 @@ class Index extends Component<Props> {
}

renderRows(visibleColumns: Array<Column>) {
const { dataSource, classes, noItemsText, rowIdKey } = this.props;
const { dataSource, classes, noItemsText, rowIdKey, onRowClick } = this.props;

if (!dataSource || dataSource.length === 0) {
const columnsCount = visibleColumns.length;
Expand Down Expand Up @@ -191,7 +197,8 @@ class Index extends Component<Props> {
return (
<Row
key={row[rowIdKey]}
className={classes.row}
className={classNames(classes.row, onRowClick ? classes.dataRow : '')}
onClick={() => onRowClick && onRowClick(row)}
>
{cells}
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,7 @@ const ActionButtonsPlain = ({

{
scopeType !== scopeTypes.TRACKER_PROGRAM ?
<Button
small
secondary
dataTest="find-button"
className={classes.marginRight}
onClick={onFindClickWithoutProgramId}
>
{ i18n.t('Search') }
</Button>
null
:
<DropdownButton
small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const requestSaveEditEventDataEntry = (itemId: string, dataEntryId: strin
actionCreator(actionTypes.REQUEST_SAVE_EDIT_EVENT_DATA_ENTRY)({ itemId, dataEntryId, formFoundation }, { skipLogging: ['formFoundation'] });


export const startSaveEditEventDataEntry = (eventId: string, serverData: Object, selections: Object) =>
export const startSaveEditEventDataEntry = (eventId: string, serverData: Object, selections: Object, listData: Object) =>
actionCreator(actionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY)({ selections }, {
offline: {
effect: {
url: `events/${eventId}`,
method: effectMethods.UPDATE,
data: serverData,
},
commit: { type: actionTypes.EDIT_EVENT_DATA_ENTRY_SAVED, meta: { selections, eventId } },
commit: { type: actionTypes.EDIT_EVENT_DATA_ENTRY_SAVED, meta: { selections, eventId, listData } },
rollback: { type: actionTypes.SAVE_EDIT_EVENT_DATA_ENTRY_FAILED, meta: { selections, eventId } },
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore)

return batchActions([
updateEventContainer(eventContainer, orgUnit),
startSaveEditEventDataEntry(eventId, serverData, state.currentSelections),
startSaveEditEventDataEntry(eventId, serverData, state.currentSelections, { clientEvent: mainDataClientValues, clientEventValues: formClientValues }),
], batchActionTypes.START_SAVE_EDIT_EVENT_DATA_ENTRY_BATCH);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ViewEvent extends Component<Props> {
<div className={classes.container}>
<Button className={classes.showAllEvents} variant="raised" onClick={this.handleGoBackToAllEvents}>
<ChevronLeft />
{i18n.t('Show all events')}
{i18n.t('Back')}
</Button>
<div className={classes.contentContainer}>
<EventDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,63 @@ import {
export const recentlyAddedEventsDesc = createReducerDescription({
[recentlyAddedEventsActionTypes.NEW_RECENTLY_ADDED_EVENT]: (state, action) => {
const newState = { ...state };
const event = action.payload.event;
const { event, programId } = action.payload;
newState[event.eventId] = event;
newState.meta = {
programId,
};
return newState;
},
[recentlyAddedEventsActionTypes.LIST_RESET]: (state, action) => {
const actionListId = action.payload.listId;
const { listId: actionListId, selections: { programId } } = action.payload;
const storedProgramId = state.meta && state.meta.programId;
if (storedProgramId === programId) {
return state;
}
if (actionListId === listId) {
const newState = {};
return newState;
}
return state;
},
EditEventDataEntrySavedForViewSingleEvent: (state, action) => {
const { listData: { clientEvent } } = action.meta;
const { eventId } = clientEvent;
return {
...state,
[eventId]: clientEvent,
};
},
}, 'recentlyAddedEvents', {});

export const recentlyAddedEventsValuesDesc = createReducerDescription({
[recentlyAddedEventsActionTypes.NEW_RECENTLY_ADDED_EVENT]: (state, action) => {
const newState = { ...state };
newState[action.payload.event.eventId] = action.payload.eventValues;
const { eventValues, event: { eventId }, programId } = action.payload;
newState[eventId] = eventValues;
newState.meta = {
programId,
};
return newState;
},

[recentlyAddedEventsActionTypes.LIST_RESET]: (state, action) => {
const actionListId = action.payload.listId;
const { listId: actionListId, selections: { programId } } = action.payload;
const storedProgramId = state.meta && state.meta.programId;
if (storedProgramId === programId) {
return state;
}
if (actionListId === listId) {
const newState = {};
return newState;
}
return state;
},

EditEventDataEntrySavedForViewSingleEvent: (state, action) => {
const { listData: { clientEvent: { eventId }, clientEventValues } } = action.meta;
return {
...state,
[eventId]: clientEventValues,
};
},
}, 'recentlyAddedEventsValues', {});
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ export const workingListsDesc = createReducerDescription({
},
[recentlyAddedEventsActionTypes.LIST_ITEM_PREPEND]: (state, action) => {
const newState = { ...state };
const { listId, itemId } = action.payload;
const { listId, itemId, programId } = action.payload;
newState[listId] = {
order: [itemId, ...(state[listId] ? state[listId].order.slice(0, 19) : [])],
programId,
};
return newState;
},
Expand All @@ -351,6 +352,11 @@ export const workingListsDesc = createReducerDescription({
return newState;
},
[recentlyAddedEventsActionTypes.LIST_RESET]: (state, action) => {
const { listId, selections: { programId } } = action.payload;
const storedProgramId = state[listId] && state[listId].programId;
if (storedProgramId === programId) {
return state;
}
const newState = { ...state };
newState[action.payload.listId] = { order: [] };
return newState;
Expand Down
4 changes: 2 additions & 2 deletions src/epics/trackerCapture.epics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
saveNewEventEpic,
saveNewEventLocationChangeEpic,
saveNewEventAddAnotherEpic,
saveNewEventAddAnotherFailedEpic,
addNoteForNewSingleEventEpic,
openRelationshipForNewSingleEventEpic,
addRelationshipForNewSingleEventEpic,
saveNewEventRelationshipsIfExistsEpic,
saveNewEventRelationshipFinishedEpic,
teiForNewEventRelationshipSavedEpic,
addNewEventListRecordEpic,
} from 'capture-core/components/DataEntries/SingleEventRegistrationEntry';
import {
initEventListEpic,
Expand Down Expand Up @@ -241,7 +241,6 @@ export default combineEpics(
goingOnlineEpic,
includeFiltersWithValueAfterColumnSortingEpic,
saveNewEventAddAnotherEpic,
saveNewEventAddAnotherFailedEpic,
searchRegisteringUnitListEpic,
showRegisteringUnitListIndicatorEpic,
openRelationshipTeiSearchEpic,
Expand Down Expand Up @@ -318,4 +317,5 @@ export default combineEpics(
resetEnrollmentSelectionEpic,
openEnrollmentPageEpic,
checkForDuplicateEpic,
addNewEventListRecordEpic,
);

0 comments on commit e78aad3

Please sign in to comment.