Skip to content

Commit

Permalink
UISACQCOMP-231: Display system change label for version cards (#836)
Browse files Browse the repository at this point in the history
* UISACQCOMP-231: Display system change label for version cards

* test: fix failing test

* refactor: simplify changed version card message logic

* revert test changes
  • Loading branch information
alisher-epam authored and usavkov-epam committed Dec 4, 2024
1 parent 0aaf3a0 commit 6ed1520
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## (6.1.0 IN PROGRESS)

* Add `useDebouncedQuery` hook to fix endless request for `DynamicSelection` component. Refs UISACQCOMP-233.
* Display system change label for version cards. Refs UISACQCOMP-231.

## [6.0.1](https://github.com/folio-org/stripes-acq-components/tree/v6.0.1) (2024-11-14)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v6.0.0...v6.0.1)
Expand Down
75 changes: 47 additions & 28 deletions lib/VersionHistory/VersionCard/VersionCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import css from './VersionCard.css';
const itemFormatter = (item, i) => (<li key={i} className={css.changedRecord}>{item}</li>);

const VersionCard = ({
changedFields,
changedFields = [],
id,
isCurrent,
isLatest,
isOriginal,
onSelect,
source,
title,
Expand Down Expand Up @@ -62,6 +63,49 @@ const VersionCard = ({
</Tooltip>
), [id, isCurrent, onSelectVersion, tooltip]);

const message = useMemo(() => {
if (isOriginal) {
return (
<b>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.version.original"
tagName="em"
/>
</b>
);
}

if (changedFields?.length) {
return (
<>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.changed"
tagName="b"
/>
<List
items={uniq(changedFields)}
itemFormatter={itemFormatter}
listClass={css.changedRecordsList}
listStyle="bullets"
/>
</>
);
}

return (
<>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.changed"
tagName="b"
/>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.systemChange"
tagName="div"
/>
</>
);
}, [changedFields, isOriginal]);

return (
<Card
id={`version-card-${id}`}
Expand All @@ -84,33 +128,7 @@ const VersionCard = ({
</span>
)}

<span>
{
changedFields
? (
<>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.changed"
tagName="b"
/>
<List
items={uniq(changedFields)}
itemFormatter={itemFormatter}
listClass={css.changedRecordsList}
listStyle="bullets"
/>
</>
)
: (
<b>
<FormattedMessage
id="stripes-acq-components.versionHistory.card.version.original"
tagName="em"
/>
</b>
)
}
</span>
<span>{message}</span>
</Card>
);
};
Expand All @@ -120,6 +138,7 @@ VersionCard.propTypes = {
id: PropTypes.string.isRequired,
isCurrent: PropTypes.bool,
isLatest: PropTypes.bool,
isOriginal: PropTypes.bool,
onSelect: PropTypes.func.isRequired,
source: PropTypes.node.isRequired,
title: PropTypes.node.isRequired,
Expand Down
13 changes: 6 additions & 7 deletions lib/VersionHistory/VersionHistoryPane/VersionHistoryPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const VersionHistoryPane = ({
isLoading: isLoadingProp,
onClose,
onSelectVersion,
hiddenFields,
hiddenFields = [],
labelsMap,
versions,
}) => {
Expand Down Expand Up @@ -54,7 +54,7 @@ const VersionHistoryPane = ({
const versionCards = useMemo(() => (
versionsToDisplay.map(({
id: versionId,
actionDate,
eventDate,
userId,
}, i) => {
const user = usersMap[userId];
Expand All @@ -65,6 +65,8 @@ const VersionHistoryPane = ({
hiddenFields,
);

const isOriginal = i === versionsToDisplay.length - 1 && !changedFields?.length;

const source = (
<FormattedMessage
id="stripes-components.metaSection.source"
Expand All @@ -82,8 +84,9 @@ const VersionHistoryPane = ({
id={versionId}
isCurrent={versionId === currentVersion}
isLatest={i === 0}
isOriginal={isOriginal}
onSelect={onSelectVersion}
title={<FolioFormattedTime dateString={actionDate} />}
title={<FolioFormattedTime dateString={eventDate} />}
source={source}
changedFields={changedFields}
/>
Expand Down Expand Up @@ -143,8 +146,4 @@ VersionHistoryPane.propTypes = {
versions: PropTypes.arrayOf(PropTypes.object).isRequired,
};

VersionHistoryPane.defaultProps = {
hiddenFields: [],
};

export default memo(VersionHistoryPane);
7 changes: 7 additions & 0 deletions lib/VersionHistory/getVersionMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import get from 'lodash/get';

export const getVersionMetadata = (version, entity) => ({
...get(entity, 'metadata', {}),
updatedByUserId: version?.userId,
updatedDate: version?.eventDate,
});
1 change: 1 addition & 0 deletions translations/stripes-acq-components/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
"validation.shouldBeGreaterThan": "Value must be greater than or equal to {minNumber}",

"versionHistory.card.changed": "Changed",
"versionHistory.card.systemChange": "System maintenance update",
"versionHistory.card.select.tooltip": "View this version",
"versionHistory.card.version.current": "Current version",
"versionHistory.card.version.original": "Original version",
Expand Down

0 comments on commit 6ed1520

Please sign in to comment.