From 30e912c3f97dd6de36bdc9d35fdd4efe50b94af0 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Tue, 16 Feb 2021 10:31:00 -0800 Subject: [PATCH] Cleanup model imports --- webapp/src/blocks/board.ts | 4 +- webapp/src/blocks/boardView.ts | 5 +-- webapp/src/blocks/card.ts | 3 +- webapp/src/blocks/commentBlock.ts | 4 +- .../{dividerBlock.tsx => dividerBlock.ts} | 1 - webapp/src/blocks/filterClause.ts | 27 ++++++++++++ webapp/src/{ => blocks}/filterGroup.ts | 0 webapp/src/cardFilter.ts | 4 +- webapp/src/components/filterComponent.tsx | 7 ++-- webapp/src/filterClause.ts | 42 ------------------- webapp/src/mutator.ts | 2 +- webapp/src/octoUtils.tsx | 16 +++++++ webapp/src/test/testBlockFactory.ts | 4 +- 13 files changed, 57 insertions(+), 62 deletions(-) rename webapp/src/blocks/{dividerBlock.tsx => dividerBlock.ts} (99%) create mode 100644 webapp/src/blocks/filterClause.ts rename webapp/src/{ => blocks}/filterGroup.ts (100%) delete mode 100644 webapp/src/filterClause.ts diff --git a/webapp/src/blocks/board.ts b/webapp/src/blocks/board.ts index 8dcbe18ff..709219b78 100644 --- a/webapp/src/blocks/board.ts +++ b/webapp/src/blocks/board.ts @@ -2,9 +2,7 @@ // See LICENSE.txt for license information. import {Utils} from '../utils' -import {IBlock} from '../blocks/block' - -import {MutableBlock} from './block' +import {IBlock, MutableBlock} from './block' type PropertyType = 'text' | 'number' | 'select' | 'multiSelect' | 'date' | 'person' | 'file' | 'checkbox' | 'url' | 'email' | 'phone' | 'createdTime' | 'createdBy' | 'updatedTime' | 'updatedBy' diff --git a/webapp/src/blocks/boardView.ts b/webapp/src/blocks/boardView.ts index c90e3b773..81694d189 100644 --- a/webapp/src/blocks/boardView.ts +++ b/webapp/src/blocks/boardView.ts @@ -1,10 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {IBlock} from '../blocks/block' -import {FilterGroup} from '../filterGroup' import {Utils} from '../utils' -import {MutableBlock} from './block' +import {IBlock, MutableBlock} from './block' +import {FilterGroup} from './filterGroup' type IViewType = 'board' | 'table' // | 'calendar' | 'list' | 'gallery' type ISortOption = { propertyId: '__title' | string, reversed: boolean } diff --git a/webapp/src/blocks/card.ts b/webapp/src/blocks/card.ts index 49ca2bd34..02721cbda 100644 --- a/webapp/src/blocks/card.ts +++ b/webapp/src/blocks/card.ts @@ -1,9 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import {Utils} from '../utils' -import {IBlock} from '../blocks/block' -import {MutableBlock} from './block' +import {IBlock, MutableBlock} from './block' interface Card extends IBlock { readonly icon: string diff --git a/webapp/src/blocks/commentBlock.ts b/webapp/src/blocks/commentBlock.ts index 41bafb0af..4cbfd8653 100644 --- a/webapp/src/blocks/commentBlock.ts +++ b/webapp/src/blocks/commentBlock.ts @@ -1,8 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {IBlock} from '../blocks/block' - -import {MutableBlock} from './block' +import {IBlock, MutableBlock} from './block' type CommentBlock = IBlock diff --git a/webapp/src/blocks/dividerBlock.tsx b/webapp/src/blocks/dividerBlock.ts similarity index 99% rename from webapp/src/blocks/dividerBlock.tsx rename to webapp/src/blocks/dividerBlock.ts index d3ff51409..da35c0af5 100644 --- a/webapp/src/blocks/dividerBlock.tsx +++ b/webapp/src/blocks/dividerBlock.ts @@ -12,4 +12,3 @@ class MutableDividerBlock extends MutableContentBlock implements DividerBlock { } export {DividerBlock, MutableDividerBlock} - diff --git a/webapp/src/blocks/filterClause.ts b/webapp/src/blocks/filterClause.ts new file mode 100644 index 000000000..17be5814b --- /dev/null +++ b/webapp/src/blocks/filterClause.ts @@ -0,0 +1,27 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +import {Utils} from '../utils' + +type FilterCondition = 'includes' | 'notIncludes' | 'isEmpty' | 'isNotEmpty' + +class FilterClause { + propertyId: string + condition: FilterCondition + values: string[] + + constructor(o: any = {}) { + this.propertyId = o.propertyId || '' + this.condition = o.condition || 'includes' + this.values = o.values?.slice() || [] + } + + isEqual(o: FilterClause): boolean { + return ( + this.propertyId === o.propertyId && + this.condition === o.condition && + Utils.arraysEqual(this.values, o.values) + ) + } +} + +export {FilterClause, FilterCondition} diff --git a/webapp/src/filterGroup.ts b/webapp/src/blocks/filterGroup.ts similarity index 100% rename from webapp/src/filterGroup.ts rename to webapp/src/blocks/filterGroup.ts diff --git a/webapp/src/cardFilter.ts b/webapp/src/cardFilter.ts index 90a9cd0f1..588ae7fc4 100644 --- a/webapp/src/cardFilter.ts +++ b/webapp/src/cardFilter.ts @@ -2,8 +2,8 @@ // See LICENSE.txt for license information. import {IPropertyTemplate} from './blocks/board' import {Card} from './blocks/card' -import {FilterClause} from './filterClause' -import {FilterGroup} from './filterGroup' +import {FilterClause} from './blocks/filterClause' +import {FilterGroup} from './blocks/filterGroup' import {Utils} from './utils' class CardFilter { diff --git a/webapp/src/components/filterComponent.tsx b/webapp/src/components/filterComponent.tsx index 7d0491290..8cb04f5e7 100644 --- a/webapp/src/components/filterComponent.tsx +++ b/webapp/src/components/filterComponent.tsx @@ -4,9 +4,10 @@ import React from 'react' import {FormattedMessage, injectIntl, IntlShape} from 'react-intl' import {IPropertyTemplate} from '../blocks/board' -import {FilterClause, FilterCondition} from '../filterClause' -import {FilterGroup} from '../filterGroup' +import {FilterClause, FilterCondition} from '../blocks/filterClause' +import {FilterGroup} from '../blocks/filterGroup' import mutator from '../mutator' +import {OctoUtils} from '../octoUtils' import {Utils} from '../utils' import {BoardTree} from '../viewModel/boardTree' import Button from '../widgets/buttons/button' @@ -91,7 +92,7 @@ class FilterComponent extends React.Component { - + block.id === newSourceBlockId)! return [newBlocks, newSourceBlock, idMap] } + + static filterConditionDisplayString(filterCondition: FilterCondition, intl: IntlShape): string { + switch (filterCondition) { + case 'includes': return intl.formatMessage({id: 'Filter.includes', defaultMessage: 'includes'}) + case 'notIncludes': return intl.formatMessage({id: 'Filter.not-includes', defaultMessage: 'doesn\'t include'}) + case 'isEmpty': return intl.formatMessage({id: 'Filter.is-empty', defaultMessage: 'is empty'}) + case 'isNotEmpty': return intl.formatMessage({id: 'Filter.is-not-empty', defaultMessage: 'is not empty'}) + default: { + Utils.assertFailure() + return '(unknown)' + } + } + } } export {OctoUtils} diff --git a/webapp/src/test/testBlockFactory.ts b/webapp/src/test/testBlockFactory.ts index f24b1495e..beca333dd 100644 --- a/webapp/src/test/testBlockFactory.ts +++ b/webapp/src/test/testBlockFactory.ts @@ -6,10 +6,10 @@ import {MutableBoardView} from '../blocks/boardView' import {Card, MutableCard} from '../blocks/card' import {MutableCommentBlock} from '../blocks/commentBlock' import {DividerBlock, MutableDividerBlock} from '../blocks/dividerBlock' +import {FilterClause} from '../blocks/filterClause' +import {FilterGroup} from '../blocks/filterGroup' import {ImageBlock, MutableImageBlock} from '../blocks/imageBlock' import {MutableTextBlock, TextBlock} from '../blocks/textBlock' -import {FilterClause} from '../filterClause' -import {FilterGroup} from '../filterGroup' class TestBlockFactory { static createBoard(): MutableBoard {