Skip to content

Commit

Permalink
collapsible filter lists in footer;
Browse files Browse the repository at this point in the history
  • Loading branch information
eharkins committed Oct 7, 2021
1 parent dbd40e4 commit 3783a78
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"query-string": "^4.2.3",
"react": "^16.8.6",
"react-addons-css-transition-group": "^15.6.0",
"react-collapsible": "^2.8.4",
"react-dom": "^16.8.6",
"react-ga": "^2.2.0",
"react-helmet": "^5.2.1",
Expand Down
74 changes: 52 additions & 22 deletions src/components/framework/footer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { Suspense, lazy } from "react";
import { connect } from "react-redux";
import styled from 'styled-components';
import Collapsible from "react-collapsible";
import { withTranslation } from "react-i18next";
import {FaAngleUp, FaAngleDown} from "react-icons/fa";
import { dataFont } from "../../globalStyles";
import Flex from "./flex";
import { applyFilter } from "../../actions/tree";
Expand Down Expand Up @@ -163,6 +165,25 @@ const removeFiltersButton = (dispatch, filterNames, outerClassName, label) => (
</SimpleFilter>
);

const TitleContainer = styled.div`
display: flex;
justify-content: space-between;
border-top: 1px solid #F0F0F0;
margin: 0px;
padding: 15px 10px 10px 10px;
`;
const IconContainer = styled.span`
font-size: 22px;
font-weight: 500;
`;

const CollapseTitle = ({name, isExpanded=false}) => (
<TitleContainer>
{name}
<IconContainer>{isExpanded ? <FaAngleUp /> : <FaAngleDown />}</IconContainer>
</TitleContainer>
);


@connect((state) => {
return {
Expand Down Expand Up @@ -197,30 +218,39 @@ class Footer extends React.Component {
const totalStateCount = this.props.totalStateCounts[filterName];
const filterTitle = this.props.metadata.colorings[filterName] ? this.props.metadata.colorings[filterName].title : filterName;
const activeFilterItems = this.props.activeFilters[filterName].filter((x) => x.active).map((x) => x.value);
const title = (<div>
{t("Filter by {{filterTitle}}", {filterTitle: filterTitle})}
{this.props.activeFilters[filterName].length ? removeFiltersButton(this.props.dispatch, [filterName], "inlineRight", t("Clear {{filterName}} filter", { filterName: filterName})) : null}
</div>);
return (
<div>
{t("Filter by {{filterTitle}}", {filterTitle: filterTitle})}
{this.props.activeFilters[filterName].length ? removeFiltersButton(this.props.dispatch, [filterName], "inlineRight", t("Clear {{filterName}} filter", { filterName: filterName})) : null}
<div className='filterList'>
<Flex wrap="wrap" justifyContent="flex-start" alignItems="center">
{
Array.from(totalStateCount.keys())
.filter((itemName) => isValueValid(itemName)) // remove invalid values present across the tree
.sort() // filters are sorted alphabetically
.map((itemName) => (
<SimpleFilter
key={itemName}
active={activeFilterItems.indexOf(itemName) !== -1}
onClick={() => dispatchFilter(this.props.dispatch, this.props.activeFilters, filterName, itemName)}
>
<span>
{`${itemName} (${totalStateCount.get(itemName)})`}
</span>
</SimpleFilter>
))
}
</Flex>
</div>
<Collapsible
triggerWhenOpen={<CollapseTitle name={title} isExpanded />}
trigger={<CollapseTitle name={title} />}
triggerStyle={{cursor: "pointer", textDecoration: "none"}}
transitionTime={100}
>
<div className='filterList'>
<Flex wrap="wrap" justifyContent="flex-start" alignItems="center">
{
Array.from(totalStateCount.keys())
.filter((itemName) => isValueValid(itemName)) // remove invalid values present across the tree
.sort() // filters are sorted alphabetically
.map((itemName) => (
<SimpleFilter
key={itemName}
active={activeFilterItems.indexOf(itemName) !== -1}
onClick={() => dispatchFilter(this.props.dispatch, this.props.activeFilters, filterName, itemName)}
>
<span>
{`${itemName} (${totalStateCount.get(itemName)})`}
</span>
</SimpleFilter>
))
}
</Flex>
</div>
</Collapsible>
</div>
);
}
Expand Down

0 comments on commit 3783a78

Please sign in to comment.