Skip to content

Commit

Permalink
add: donors information history view
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Dec 21, 2023
1 parent 04890c9 commit 7165fc1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
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,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { DonorsVersionView } from './DonorsVersionView';
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;
};
8 changes: 8 additions & 0 deletions src/components/POLine/POLineVersionView/POLineVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PHRESOURCES,
} from '../const';
import { CostVersionView } from './CostVersionView';
import { DonorsVersionView } from './DonorsVersionView';
import { EresourcesVersionView } from './EresourcesVersionView';
import { FundDistributionVersionView } from './FundDistributionVersionView';
import { ItemVersionView } from './ItemVersionView';
Expand Down Expand Up @@ -97,6 +98,13 @@ const POLineVersion = ({ version }) => {
</Row>
</Accordion>

<Accordion
label={<FormattedMessage id="ui-orders.line.accordion.donorInformation" />}
id={ACCORDION_ID.donorsInformation}
>
<DonorsVersionView version={version} />
</Accordion>

<Accordion
label={<FormattedMessage id="ui-orders.line.accordion.vendor" />}
id="Vendor"
Expand Down

0 comments on commit 7165fc1

Please sign in to comment.