From 824ad6bd9908b90d1d83aa2bd87efea2b7dd3928 Mon Sep 17 00:00:00 2001 From: Richard Dinh Date: Wed, 8 Jul 2020 09:52:22 -0400 Subject: [PATCH 1/2] save work eslint complexity nags update test and snapshots props es6 --- src/components/Trends/TrendDepthToggle.jsx | 36 +++++++++++--- .../__tests__/TrendDepthToggle.spec.jsx | 47 ++++++++++++++----- .../TrendDepthToggle.spec.jsx.snap | 2 +- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/components/Trends/TrendDepthToggle.jsx b/src/components/Trends/TrendDepthToggle.jsx index 8fbd17f76..36575d0e7 100644 --- a/src/components/Trends/TrendDepthToggle.jsx +++ b/src/components/Trends/TrendDepthToggle.jsx @@ -1,19 +1,35 @@ +/* eslint complexity: ["error", 5] */ import './TrendDepthToggle.less' import { changeDepth, resetDepth } from '../../actions/trends' import { clamp, coalesce } from '../../utils' import { connect } from 'react-redux' import React from 'react' +import { SLUG_SEPARATOR } from '../../constants' + +const maxRows = 5 export class TrendDepthToggle extends React.Component { + + _showMore() { + const { queryCount, resultCount } = this.props + // scenarios where we want to show more: + // you have less visible rows that the max (5) + if ( resultCount <= maxRows ) { + return true + } + // or more filters count > max Rows and they aren't the same (visible) + return queryCount > maxRows && queryCount !== resultCount + } + render() { - const { diff, showToggle } = this.props + const { diff, increaseDepth, resetDepth, showToggle } = this.props if ( showToggle ) { - if ( diff > 0 ) { + if ( this._showMore() ) { return