-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add change history to area search (#467)
- Loading branch information
1 parent
9709134
commit ab36159
Showing
10 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
src/areaSearch/components/AreaSearchApplicationAuditLog.js
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,130 @@ | ||
//@flow | ||
import React, {Fragment, PureComponent} from 'react'; | ||
import {connect} from 'react-redux'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
import AuditLogTable from '$components/auditLog/AuditLogTable'; | ||
import Divider from '$components/content/Divider'; | ||
import Loader from '$components/loader/Loader'; | ||
import LoaderWrapper from '$components/loader/LoaderWrapper'; | ||
import Pagination from '$components/table/Pagination'; | ||
import TableWrapper from '$components/table/TableWrapper'; | ||
import Title from '$components/content/Title'; | ||
import {fetchAuditLogByAreaSearch} from '$src/auditLog/actions'; | ||
import {LIST_TABLE_PAGE_SIZE} from '$src/constants'; | ||
import { | ||
AreaSearchFieldPaths, | ||
AreaSearchFieldTitles, | ||
} from '$src/areaSearch/enums'; | ||
import {getApiResponseCount, getApiResponseMaxPage, getApiResponseResults} from '$util/helpers'; | ||
import {getUiDataLeaseKey} from '$src/uiData/helpers'; | ||
import {getAuditLogByAreaSearch, getIsFetchingByAreaSearch} from '$src/auditLog/selectors'; | ||
import {getIsEditMode} from '$src/leases/selectors'; | ||
|
||
import type {AuditLogList} from '$src/auditLog/types'; | ||
|
||
type Props = { | ||
auditLogList: AuditLogList, | ||
fetchAuditLogByAreaSearch: Function, | ||
isEditMode: boolean, | ||
isFetching: boolean, | ||
areaSearchId: string, | ||
} | ||
|
||
type State = { | ||
activePage: number, | ||
auditLogItems: Array<Object>, | ||
auditLogList: AuditLogList, | ||
count: number, | ||
maxPage: number, | ||
} | ||
|
||
class AreaSearchApplicationAuditLog extends PureComponent<Props, State> { | ||
state = { | ||
activePage: 1, | ||
auditLogItems: [], | ||
auditLogList: {}, | ||
count: 0, | ||
maxPage: 0, | ||
} | ||
componentDidMount() { | ||
const {fetchAuditLogByAreaSearch, areaSearchId} = this.props; | ||
|
||
fetchAuditLogByAreaSearch({ | ||
id: areaSearchId, | ||
limit: LIST_TABLE_PAGE_SIZE, | ||
}); | ||
} | ||
|
||
static getDerivedStateFromProps(props: Props, state: State) { | ||
const newState = {}; | ||
|
||
if(props.auditLogList !== state.auditLogList) { | ||
newState.auditLogList = props.auditLogList; | ||
newState.auditLogItems = getApiResponseResults(props.auditLogList); | ||
newState.count = getApiResponseCount(props.auditLogList); | ||
newState.maxPage = getApiResponseMaxPage(props.auditLogList, LIST_TABLE_PAGE_SIZE); | ||
} | ||
|
||
return !isEmpty(newState) ? newState : null; | ||
} | ||
|
||
handlePageClick = (page: number) => { | ||
const {fetchAuditLogByAreaSearch, areaSearchId} = this.props; | ||
|
||
this.setState({activePage: page}, () => { | ||
const payload: any = { | ||
id: areaSearchId, | ||
limit: LIST_TABLE_PAGE_SIZE, | ||
}; | ||
|
||
if(page > 1) { | ||
payload.offset = (page - 1) * LIST_TABLE_PAGE_SIZE; | ||
} | ||
|
||
fetchAuditLogByAreaSearch(payload); | ||
}); | ||
} | ||
|
||
render() { | ||
const {isEditMode, isFetching} = this.props; | ||
const {activePage, auditLogItems, maxPage} = this.state; | ||
|
||
return( | ||
<Fragment> | ||
<Title enableUiDataEdit={isEditMode} uiDataKey={getUiDataLeaseKey(AreaSearchFieldPaths.AUDIT_LOG)}> | ||
{AreaSearchFieldTitles.AUDIT_LOG} | ||
</Title> | ||
<Divider /> | ||
|
||
<TableWrapper> | ||
{isFetching && | ||
<LoaderWrapper className='relative-overlay-wrapper'><Loader isLoading={isFetching} /></LoaderWrapper> | ||
} | ||
|
||
<AuditLogTable | ||
items={auditLogItems} | ||
/> | ||
<Pagination | ||
activePage={activePage} | ||
maxPage={maxPage} | ||
onPageClick={this.handlePageClick} | ||
/> | ||
</TableWrapper> | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
(state, props: Props) => { | ||
return { | ||
auditLogList: getAuditLogByAreaSearch(state, props.areaSearchId), | ||
isEditMode: getIsEditMode(state), | ||
isFetching: getIsFetchingByAreaSearch(state, props.areaSearchId), | ||
}; | ||
}, | ||
{ | ||
fetchAuditLogByAreaSearch, | ||
} | ||
)(AreaSearchApplicationAuditLog); |
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
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
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