Skip to content

Commit

Permalink
refactor: Rename formated in formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Apr 9, 2024
1 parent 4358f37 commit 0fc2292
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 33 deletions.
10 changes: 5 additions & 5 deletions react/ListItem/ExpandedAttributes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const hasExpandedAttributesDisplayed = ({ doc, expandedAttributes }) => {
return attrsValues?.length > 0 || false
}

export const getFormatedValue = ({
export const getFormattedValue = ({
attrName,
attrValue,
qualificationLabel,
Expand Down Expand Up @@ -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
Expand All @@ -194,7 +194,7 @@ export const makeAttrsLabelAndFormatedValue = ({
lang
})

const value = getFormatedValue({
const value = getFormattedValue({
attrName: _attrName,
attrValue,
qualificationLabel,
Expand Down
6 changes: 3 additions & 3 deletions react/ListItem/ExpandedAttributes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -17,7 +17,7 @@ const ExpandedAttributes = ({ doc, expandedAttributes }) => {
message: ''
})

const attrsLabelAndFormatedValue = makeAttrsLabelAndFormatedValue({
const attrsLabelAndFormattedValue = makeAttrsLabelAndFormattedValue({
doc,
expandedAttributes,
t,
Expand All @@ -29,7 +29,7 @@ const ExpandedAttributes = ({ doc, expandedAttributes }) => {

return (
<>
{attrsLabelAndFormatedValue.map(({ label, value }, index) => {
{attrsLabelAndFormattedValue.map(({ label, value }, index) => {
return (
<ExpandedAttribute
key={index}
Expand Down
10 changes: 5 additions & 5 deletions react/Viewer/Panel/Qualification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ const Qualification = ({ file }) => {
})
}

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 (
<>
{isExpiringSoon(file) && !isExpirationAlertHidden(file) && (
<ExpirationAlert file={file} />
)}
<List className={'u-pv-1'}>
{formatedMetadataQualification.map((meta, idx) => {
{formattedMetadataQualification.map((meta, idx) => {
const { name } = meta
const metadataQualificationType = getMetadataQualificationType(name)
const QualificationListItemComp =
Expand All @@ -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)}
/>
)
Expand Down
6 changes: 3 additions & 3 deletions react/Viewer/Panel/QualificationListItemDate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions react/Viewer/Panel/QualificationListItemInformation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 17 additions & 11 deletions react/Viewer/Panel/QualificationListItemInformation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jest.mock('../../providers/I18n', () => ({
}))

const setup = ({
formatedMetadataQualification = {},
formattedMetadataQualification = {},
toggleActionsMenu = jest.fn()
} = {}) => {
return render(
<QualificationListItemInformation
formatedMetadataQualification={formatedMetadataQualification}
formattedMetadataQualification={formattedMetadataQualification}
toggleActionsMenu={toggleActionsMenu}
file={{
metadata: { qualification: { label: 'label_of_qualification' } }
Expand All @@ -23,26 +23,29 @@ const setup = ({
}

describe('QualificationListItemInformation', () => {
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()
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions react/Viewer/Panel/QualificationListItemOther.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0fc2292

Please sign in to comment.