Skip to content

Commit

Permalink
CM-158: fix download and switching tabs (#23)
Browse files Browse the repository at this point in the history
* CM-158: fix download and switching tabs

* CM-158: fix eslint
  • Loading branch information
jdolkowski authored Jul 19, 2023
1 parent fc68e04 commit 9d92755
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
22 changes: 21 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
formatGQLString,
} from '@openimis/fe-core';
import { ACTION_TYPE } from './reducer';
import { ERROR, REQUEST, SUCCESS } from './util/action-type';
import {
CLEAR, ERROR, REQUEST, SUCCESS,
} from './util/action-type';

const INDIVIDUAL_FULL_PROJECTION = [
'id',
Expand Down Expand Up @@ -204,3 +206,21 @@ export function downloadGroupIndividuals(params) {
}`;
return graphql(payload, ACTION_TYPE.GROUP_INDIVIDUAL_EXPORT);
}

export const clearGroupIndividualExport = () => (dispatch) => {
dispatch({
type: CLEAR(ACTION_TYPE.GROUP_INDIVIDUAL_EXPORT),
});
};

export const clearIndividualExport = () => (dispatch) => {
dispatch({
type: CLEAR(ACTION_TYPE.INDIVIDUAL_EXPORT),
});
};

export const clearGroupExport = () => (dispatch) => {
dispatch({
type: CLEAR(ACTION_TYPE.GROUP_EXPORT),
});
};
9 changes: 8 additions & 1 deletion src/components/GroupIndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
import EditIcon from '@material-ui/icons/Edit';
import DeleteIcon from '@material-ui/icons/Delete';
import {
fetchGroupIndividuals, deleteGroupIndividual, downloadGroupIndividuals, updateGroupIndividual,
fetchGroupIndividuals,
deleteGroupIndividual,
clearGroupIndividualExport,
downloadGroupIndividuals,
updateGroupIndividual,
} from '../actions';
import {
DEFAULT_PAGE_SIZE,
Expand Down Expand Up @@ -56,6 +60,7 @@ function GroupIndividualSearcher({
updateGroupIndividual,
groupIndividualsPageInfo,
groupIndividualsTotalCount,
clearGroupIndividualExport,
groupId,
downloadGroupIndividuals,
groupIndividualExport,
Expand Down Expand Up @@ -231,6 +236,7 @@ function GroupIndividualSearcher({
groupIndividualExport,
`${formatMessage(intl, 'individual', 'export.filename.individuals')}.csv`,
)();
clearGroupIndividualExport();
}
}, [groupIndividualExport]);

Expand Down Expand Up @@ -332,6 +338,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators(
fetchGroupIndividuals,
updateGroupIndividual,
deleteGroupIndividual,
clearGroupIndividualExport,
downloadGroupIndividuals,
coreConfirm,
clearConfirm,
Expand Down
7 changes: 6 additions & 1 deletion src/components/GroupSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
} from '@material-ui/core';
import EditIcon from '@material-ui/icons/Edit';
import DeleteIcon from '@material-ui/icons/Delete';
import { deleteGroup, downloadGroups, fetchGroups } from '../actions';
import {
deleteGroup, downloadGroups, fetchGroups, clearGroupExport,
} from '../actions';
import {
DEFAULT_PAGE_SIZE,
ROWS_PER_PAGE_OPTIONS,
Expand All @@ -48,6 +50,7 @@ function GroupSearcher({
deleteGroup,
confirmed,
submittingMutation,
clearGroupExport,
mutation,
coreConfirm,
clearConfirm,
Expand Down Expand Up @@ -169,6 +172,7 @@ function GroupSearcher({
useEffect(() => {
if (groupExport) {
downloadExport(groupExport, `${formatMessage(intl, 'individual', 'export.filename.groups')}.csv`)();
clearGroupExport();
}
}, [groupExport]);

Expand Down Expand Up @@ -255,6 +259,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators(
{
fetchGroups,
downloadGroups,
clearGroupExport,
deleteGroup,
coreConfirm,
clearConfirm,
Expand Down
7 changes: 6 additions & 1 deletion src/components/IndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
} from '@material-ui/core';
import EditIcon from '@material-ui/icons/Edit';
import DeleteIcon from '@material-ui/icons/Delete';
import { fetchIndividuals, deleteIndividual, downloadIndividuals } from '../actions';
import {
fetchIndividuals, deleteIndividual, downloadIndividuals, clearIndividualExport,
} from '../actions';
import {
DEFAULT_PAGE_SIZE,
ROWS_PER_PAGE_OPTIONS,
Expand Down Expand Up @@ -52,6 +54,7 @@ function IndividualSearcher({
individuals,
individualsPageInfo,
individualsTotalCount,
clearIndividualExport,
groupId,
downloadIndividuals,
individualExport,
Expand Down Expand Up @@ -175,6 +178,7 @@ function IndividualSearcher({
useEffect(() => {
if (individualExport) {
downloadExport(individualExport, `${formatMessage(intl, 'individual', 'export.filename.individuals')}.csv`)();
clearIndividualExport();
}
}, [individualExport]);

Expand Down Expand Up @@ -275,6 +279,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators(
fetchIndividuals,
deleteIndividual,
downloadIndividuals,
clearIndividualExport,
coreConfirm,
clearConfirm,
journalize,
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import GroupsPage from './pages/GroupsPage';
import GroupPage from './pages/GroupPage';
import { IndividualsListTabLabel, IndividualsListTabPanel } from './components/IndividualsListTab';
import GroupIndividualSearcher from './components/GroupIndividualSearcher';
import { downloadIndividuals, fetchIndividuals } from './actions';
import { clearIndividualExport, downloadIndividuals, fetchIndividuals } from './actions';

const ROUTE_INDIVIDUALS = 'individuals';
const ROUTE_INDIVIDUAL = 'individuals/individual';
Expand All @@ -40,6 +40,7 @@ const DEFAULT_CONFIG = {
{ key: 'individual.GroupIndividualSearcher', ref: GroupIndividualSearcher },
{ key: 'individual.actions.fetchIndividuals', ref: fetchIndividuals },
{ key: 'individual.actions.downloadIndividuals', ref: downloadIndividuals },
{ key: 'individual.actions.clearIndividualExport', ref: clearIndividualExport },
],
'individual.TabPanel.label': [
IndividualsListTabLabel,
Expand Down
31 changes: 30 additions & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
pageInfo,
decodeId,
} from '@openimis/fe-core';
import { REQUEST, SUCCESS, ERROR } from './util/action-type';
import {
REQUEST, SUCCESS, ERROR, CLEAR,
} from './util/action-type';

export const ACTION_TYPE = {
MUTATION: 'INDIVIDUAL_MUTATION',
Expand Down Expand Up @@ -306,6 +308,33 @@ function reducer(
fetchingGroupIndividualExport: false,
errorGroupIndividualExport: formatServerError(action.payload),
};
case CLEAR(ACTION_TYPE.GROUP_EXPORT):
return {
...state,
fetchingGroupExport: false,
fetchedGroupExport: false,
groupExport: null,
groupExportPageInfo: {},
errorGroupExport: null,
};
case CLEAR(ACTION_TYPE.GROUP_INDIVIDUAL_EXPORT):
return {
...state,
fetchingGroupIndividualExport: false,
fetchedGroupIndividualExport: false,
groupIndividualExport: null,
groupIndividualExportPageInfo: {},
errorGroupIndividualExport: null,
};
case CLEAR(ACTION_TYPE.INDIVIDUAL_EXPORT):
return {
...state,
fetchingIndividualExport: false,
fetchedIndividualExport: false,
individualExport: null,
individualExportPageInfo: {},
errorIndividualExport: null,
};
case REQUEST(ACTION_TYPE.MUTATION):
return dispatchMutationReq(state, action);
case ERROR(ACTION_TYPE.MUTATION):
Expand Down
1 change: 1 addition & 0 deletions src/util/action-type.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const REQUEST = (actionTypeName) => `${actionTypeName}_REQ`;
export const SUCCESS = (actionTypeName) => `${actionTypeName}_RESP`;
export const ERROR = (actionTypeName) => `${actionTypeName}_ERR`;
export const CLEAR = (actionTypeName) => `${actionTypeName}_CLEAR`;

0 comments on commit 9d92755

Please sign in to comment.