-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: donors information history view
- Loading branch information
1 parent
04890c9
commit 7165fc1
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/components/POLine/POLineVersionView/DonorsVersionView/DonorsVersionView.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,53 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
useCallback, | ||
useContext, | ||
useMemo, | ||
} from 'react'; | ||
|
||
import { | ||
DonorsListContainer, | ||
VersionViewContext, | ||
} from '@folio/stripes-acq-components'; | ||
import { TextLink } from '@folio/stripes/components'; | ||
|
||
import { getDonorUrl } from './utils'; | ||
|
||
export const DonorsVersionView = ({ version }) => { | ||
const donorOrganizationIds = version?.donorOrganizationIds; | ||
const versionContext = useContext(VersionViewContext); | ||
|
||
const changedDonorIds = useMemo(() => { | ||
const changedDonors = versionContext?.changes?.filter((change) => { | ||
return change.path.startsWith('donorOrganizationIds'); | ||
}); | ||
const donorIds = changedDonors.map(({ values }) => values.filter(Boolean)); | ||
|
||
return donorIds.flat(); | ||
}, [versionContext?.changes]); | ||
|
||
const renderKeyValueComponent = useCallback(({ value, id, asLink = false }) => { | ||
const content = asLink ? <TextLink to={getDonorUrl(id)}>{value}</TextLink> : value; | ||
const isUpdated = changedDonorIds?.includes(id); | ||
|
||
const displayValue = isUpdated ? <mark>{content}</mark> : content; | ||
|
||
return displayValue; | ||
}, [changedDonorIds]); | ||
|
||
const formatter = { | ||
name: ({ name, id }) => renderKeyValueComponent({ value: name, id, asLink: true }), | ||
code: ({ code, id }) => renderKeyValueComponent({ value: code, id }), | ||
}; | ||
|
||
return ( | ||
<DonorsListContainer | ||
donorOrganizationIds={donorOrganizationIds} | ||
formatter={formatter} | ||
/> | ||
); | ||
}; | ||
|
||
DonorsVersionView.propTypes = { | ||
version: PropTypes.object.isRequired, | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/POLine/POLineVersionView/DonorsVersionView/index.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 @@ | ||
export { DonorsVersionView } from './DonorsVersionView'; |
7 changes: 7 additions & 0 deletions
7
src/components/POLine/POLineVersionView/DonorsVersionView/utils.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,7 @@ | ||
export const getDonorUrl = (orgId) => { | ||
if (orgId) { | ||
return `/organizations/view/${orgId}`; | ||
} | ||
|
||
return undefined; | ||
}; |
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