From 0fc22921816a7781fd075b55eb5de512af457f48 Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Tue, 9 Apr 2024 09:25:16 +0200 Subject: [PATCH] refactor: Rename `formated` in `formatted` --- react/ListItem/ExpandedAttributes/helpers.js | 10 +++---- react/ListItem/ExpandedAttributes/index.jsx | 6 ++-- react/Viewer/Panel/Qualification.jsx | 10 +++---- .../Panel/QualificationListItemDate.jsx | 6 ++-- .../QualificationListItemInformation.jsx | 6 ++-- .../QualificationListItemInformation.spec.jsx | 28 +++++++++++-------- .../Panel/QualificationListItemOther.jsx | 6 ++-- 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/react/ListItem/ExpandedAttributes/helpers.js b/react/ListItem/ExpandedAttributes/helpers.js index 7fc97cd0a1..3c5f592b7f 100644 --- a/react/ListItem/ExpandedAttributes/helpers.js +++ b/react/ListItem/ExpandedAttributes/helpers.js @@ -138,7 +138,7 @@ export const hasExpandedAttributesDisplayed = ({ doc, expandedAttributes }) => { return attrsValues?.length > 0 || false } -export const getFormatedValue = ({ +export const getFormattedValue = ({ attrName, attrValue, qualificationLabel, @@ -173,16 +173,16 @@ export const makeLabel = ({ attrName, qualificationLabel, t, lang }) => { return t(`ListItem.attributes.${attrName}`) } -export const makeAttrsLabelAndFormatedValue = ({ +export const makeAttrsLabelAndFormattedValue = ({ doc, expandedAttributes, t, f, lang }) => { - const attrsKeyAndFormatedValue = makeAttrsValues(doc, expandedAttributes) + const attrsKeyAndFormattedValue = makeAttrsValues(doc, expandedAttributes) - return attrsKeyAndFormatedValue.map(({ attrName, attrValue }) => { + return attrsKeyAndFormattedValue.map(({ attrName, attrValue }) => { const _attrName = attrName.match(/\[.+\]/g) !== null ? attrName.split('[')[0] : attrName const qualificationLabel = doc.metadata?.qualification?.label @@ -194,7 +194,7 @@ export const makeAttrsLabelAndFormatedValue = ({ lang }) - const value = getFormatedValue({ + const value = getFormattedValue({ attrName: _attrName, attrValue, qualificationLabel, diff --git a/react/ListItem/ExpandedAttributes/index.jsx b/react/ListItem/ExpandedAttributes/index.jsx index 9511489ea6..376c4c5f9e 100644 --- a/react/ListItem/ExpandedAttributes/index.jsx +++ b/react/ListItem/ExpandedAttributes/index.jsx @@ -7,7 +7,7 @@ import { useI18n } from '../../providers/I18n' import withListItemLocales from '../hoc/withListItemLocales' import ExpandedAttribute from './ExpandedAttribute' -import { makeAttrsLabelAndFormatedValue } from './helpers' +import { makeAttrsLabelAndFormattedValue } from './helpers' const ExpandedAttributes = ({ doc, expandedAttributes }) => { const { t, f, lang } = useI18n() @@ -17,7 +17,7 @@ const ExpandedAttributes = ({ doc, expandedAttributes }) => { message: '' }) - const attrsLabelAndFormatedValue = makeAttrsLabelAndFormatedValue({ + const attrsLabelAndFormattedValue = makeAttrsLabelAndFormattedValue({ doc, expandedAttributes, t, @@ -29,7 +29,7 @@ const ExpandedAttributes = ({ doc, expandedAttributes }) => { return ( <> - {attrsLabelAndFormatedValue.map(({ label, value }, index) => { + {attrsLabelAndFormattedValue.map(({ label, value }, index) => { return ( { }) } - const formatedMetadataQualification = useMemo(() => { + const formattedMetadataQualification = useMemo(() => { return formatMetadataQualification(metadata) }, [metadata]) useEffect(() => { - actionBtnRef.current = formatedMetadataQualification.map( + actionBtnRef.current = formattedMetadataQualification.map( (_, idx) => actionBtnRef.current[idx] ?? createRef() ) - }, [formatedMetadataQualification]) + }, [formattedMetadataQualification]) return ( <> @@ -63,7 +63,7 @@ const Qualification = ({ file }) => { )} - {formatedMetadataQualification.map((meta, idx) => { + {formattedMetadataQualification.map((meta, idx) => { const { name } = meta const metadataQualificationType = getMetadataQualificationType(name) const QualificationListItemComp = @@ -74,7 +74,7 @@ const Qualification = ({ file }) => { key={idx} file={file} ref={actionBtnRef.current[idx]} - formatedMetadataQualification={meta} + formattedMetadataQualification={meta} toggleActionsMenu={val => toggleActionsMenu(idx, name, val)} /> ) diff --git a/react/Viewer/Panel/QualificationListItemDate.jsx b/react/Viewer/Panel/QualificationListItemDate.jsx index 77cff14acc..ae75b8428a 100644 --- a/react/Viewer/Panel/QualificationListItemDate.jsx +++ b/react/Viewer/Panel/QualificationListItemDate.jsx @@ -19,9 +19,9 @@ import QualificationListItemText from './QualificationListItemText' import { useI18n } from '../../providers/I18n' const QualificationListItemDate = forwardRef( - ({ file, formatedMetadataQualification, toggleActionsMenu }, ref) => { + ({ file, formattedMetadataQualification, toggleActionsMenu }, ref) => { const { f, lang } = useI18n() - const { name, value } = formatedMetadataQualification + const { name, value } = formattedMetadataQualification const formattedTitle = getTranslatedNameForDateMetadata(name, { lang }) const formattedDate = formatDateMetadataValue(value, { f, @@ -67,7 +67,7 @@ QualificationListItemDate.displayName = 'QualificationListItemDate' QualificationListItemDate.propTypes = { file: PropTypes.object.isRequired, - formatedMetadataQualification: PropTypes.shape({ + formattedMetadataQualification: PropTypes.shape({ name: PropTypes.string, value: PropTypes.string }).isRequired, diff --git a/react/Viewer/Panel/QualificationListItemInformation.jsx b/react/Viewer/Panel/QualificationListItemInformation.jsx index b84c1e6f76..d7feb49726 100644 --- a/react/Viewer/Panel/QualificationListItemInformation.jsx +++ b/react/Viewer/Panel/QualificationListItemInformation.jsx @@ -16,9 +16,9 @@ import { useI18n } from '../../providers/I18n' import MidEllipsis from '../../MidEllipsis' const QualificationListItemInformation = forwardRef( - ({ formatedMetadataQualification, file, toggleActionsMenu }, ref) => { + ({ formattedMetadataQualification, file, toggleActionsMenu }, ref) => { const { lang } = useI18n() - const { name, value } = formatedMetadataQualification + const { name, value } = formattedMetadataQualification const qualificationLabel = file.metadata.qualification.label const formattedTitle = getTranslatedNameForInformationMetadata(name, { @@ -58,7 +58,7 @@ const QualificationListItemInformation = forwardRef( QualificationListItemInformation.displayName = 'QualificationListItemNumber' QualificationListItemInformation.propTypes = { - formatedMetadataQualification: PropTypes.shape({ + formattedMetadataQualification: PropTypes.shape({ name: PropTypes.string, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) }).isRequired, diff --git a/react/Viewer/Panel/QualificationListItemInformation.spec.jsx b/react/Viewer/Panel/QualificationListItemInformation.spec.jsx index c57bd32cf2..639dceceb8 100644 --- a/react/Viewer/Panel/QualificationListItemInformation.spec.jsx +++ b/react/Viewer/Panel/QualificationListItemInformation.spec.jsx @@ -8,12 +8,12 @@ jest.mock('../../providers/I18n', () => ({ })) const setup = ({ - formatedMetadataQualification = {}, + formattedMetadataQualification = {}, toggleActionsMenu = jest.fn() } = {}) => { return render( { - describe('formatedMetadataQualification', () => { + describe('formattedMetadataQualification', () => { it('should display default text if value is falsy', () => { - const formatedMetadataQualification = { name: 'country', value: '' } - const { getByText } = setup({ formatedMetadataQualification }) + const formattedMetadataQualification = { name: 'country', value: '' } + const { getByText } = setup({ formattedMetadataQualification }) expect(getByText('No information')) }) it.only('should display current value if it is truthy', () => { - const formatedMetadataQualification = { name: 'country', value: 'Italie' } + const formattedMetadataQualification = { + name: 'country', + value: 'Italie' + } const { queryByText } = setup({ - formatedMetadataQualification + formattedMetadataQualification }) expect(queryByText('No information')).toBeNull() expect(queryByText('Italie')).toBeInTheDocument() }) it('should display current value if it number type', () => { - const formatedMetadataQualification = { name: 'country', value: 0 } + const formattedMetadataQualification = { name: 'country', value: 0 } const { queryByText } = setup({ - formatedMetadataQualification + formattedMetadataQualification }) expect(queryByText('No information')).toBeNull() @@ -51,11 +54,14 @@ describe('QualificationListItemInformation', () => { }) describe('toggleActionsMenu', () => { it('should call toggleActionsMenu with current value on click it', () => { - const formatedMetadataQualification = { name: 'country', value: 'Italie' } + const formattedMetadataQualification = { + name: 'country', + value: 'Italie' + } const toggleActionsMenu = jest.fn() const { getByTestId } = setup({ toggleActionsMenu, - formatedMetadataQualification + formattedMetadataQualification }) const toggleActionsMenuBtn = getByTestId('toggleActionsMenuBtn') fireEvent.click(toggleActionsMenuBtn) diff --git a/react/Viewer/Panel/QualificationListItemOther.jsx b/react/Viewer/Panel/QualificationListItemOther.jsx index 60f114a168..4f44a44f1e 100644 --- a/react/Viewer/Panel/QualificationListItemOther.jsx +++ b/react/Viewer/Panel/QualificationListItemOther.jsx @@ -16,9 +16,9 @@ import { useI18n } from '../../providers/I18n' import MidEllipsis from '../../MidEllipsis' const QualificationListItemOther = forwardRef( - ({ formatedMetadataQualification, toggleActionsMenu }, ref) => { + ({ formattedMetadataQualification, toggleActionsMenu }, ref) => { const { lang } = useI18n() - const { name, value } = formatedMetadataQualification + const { name, value } = formattedMetadataQualification if (!value) return null @@ -51,7 +51,7 @@ const QualificationListItemOther = forwardRef( QualificationListItemOther.displayName = 'QualificationListItemOther' QualificationListItemOther.propTypes = { - formatedMetadataQualification: PropTypes.shape({ + formattedMetadataQualification: PropTypes.shape({ name: PropTypes.string, value: PropTypes.string }).isRequired,