Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include badge showing applied filters in Verify page #173

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/Verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import LinearProgress from '@material-ui/core/LinearProgress';
import IconFilter from '@material-ui/icons/FilterList';
import IconButton from '@material-ui/core/IconButton';
import Snackbar from '@material-ui/core/Snackbar';
import Avatar from '@material-ui/core/Avatar';

import FilterTop from './FilterTop';
import CheckIcon from '@material-ui/icons/Check';
Expand Down Expand Up @@ -139,6 +140,12 @@ const useStyles = makeStyles((theme) => ({
mb: {
marginBottom: '1rem',
},
activeFilters: {
width: theme.spacing(5),
height: theme.spacing(5),
marginLeft: '0.75rem',
backgroundColor: theme.palette.stats.green,
}
}));

const ToVerifyCounter = withData(({ data }) => (
Expand All @@ -164,6 +171,7 @@ const Verify = (props) => {
grower: {},
});
const refContainer = useRef();
const numFilters = verifyContext.filter.countAppliedFilters();

// log.debug(
// 'render: verify',
Expand Down Expand Up @@ -446,13 +454,21 @@ const Verify = (props) => {
<Navbar
buttons={[
<Button
variant="text"
variant="outlined"
color="primary"
onClick={handleFilterClick}
startIcon={<IconFilter />}
key={1}
>
Filter
{
numFilters > 0 &&
(
<Avatar className={classes.activeFilters}>
{numFilters}
</Avatar>
)
}
</Button>,
]}
>
Expand Down
7 changes: 7 additions & 0 deletions src/components/tests/verify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ describe('Verify', () => {
filter: new FilterModel({
approved: false,
active: true,
deviceIdentifier: '06C71C70-0636-4339-AE53-949107B58814',
}),
invalidateCaptureCount: true,
captureCount: null,
Expand Down Expand Up @@ -370,6 +371,12 @@ describe('Verify', () => {
expect(tokenStatus).toBeInTheDocument();
});

it('renders number of applied filters', () => {
const filter = screen.getByRole('button', { name: /filter/i });
userEvent.click(filter);
expect(verifyValues.filter.countAppliedFilters()).toBe(2) ;
})

it('renders side panel', () => {
// screen.logTestingPlaygroundURL();
// expect(screen.getByText(/planters per page: 24/i));
Expand Down
58 changes: 58 additions & 0 deletions src/models/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,62 @@ export default class Filter {
return true;
}
};

/*
* A fn to count the number of current applied filters
*/
countAppliedFilters() {
let numFilters = 0;

if (this.active !== undefined && this.approved !== undefined) {
numFilters += 1;
}

if (this.uuid) {
numFilters += 1;
}

if (this.captureId) {
numFilters += 1;
}

if (this.deviceIdentifier) {
numFilters += 1;
}

if (this.planterId) {
numFilters += 1;
}

if (this.planterIdentifier) {
numFilters += 1;
}

if (this.tagId > 0) {
numFilters += 1;
}

if (this.dateStart) {
numFilters += 1;
}

if (this.dateEnd) {
numFilters += 1;
}

if (this.organizationId && this.organizationId !== ALL_ORGANIZATIONS) {
numFilters += 1;
}

if (this.speciesId && this.speciesId !== ALL_SPECIES) {
numFilters += 1;
}

if (this.tokenId && this.tokenId !== 'All') {
numFilters += 1;
}

return numFilters;
}

}