diff --git a/.eslintrc.js b/.eslintrc.js index a16f10b9..2f87a271 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,6 +10,13 @@ module.exports = { rules: { 'jsx-a11y/href-no-hash': ['off'], 'react/jsx-filename-extension': ['warn', { extensions: ['.js', '.jsx'] }], + 'react/destructuring-assignment': [ + 'warn', + 'always', + { + ignoreClassFields: false, + }, + ], 'max-len': [ 'warn', { diff --git a/src/components/PatternFrequencies/index.js b/src/components/PatternFrequencies/index.js new file mode 100644 index 00000000..040a08f0 --- /dev/null +++ b/src/components/PatternFrequencies/index.js @@ -0,0 +1,74 @@ +import { Badge } from 'reactstrap'; +import React from 'react'; +// eslint-disable-next-line import/no-extraneous-dependencies +import PropTypes from 'prop-types'; +import './styles.scss'; + +const PatternFrequencies = ({ filters, rows }) => { + const patternsMap = rows.reduce((acc, row) => { + for (let i = 0; i < row.original.pattern.length; i += 1) { + const pattern = row.original.pattern[i]; + acc[pattern] = acc[pattern] + 1 || 1; + } + return acc; + }, Object.create(null)); + const sortedPatternsByFrequency = Object.keys(patternsMap).sort( + (a, b) => patternsMap[b] - patternsMap[a], + ); + const showComponent = filters.find(filter => + ['companies', 'difficulty'].includes(filter.id), + ); + + const getFrequencyClass = rate => { + const highestFrequency = Math.round( + patternsMap[sortedPatternsByFrequency[0]], + ); + + if (highestFrequency / 3 < 1) { + return ''; + } + + const frequencyRate = { + easy: Math.round(highestFrequency / 3), + medium: Math.round((highestFrequency / 3) * 2), + hard: highestFrequency, + }; + + return Object.keys(frequencyRate).find(key => rate <= frequencyRate[key]); + }; + + return showComponent ? ( +