-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UISACQCOMP-230 Move reusable version history components to the ACQ lib
- Loading branch information
1 parent
7f664e2
commit 2b08ec8
Showing
12 changed files
with
176 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
40 changes: 40 additions & 0 deletions
40
lib/VersionHistory/components/VersionCheckbox/VersionCheckbox.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,40 @@ | ||
import PropTypes from 'prop-types'; | ||
import { useContext, useMemo } from 'react'; | ||
|
||
import { Checkbox } from '@folio/stripes/components'; | ||
|
||
import { VersionViewContext } from '../../VersionViewContext'; | ||
|
||
export const VersionCheckbox = ({ | ||
checked, | ||
label, | ||
name, | ||
...props | ||
}) => { | ||
const versionContext = useContext(VersionViewContext); | ||
const isUpdated = useMemo(() => ( | ||
versionContext?.paths?.includes(name) | ||
), [name, versionContext?.paths]); | ||
|
||
const checkboxLabel = isUpdated ? <mark>{label}</mark> : label; | ||
|
||
return ( | ||
<Checkbox | ||
checked={Boolean(checked)} | ||
disabled | ||
label={checkboxLabel} | ||
vertical | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
VersionCheckbox.defaultProps = { | ||
checked: false, | ||
}; | ||
|
||
VersionCheckbox.propTypes = { | ||
checked: PropTypes.bool, | ||
label: PropTypes.node.isRequired, | ||
name: PropTypes.string.isRequired, | ||
}; |
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 { VersionCheckbox } from './VersionCheckbox'; |
49 changes: 49 additions & 0 deletions
49
lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.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,49 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
useContext, | ||
useMemo, | ||
} from 'react'; | ||
|
||
import { | ||
KeyValue, | ||
NoValue, | ||
} from '@folio/stripes/components'; | ||
|
||
import { VersionViewContext } from '../../VersionViewContext'; | ||
|
||
export const VersionKeyValue = ({ | ||
children, | ||
label, | ||
multiple, | ||
name, | ||
value, | ||
}) => { | ||
const versionContext = useContext(VersionViewContext); | ||
const isUpdated = useMemo(() => ( | ||
multiple | ||
? versionContext?.paths?.find((field) => new RegExp(`^${name}\\[\\d\\]$`).test(field)) | ||
: versionContext?.paths?.includes(name) | ||
), [multiple, name, versionContext?.paths]); | ||
|
||
const content = (children || value) || <NoValue />; | ||
const displayValue = isUpdated ? <mark>{content}</mark> : content; | ||
|
||
return ( | ||
<KeyValue | ||
label={label} | ||
value={displayValue} | ||
/> | ||
); | ||
}; | ||
|
||
VersionKeyValue.defaultProps = { | ||
multiple: false, | ||
}; | ||
|
||
VersionKeyValue.propTypes = { | ||
children: PropTypes.node, | ||
label: PropTypes.node.isRequired, | ||
multiple: PropTypes.bool, | ||
name: PropTypes.string.isRequired, | ||
value: PropTypes.node, | ||
}; |
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 { VersionKeyValue } from './VersionKeyValue'; |
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,76 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
memo, | ||
useMemo, | ||
} from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
Layout, | ||
LoadingPane, | ||
Pane, | ||
PaneMenu, | ||
} from '@folio/stripes/components'; | ||
|
||
import { TagsBadge } from '../../../Tags'; | ||
import { VersionHistoryButton } from '../../VersionHistoryButton'; | ||
|
||
const VersionView = ({ | ||
children, | ||
id, | ||
isLoading, | ||
onClose, | ||
tags, | ||
versionId, | ||
...props | ||
}) => { | ||
const isVersionExist = Boolean(versionId && !isLoading); | ||
|
||
const lastMenu = useMemo(() => ( | ||
<PaneMenu> | ||
{tags && ( | ||
<TagsBadge | ||
disabled | ||
tagsQuantity={tags.length} | ||
/> | ||
)} | ||
<VersionHistoryButton disabled /> | ||
</PaneMenu> | ||
), [tags]); | ||
|
||
if (isLoading) return <LoadingPane />; | ||
|
||
return ( | ||
<Pane | ||
id={`${id}-version-view`} | ||
defaultWidth="fill" | ||
onClose={onClose} | ||
lastMenu={lastMenu} | ||
{...props} | ||
> | ||
{ | ||
isVersionExist | ||
? children | ||
: ( | ||
<Layout | ||
element="span" | ||
className="flex centerContent" | ||
> | ||
<FormattedMessage id="stripes-acq-components.versionHistory.noVersion" /> | ||
</Layout> | ||
) | ||
} | ||
</Pane> | ||
); | ||
}; | ||
|
||
VersionView.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
id: PropTypes.string.isRequired, | ||
isLoading: PropTypes.bool, | ||
onClose: PropTypes.func, | ||
tags: PropTypes.arrayOf(PropTypes.object), | ||
versionId: PropTypes.string, | ||
}; | ||
|
||
export default memo(VersionView); |
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 { default as VersionView } from './VersionView'; |
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,3 @@ | ||
export { VersionCheckbox } from './VersionCheckbox'; | ||
export { VersionKeyValue } from './VersionKeyValue'; | ||
export { VersionView } from './VersionView'; |
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