2022-05-31 18:50:40 +02:00
|
|
|
import { configs } from 'shared/designs/index.js'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import orderBy from 'lodash.orderby'
|
|
|
|
import PageLink from 'shared/components/page-link.js'
|
2022-05-29 11:58:48 +02:00
|
|
|
|
2022-06-01 17:04:29 +02:00
|
|
|
const PatternMeasurements = ({ pattern, before=null, after=null }) => {
|
2022-05-31 18:50:40 +02:00
|
|
|
const { t } = useTranslation(['measurements'])
|
|
|
|
|
2022-05-29 11:58:48 +02:00
|
|
|
const sortMeasurements = (measurements) => {
|
|
|
|
if (typeof measurements === 'undefined') return []
|
|
|
|
let sorted = []
|
|
|
|
let translated = {}
|
|
|
|
for (let m of measurements) {
|
|
|
|
let translation = intl.messages['measurements.' + m] || m
|
|
|
|
translated[translation] = m
|
|
|
|
}
|
|
|
|
let order = Object.keys(translated)
|
|
|
|
order.sort()
|
|
|
|
for (let m of order) sorted.push(translated[m])
|
|
|
|
|
|
|
|
return sorted
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:50:40 +02:00
|
|
|
const measurements = {}
|
2022-06-01 17:04:29 +02:00
|
|
|
for (const m of configs[pattern].measurements) {
|
2022-05-31 18:50:40 +02:00
|
|
|
measurements[m] = {
|
|
|
|
title: t(`measurements.${m}`),
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 17:04:29 +02:00
|
|
|
for (const m of configs[pattern].measurements || []) {
|
2022-05-31 18:50:40 +02:00
|
|
|
measurements[m] = {
|
|
|
|
name: m,
|
|
|
|
title: t(`measurements:${m}`),
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-01 17:04:29 +02:00
|
|
|
// Not all patterns require measurements
|
|
|
|
if (Object.keys(measurements).length < 1) return null
|
2022-05-31 18:50:40 +02:00
|
|
|
|
2022-05-29 11:58:48 +02:00
|
|
|
return (
|
2022-06-01 17:04:29 +02:00
|
|
|
<div>
|
|
|
|
{before}
|
|
|
|
<ol className="list-inside ml-8 my-4">
|
|
|
|
{orderBy(measurements, ['title'], ['asc']).map(m => (
|
|
|
|
<li key={m.name}>
|
|
|
|
<PageLink href={'/docs/measurements/' + m.name.toLowerCase()} txt={m.title} />
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ol>
|
|
|
|
{after}
|
|
|
|
</div>
|
2022-05-29 11:58:48 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PatternMeasurements
|