From ca6029b034bd92d95237bb33ba2c5ff59020656d Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 13 Sep 2019 13:22:02 +0200 Subject: [PATCH] search page component reorder --- .../components/atoms/Form/Input.module.scss | 2 +- client/src/routes/Search/FilterItem.test.tsx | 51 ++++++++++ client/src/routes/Search/FilterItem.tsx | 6 +- client/src/routes/Search/Filters.module.scss | 16 --- client/src/routes/Search/Filters.tsx | 94 ------------------ client/src/routes/Search/Sidebar.module.scss | 15 +++ .../{Filters.test.tsx => Sidebar.test.tsx} | 6 +- client/src/routes/Search/Sidebar.tsx | 98 ++++++++++++++----- client/src/routes/Search/index.module.scss | 3 +- client/src/routes/Search/index.tsx | 36 ++++--- 10 files changed, 170 insertions(+), 157 deletions(-) create mode 100644 client/src/routes/Search/FilterItem.test.tsx delete mode 100644 client/src/routes/Search/Filters.module.scss delete mode 100644 client/src/routes/Search/Filters.tsx rename client/src/routes/Search/{Filters.test.tsx => Sidebar.test.tsx} (89%) diff --git a/client/src/components/atoms/Form/Input.module.scss b/client/src/components/atoms/Form/Input.module.scss index e3c0607..23ca1d0 100644 --- a/client/src/components/atoms/Form/Input.module.scss +++ b/client/src/components/atoms/Form/Input.module.scss @@ -22,7 +22,7 @@ composes: inputWrap; .input { - padding-left: $spacer * 1.5; + padding-left: $spacer; } svg { diff --git a/client/src/routes/Search/FilterItem.test.tsx b/client/src/routes/Search/FilterItem.test.tsx new file mode 100644 index 0000000..21a7c1a --- /dev/null +++ b/client/src/routes/Search/FilterItem.test.tsx @@ -0,0 +1,51 @@ +import React from 'react' +import { render, fireEvent } from '@testing-library/react' +import FilterItem from './FilterItem' + +describe('FilterItem', () => { + const filterByCategory = jest.fn() + const filterByLicense = jest.fn() + + it('renders without crashing', () => { + const { container } = render( + + ) + expect(container.firstChild).toBeInTheDocument() + }) + + it('filterByCategory can be called', () => { + const { getByText, getByTitle } = render( + + ) + fireEvent.click(getByText(/Hello/)) + expect(filterByCategory).toHaveBeenCalled() + fireEvent.click(getByTitle('Clear')) + }) + + it('filterByLicense can be called', () => { + const { getByText, getByTitle } = render( + + ) + fireEvent.click(getByText(/Hello/)) + expect(filterByLicense).toHaveBeenCalled() + fireEvent.click(getByTitle('Clear')) + }) +}) diff --git a/client/src/routes/Search/FilterItem.tsx b/client/src/routes/Search/FilterItem.tsx index d1b42ab..5f10728 100644 --- a/client/src/routes/Search/FilterItem.tsx +++ b/client/src/routes/Search/FilterItem.tsx @@ -1,5 +1,4 @@ import React from 'react' -import shortid from 'shortid' import Button from '../../components/atoms/Button' import styles from './FilterItem.module.scss' @@ -17,10 +16,7 @@ export default function FilterItem({ filterByLicense(license: string): void }) { return ( -
  • +
  • - // } - /> + {filters.map(filter => ( +
    +

    {filter.label}

    +
      + {filter.items && + filter.items + .sort((a: string, b: string) => + a.localeCompare(b) + ) // sort alphabetically + .map((option: string) => { + const isActive = + category === option || + license === option - + return ( + + ) + })} +
    +
    + ))} ) } diff --git a/client/src/routes/Search/index.module.scss b/client/src/routes/Search/index.module.scss index 85d198d..611fc86 100644 --- a/client/src/routes/Search/index.module.scss +++ b/client/src/routes/Search/index.module.scss @@ -4,8 +4,9 @@ display: grid; grid-gap: $spacer * 2; grid-template-columns: 1fr; + margin-top: $spacer * 2; @media (min-width: $break-point--medium) { - grid-template-columns: 1fr 3fr; + grid-template-columns: 3fr 1fr; } } diff --git a/client/src/routes/Search/index.tsx b/client/src/routes/Search/index.tsx index ad02e86..85a579c 100644 --- a/client/src/routes/Search/index.tsx +++ b/client/src/routes/Search/index.tsx @@ -6,6 +6,7 @@ import Spinner from '../../components/atoms/Spinner' import Route from '../../components/templates/Route' import { User } from '../../context' import Content from '../../components/atoms/Content' +import Input from '../../components/atoms/Form/Input' import withTracker from '../../hoc/withTracker' import Sidebar from './Sidebar' import Results from './Results' @@ -206,19 +207,24 @@ class Search extends PureComponent { } = this.state return ( - + + + + // Search + // + // } + /> +
    - -
    {isLoading ? ( @@ -235,6 +241,14 @@ class Search extends PureComponent { /> )}
    + +