From 5a56c40d3610fdd432e46d79a9db99f237cb1f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Fri, 9 Apr 2021 18:20:19 +0200 Subject: [PATCH] Extracting filterValue from filterComponent in the viewHeader --- .../components/viewHeader/filterComponent.tsx | 62 +++------------- .../components/viewHeader/filterValue.scss | 2 + .../src/components/viewHeader/filterValue.tsx | 71 +++++++++++++++++++ 3 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 webapp/src/components/viewHeader/filterValue.scss create mode 100644 webapp/src/components/viewHeader/filterValue.tsx diff --git a/webapp/src/components/viewHeader/filterComponent.tsx b/webapp/src/components/viewHeader/filterComponent.tsx index 3d408bb67..f107e256c 100644 --- a/webapp/src/components/viewHeader/filterComponent.tsx +++ b/webapp/src/components/viewHeader/filterComponent.tsx @@ -3,7 +3,6 @@ import React from 'react' import {FormattedMessage, injectIntl, IntlShape} from 'react-intl' -import {IPropertyTemplate} from '../../blocks/board' import {FilterClause, FilterCondition} from '../../blocks/filterClause' import {FilterGroup} from '../../blocks/filterGroup' import mutator from '../../mutator' @@ -16,6 +15,8 @@ import MenuWrapper from '../../widgets/menuWrapper' import Modal from '../modal' +import FilterValue from './filterValue' + import './filterComponent.scss' type Props = { @@ -117,9 +118,12 @@ class FilterComponent extends React.Component { /> - { - template && this.filterValue(filter, template) - } + {template && + }
- - {template.options.map((o) => ( - { - const filterIndex = view.filter.filters.indexOf(filter) - Utils.assert(filterIndex >= 0, "Can't find filter") - - const filterGroup = new FilterGroup(view.filter) - const newFilter = filterGroup.filters[filterIndex] as FilterClause - Utils.assert(newFilter, `No filter at index ${filterIndex}`) - if (filter.values.includes(o.id)) { - newFilter.values = newFilter.values.filter((id) => id !== optionId) - mutator.changeViewFilter(view, filterGroup) - } else { - newFilter.values.push(optionId) - mutator.changeViewFilter(view, filterGroup) - } - }} - /> - ))} - - - ) - } - - return undefined - } - private deleteClicked(filter: FilterClause) { const {boardTree} = this.props const {activeView: view} = boardTree diff --git a/webapp/src/components/viewHeader/filterValue.scss b/webapp/src/components/viewHeader/filterValue.scss new file mode 100644 index 000000000..7085f6f50 --- /dev/null +++ b/webapp/src/components/viewHeader/filterValue.scss @@ -0,0 +1,2 @@ +.FilterValue { +} diff --git a/webapp/src/components/viewHeader/filterValue.tsx b/webapp/src/components/viewHeader/filterValue.tsx new file mode 100644 index 000000000..a0d4a13c6 --- /dev/null +++ b/webapp/src/components/viewHeader/filterValue.tsx @@ -0,0 +1,71 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +import React from 'react' + +import {IPropertyTemplate} from '../../blocks/board' +import {FilterClause} from '../../blocks/filterClause' +import {FilterGroup} from '../../blocks/filterGroup' +import {BoardView} from '../../blocks/boardView' +import mutator from '../../mutator' +import {Utils} from '../../utils' +import Button from '../../widgets/buttons/button' +import Menu from '../../widgets/menu' +import MenuWrapper from '../../widgets/menuWrapper' + +import './filterValue.scss' + +type Props = { + view: BoardView + filter: FilterClause + template: IPropertyTemplate +} + +const filterValue = (props: Props): JSX.Element|null => { + const {filter, template, view} = props + if (filter.condition !== 'includes' && filter.condition !== 'notIncludes') { + return null + } + + let displayValue: string + if (filter.values.length > 0) { + displayValue = filter.values.map((id) => { + const option = template.options.find((o) => o.id === id) + return option?.value || '(Unknown)' + }).join(', ') + } else { + displayValue = '(empty)' + } + + return ( + + + + {template.options.map((o) => ( + { + const filterIndex = view.filter.filters.indexOf(filter) + Utils.assert(filterIndex >= 0, "Can't find filter") + + const filterGroup = new FilterGroup(view.filter) + const newFilter = filterGroup.filters[filterIndex] as FilterClause + Utils.assert(newFilter, `No filter at index ${filterIndex}`) + if (filter.values.includes(o.id)) { + newFilter.values = newFilter.values.filter((id) => id !== optionId) + mutator.changeViewFilter(view, filterGroup) + } else { + newFilter.values.push(optionId) + mutator.changeViewFilter(view, filterGroup) + } + }} + /> + ))} + + + ) +} + +export default filterValue