From 9ac8d2b0f9c46042500bf72bcc7980636cb7af29 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Wed, 14 Oct 2020 17:58:11 -0700 Subject: [PATCH] Fix filter assert --- src/client/cardFilter.ts | 19 ++++++++++++++----- src/client/components/boardComponent.tsx | 7 ++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/client/cardFilter.ts b/src/client/cardFilter.ts index 7e69aba21..28dd14768 100644 --- a/src/client/cardFilter.ts +++ b/src/client/cardFilter.ts @@ -55,22 +55,31 @@ class CardFilter { case "isNotEmpty": { return !!value } + default: { + Utils.assertFailure(`Invalid filter condition ${filter.condition}`) + } } - Utils.assertFailure(`Invalid filter condition ${filter.condition}`) return true } - static propertiesThatMeetFilterGroup(filterGroup: FilterGroup, templates: IPropertyTemplate[]): Record { + static propertiesThatMeetFilterGroup(filterGroup: FilterGroup, templates: IPropertyTemplate[]): Record { // TODO: Handle filter groups const filters = filterGroup.filters.filter(o => !FilterGroup.isAnInstanceOf(o)) - if (filters.length < 1) { return [] } + if (filters.length < 1) { return {} } if (filterGroup.operation === "or") { // Just need to meet the first clause const property = this.propertyThatMeetsFilterClause(filters[0] as FilterClause, templates) - return [property] + const result: Record = {} + result[property.id] = property.value + return result } else { - return filters.map(filterClause => this.propertyThatMeetsFilterClause(filterClause as FilterClause, templates)) + const result: Record = {} + filters.forEach(filterClause => { + const p = this.propertyThatMeetsFilterClause(filterClause as FilterClause, templates) + result[p.id] = p.value + }) + return result } } diff --git a/src/client/components/boardComponent.tsx b/src/client/components/boardComponent.tsx index 46bff9a3c..1266f893e 100644 --- a/src/client/components/boardComponent.tsx +++ b/src/client/components/boardComponent.tsx @@ -7,6 +7,7 @@ import { Card } from "../card" import { CardFilter } from "../cardFilter" import ViewMenu from "../components/viewMenu" import { Constants } from "../constants" +import { randomEmojiList } from "../emojiList" import { Menu as OldMenu } from "../menu" import { Mutator } from "../mutator" import { OctoUtils } from "../octoUtils" @@ -309,9 +310,11 @@ class BoardComponent extends React.Component { } case "testAdd100Cards": { this.testAddCards(100) + break } case "testAdd1000Cards": { this.testAddCards(1000) + break } } } @@ -322,6 +325,7 @@ class BoardComponent extends React.Component { const { mutator, boardTree } = this.props const { board, activeView } = boardTree + const startCount = boardTree?.cards?.length let optionIndex = 0 for (let i = 0; i < count; i++) { @@ -333,7 +337,8 @@ class BoardComponent extends React.Component { const option = boardTree.groupByProperty.options[optionIndex] optionIndex = (optionIndex + 1) % boardTree.groupByProperty.options.length card.properties[boardTree.groupByProperty.id] = option.value - card.title = `Test Card ${i + 1}` + card.title = `Test Card ${startCount + i + 1}` + card.icon = BlockIcons.shared.randomIcon() } await mutator.insertBlock(card, "test add card") }