-
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.
CM-406: add change log fe for group (#33)
Co-authored-by: Jan <[email protected]>
- Loading branch information
1 parent
71af2b0
commit a89928a
Showing
8 changed files
with
275 additions
and
1 deletion.
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 { GROUP_CHANGELOG_TAB_VALUE } from '../constants'; | ||
|
||
function GroupChangelogTabLabel({ | ||
intl, onChange, tabStyle, isSelected, | ||
}) { | ||
return ( | ||
<Tab | ||
onChange={onChange} | ||
className={tabStyle(GROUP_CHANGELOG_TAB_VALUE)} | ||
selected={isSelected(GROUP_CHANGELOG_TAB_VALUE)} | ||
value={GROUP_CHANGELOG_TAB_VALUE} | ||
label={formatMessage(intl, 'individual', 'groupChangelog.label')} | ||
/> | ||
); | ||
} | ||
|
||
function GroupChangelogTabPanel({ | ||
value, group, | ||
}) { | ||
return ( | ||
<PublishedComponent | ||
pubRef="policyHolder.TabPanel" | ||
module="individual" | ||
index={GROUP_CHANGELOG_TAB_VALUE} | ||
value={value} | ||
> | ||
<PublishedComponent | ||
pubRef="individual.GroupHistorySearcher" | ||
groupId={group?.id} | ||
/> | ||
</PublishedComponent> | ||
); | ||
} | ||
|
||
export { GroupChangelogTabLabel, GroupChangelogTabPanel }; |
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,58 @@ | ||
import React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
import { TextInput } 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 GroupHistoryFilter({ | ||
classes, filters, onChangeFilters, | ||
}) { | ||
const debouncedOnChangeFilters = _debounce(onChangeFilters, DEFAULT_DEBOUNCE_TIME); | ||
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="groupHistory.id" | ||
value={filterTextFieldValue('firstName')} | ||
onChange={onChangeStringFilter('firstName', CONTAINS_LOOKUP)} | ||
/> | ||
</Grid> | ||
<Grid item xs={2} className={classes.item}> | ||
<TextInput | ||
module="individual" | ||
label="groupHistory.head" | ||
value={filterTextFieldValue('head')} | ||
onChange={onChangeStringFilter('head', CONTAINS_LOOKUP)} | ||
/> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
export default injectIntl(withTheme(withStyles(defaultFilterStyles)(GroupHistoryFilter))); |
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,113 @@ | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { injectIntl } from 'react-intl'; | ||
import { | ||
useModulesManager, | ||
useTranslations, | ||
Searcher, | ||
withHistory, | ||
withModulesManager, | ||
} from '@openimis/fe-core'; | ||
import { DEFAULT_PAGE_SIZE, EMPTY_STRING, ROWS_PER_PAGE_OPTIONS } from '../constants'; | ||
import GroupHistoryFilter from './GroupHistoryFilter'; | ||
import { fetchGroupHistory } from '../actions'; | ||
|
||
function GroupHistorySearcher({ | ||
groupId, | ||
}) { | ||
const modulesManager = useModulesManager(); | ||
const dispatch = useDispatch(); | ||
const { formatDateFromISO, formatMessageWithValues } = useTranslations('individual', modulesManager); | ||
|
||
const fetchingGroupHistory = useSelector((state) => state.individual.fetchingGroupHistory); | ||
const fetchedGroupHistory = useSelector((state) => state.individual.fetchedGroupHistory); | ||
const errorGroupHistory = useSelector((state) => state.individual.errorGroupHistory); | ||
const groupHistory = useSelector((state) => state.individual.groupHistory); | ||
const groupHistoryPageInfo = useSelector((state) => state.individual.groupHistoryPageInfo); | ||
const groupHistoryTotalCount = useSelector((state) => state.individual.groupHistoryTotalCount); | ||
const fetch = (params) => dispatch(fetchGroupHistory(params)); | ||
|
||
const headers = () => [ | ||
'groupHistory.id', | ||
'groupHistory.head', | ||
'groupHistory.dateUpdated', | ||
'groupHistory.version', | ||
'groupHistory.jsonExt', | ||
]; | ||
|
||
const itemFormatters = () => [ | ||
(groupHistory) => groupHistory.id, | ||
(groupHistory) => groupHistory.head, | ||
(groupHistory) => (groupHistory.dateUpdated | ||
? formatDateFromISO(groupHistory.dateUpdated) : EMPTY_STRING | ||
), | ||
(groupHistory) => groupHistory.version, | ||
(groupHistory) => groupHistory.jsonExt, | ||
]; | ||
|
||
const rowIdentifier = (groupHistory) => groupHistory.id; | ||
|
||
const sorts = () => [ | ||
['id', false], | ||
['head', true], | ||
['dateUpdated', true], | ||
['version', true], | ||
]; | ||
|
||
const defaultFilters = () => { | ||
const filters = { | ||
isDeleted: { | ||
value: false, | ||
filter: 'isDeleted: false', | ||
}, | ||
}; | ||
if (groupId !== null && groupId !== undefined) { | ||
filters.groupId = { | ||
value: groupId, | ||
filter: `id: "${groupId}"`, | ||
}; | ||
} | ||
return filters; | ||
}; | ||
|
||
const groupHistoryFilter = (props) => ( | ||
<GroupHistoryFilter | ||
intl={props.intl} | ||
classes={props.classes} | ||
filters={props.filters} | ||
onChangeFilters={props.onChangeFilters} | ||
/> | ||
); | ||
|
||
return ( | ||
<div> | ||
<Searcher | ||
module="individual" | ||
FilterPane={groupHistoryFilter} | ||
fetch={fetch} | ||
items={groupHistory} | ||
itemsPageInfo={groupHistoryPageInfo} | ||
fetchingItems={fetchingGroupHistory} | ||
fetchedItems={fetchedGroupHistory} | ||
errorItems={errorGroupHistory} | ||
tableTitle={formatMessageWithValues('groupHistoryList.searcherResultsTitle', { | ||
groupHistoryTotalCount, | ||
})} | ||
headers={headers} | ||
itemFormatters={itemFormatters} | ||
sorts={sorts} | ||
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS} | ||
defaultPageSize={DEFAULT_PAGE_SIZE} | ||
defaultOrderBy="id" | ||
rowIdentifier={rowIdentifier} | ||
defaultFilters={defaultFilters()} | ||
cacheFiltersKey="groupHistoryFilterCache" | ||
resetFiltersOnUnmount | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default withHistory( | ||
withModulesManager(injectIntl((GroupHistorySearcher))), | ||
); |
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
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