-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from openimis/feature/CM-381
CM-381: Create change log tab for individual
- Loading branch information
Showing
8 changed files
with
331 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import { Tab } from '@material-ui/core'; | ||
import { formatMessage, PublishedComponent } from '@openimis/fe-core'; | ||
import { INDIVIDUAL_CHANGELOG_TAB_VALUE } from '../constants'; | ||
|
||
function IndividalChangelogTabLabel({ | ||
intl, onChange, tabStyle, isSelected, | ||
}) { | ||
return ( | ||
<Tab | ||
onChange={onChange} | ||
className={tabStyle(INDIVIDUAL_CHANGELOG_TAB_VALUE)} | ||
selected={isSelected(INDIVIDUAL_CHANGELOG_TAB_VALUE)} | ||
value={INDIVIDUAL_CHANGELOG_TAB_VALUE} | ||
label={formatMessage(intl, 'individual', 'individualChangelog.label')} | ||
/> | ||
); | ||
} | ||
|
||
function IndividalChangelogTabPanel({ | ||
value, individual, | ||
}) { | ||
return ( | ||
<PublishedComponent | ||
pubRef="policyHolder.TabPanel" | ||
module="individual" | ||
index={INDIVIDUAL_CHANGELOG_TAB_VALUE} | ||
value={value} | ||
> | ||
<PublishedComponent | ||
pubRef="individual.IndividualHistorySearcher" | ||
individualId={individual?.id} | ||
/> | ||
</PublishedComponent> | ||
); | ||
} | ||
|
||
export { IndividalChangelogTabLabel, IndividalChangelogTabPanel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
import { TextInput, PublishedComponent } from '@openimis/fe-core'; | ||
import { Grid } from '@material-ui/core'; | ||
import { withTheme, withStyles } from '@material-ui/core/styles'; | ||
import _debounce from 'lodash/debounce'; | ||
import { CONTAINS_LOOKUP, DEFAULT_DEBOUNCE_TIME, EMPTY_STRING } from '../constants'; | ||
import { defaultFilterStyles } from '../util/styles'; | ||
|
||
function IndividualHistoryFilter({ | ||
classes, filters, onChangeFilters, | ||
}) { | ||
const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFAULT_DEBOUNCE_TIME); | ||
|
||
const filterValue = (filterName) => filters?.[filterName]?.value; | ||
|
||
const filterTextFieldValue = (filterName) => filters?.[filterName]?.value ?? EMPTY_STRING; | ||
|
||
const onChangeStringFilter = (filterName, lookup = null) => (value) => { | ||
if (lookup) { | ||
debouncedOnChangeFilters([ | ||
{ | ||
id: filterName, | ||
value, | ||
filter: `${filterName}_${lookup}: "${value}"`, | ||
}, | ||
]); | ||
} else { | ||
onChangeFilters([ | ||
{ | ||
id: filterName, | ||
value, | ||
filter: `${filterName}: "${value}"`, | ||
}, | ||
]); | ||
} | ||
}; | ||
|
||
return ( | ||
<Grid container className={classes.form}> | ||
<Grid item xs={2} className={classes.item}> | ||
<TextInput | ||
module="individual" | ||
label="individualHistory.firstName" | ||
value={filterTextFieldValue('firstName')} | ||
onChange={onChangeStringFilter('firstName', CONTAINS_LOOKUP)} | ||
/> | ||
</Grid> | ||
<Grid item xs={2} className={classes.item}> | ||
<TextInput | ||
module="individual" | ||
label="individualHistory.lastName" | ||
value={filterTextFieldValue('lastName')} | ||
onChange={onChangeStringFilter('lastName', CONTAINS_LOOKUP)} | ||
/> | ||
</Grid> | ||
<Grid item xs={2} className={classes.item}> | ||
<PublishedComponent | ||
pubRef="core.DatePicker" | ||
module="individual" | ||
label="individualHistory.dob" | ||
value={filterValue('dob')} | ||
onChange={(v) => onChangeFilters([ | ||
{ | ||
id: 'dob', | ||
value: v, | ||
filter: `dob: "${v}"`, | ||
}, | ||
])} | ||
/> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
export default injectIntl(withTheme(withStyles(defaultFilterStyles)(IndividualHistoryFilter))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
import { | ||
withModulesManager, | ||
formatMessageWithValues, | ||
Searcher, | ||
formatDateFromISO, | ||
withHistory, | ||
} from '@openimis/fe-core'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { fetchIndividualHistory } from '../actions'; | ||
import { | ||
DEFAULT_PAGE_SIZE, | ||
ROWS_PER_PAGE_OPTIONS, | ||
EMPTY_STRING, | ||
} from '../constants'; | ||
import IndividualHistoryFilter from './IndividualHistoryFilter'; | ||
|
||
function IndividualHistorySearcher({ | ||
intl, | ||
modulesManager, | ||
individualHistory, | ||
fetchIndividualHistory, | ||
individualHistoryPageInfo, | ||
fetchingIndividualHistory, | ||
fetchedIndividualHistory, | ||
errorIndividualHistory, | ||
individualHistoryTotalCount, | ||
individualId, | ||
}) { | ||
const fetch = (params) => fetchIndividualHistory(params); | ||
|
||
const headers = () => { | ||
const headers = [ | ||
'individualHistory.firstName', | ||
'individualHistory.lastName', | ||
'individualHistory.dob', | ||
'individualHistory.dateUpdated', | ||
'individualHistory.version', | ||
'individualHistory.jsonExt', | ||
]; | ||
return headers; | ||
}; | ||
|
||
const itemFormatters = () => { | ||
const formatters = [ | ||
(individualHistory) => individualHistory.firstName, | ||
(individualHistory) => individualHistory.lastName, | ||
(individualHistory) => (individualHistory.dob | ||
? formatDateFromISO(modulesManager, intl, individualHistory.dob) : EMPTY_STRING | ||
), | ||
(individualHistory) => (individualHistory.dateUpdated | ||
? formatDateFromISO(modulesManager, intl, individualHistory.dateUpdated) : EMPTY_STRING | ||
), | ||
(individualHistory) => individualHistory.version, | ||
(individualHistory) => individualHistory.jsonExt, | ||
]; | ||
return formatters; | ||
}; | ||
|
||
const rowIdentifier = (individualHistory) => individualHistory.id; | ||
|
||
const sorts = () => [ | ||
['firstName', true], | ||
['lastName', true], | ||
['dob', true], | ||
['dateUpdated', true], | ||
['version', true], | ||
]; | ||
|
||
const defaultFilters = () => { | ||
const filters = { | ||
isDeleted: { | ||
value: false, | ||
filter: 'isDeleted: false', | ||
}, | ||
}; | ||
if (individualId !== null && individualId !== undefined) { | ||
filters.individualId = { | ||
value: individualId, | ||
filter: `id: "${individualId}"`, | ||
}; | ||
} | ||
return filters; | ||
}; | ||
|
||
const individualHistoryFilter = (props) => ( | ||
<IndividualHistoryFilter | ||
intl={props.intl} | ||
classes={props.classes} | ||
filters={props.filters} | ||
onChangeFilters={props.onChangeFilters} | ||
/> | ||
); | ||
|
||
return ( | ||
<div> | ||
<Searcher | ||
module="individual" | ||
FilterPane={individualHistoryFilter} | ||
fetch={fetch} | ||
items={individualHistory} | ||
itemsPageInfo={individualHistoryPageInfo} | ||
fetchingItems={fetchingIndividualHistory} | ||
fetchedItems={fetchedIndividualHistory} | ||
errorItems={errorIndividualHistory} | ||
tableTitle={formatMessageWithValues(intl, 'individual', 'individualHistoryList.searcherResultsTitle', { | ||
individualHistoryTotalCount, | ||
})} | ||
headers={headers} | ||
itemFormatters={itemFormatters} | ||
sorts={sorts} | ||
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} | ||
defaultPageSize={DEFAULT_PAGE_SIZE} | ||
defaultOrderBy="lastName" | ||
rowIdentifier={rowIdentifier} | ||
defaultFilters={defaultFilters()} | ||
cacheFiltersKey="individualHistoryFilterChache" | ||
resetFiltersOnUnmount | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
fetchingIndividualHistory: state.individual.fetchingIndividualHistory, | ||
fetchedIndividualHistory: state.individual.fetchedIndividualHistory, | ||
errorIndividualHistory: state.individual.errorIndividualHistory, | ||
individualHistory: state.individual.individualHistory, | ||
individualHistoryPageInfo: state.individual.individualHistoryPageInfo, | ||
individualHistoryTotalCount: state.individual.individualHistoryTotalCount, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => bindActionCreators( | ||
{ | ||
fetchIndividualHistory, | ||
}, | ||
dispatch, | ||
); | ||
|
||
export default withHistory( | ||
withModulesManager(injectIntl(connect(mapStateToProps, mapDispatchToProps)(IndividualHistorySearcher))), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.