From 04a633bd32965461f98b62e7ede46f05a6d50203 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Fri, 10 Jan 2020 12:34:38 +0100 Subject: [PATCH] Add boolean field --- src/components/Filter/FilterContent.tsx | 37 +++++++++++++++++++++++++ src/components/Filter/types.ts | 1 + src/utils/filters/fields.ts | 26 +++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/src/components/Filter/FilterContent.tsx b/src/components/Filter/FilterContent.tsx index f9cf27caa..d0eefc5a6 100644 --- a/src/components/Filter/FilterContent.tsx +++ b/src/components/Filter/FilterContent.tsx @@ -1,9 +1,11 @@ import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; +import Radio from "@material-ui/core/Radio"; import Typography from "@material-ui/core/Typography"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import React from "react"; import { FormattedMessage, useIntl, IntlShape } from "react-intl"; +import classNames from "classnames"; import makeStyles from "@material-ui/core/styles/makeStyles"; import { fade } from "@material-ui/core/styles/colorManipulator"; @@ -67,6 +69,9 @@ const useStyles = makeStyles( option: { left: -theme.spacing(0.5), position: "relative" + }, + optionRadio: { + left: -theme.spacing(0.25) } }), { name: "FilterContent" } @@ -372,6 +377,38 @@ const FilterContent: React.FC = ({ } /> ))} + {filterField.type === FieldType.boolean && + filterField.options.map(option => ( +
+ + } + label={option.label} + name={filterField.name} + onChange={() => + onFilterPropertyChange({ + payload: { + name: filterField.name, + update: { + value: [option.value] + } + }, + type: "set-property" + }) + } + /> +
+ ))} )} diff --git a/src/components/Filter/types.ts b/src/components/Filter/types.ts index 3ed9beb05..eea2f96d5 100644 --- a/src/components/Filter/types.ts +++ b/src/components/Filter/types.ts @@ -2,6 +2,7 @@ import { FetchMoreProps } from "@saleor/types"; import { MultiAutocompleteChoiceType } from "../MultiAutocompleteSelectField"; export enum FieldType { + boolean, date, dateTime, number, diff --git a/src/utils/filters/fields.ts b/src/utils/filters/fields.ts index fb86a4a2f..69dae346b 100644 --- a/src/utils/filters/fields.ts +++ b/src/utils/filters/fields.ts @@ -79,3 +79,29 @@ export function createTextField( value: [defaultValue] }; } + +export function createBooleanField( + name: T, + label: string, + defaultValue: boolean, + labels: Record<"positive" | "negative", string> +): IFilterElement { + return { + active: false, + label, + multiple: false, + name, + options: [ + { + label: labels.positive, + value: true.toString() + }, + { + label: labels.negative, + value: false.toString() + } + ], + type: FieldType.boolean, + value: [defaultValue.toString()] + }; +}