From 066337235e0239190f33db061a91832ce684374e Mon Sep 17 00:00:00 2001 From: stew-ro Date: Tue, 5 May 2020 16:34:55 -0700 Subject: [PATCH 1/3] refactor: check tag type and region catagory compatibility --- .../components/common/tagInput/tagInput.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/react/components/common/tagInput/tagInput.tsx b/src/react/components/common/tagInput/tagInput.tsx index 2e46198e9..97821be1c 100644 --- a/src/react/components/common/tagInput/tagInput.tsx +++ b/src/react/components/common/tagInput/tagInput.tsx @@ -472,16 +472,13 @@ export class TagInput extends React.Component { if (selectedRegions && selectedRegions.length && onTagClick) { const { category } = selectedRegions[0]; const { format, type, documentCount } = tag; - switch (true) { - case this.isSelectionMark(category) && this.isSelectionMark(type): - case !this.isSelectionMark(category) && !this.isSelectionMark(type): - case documentCount === 0 && type === FieldType.String && format === FieldFormat.NotSpecified: + const tagCatagory = this.getTagCatagory(type); + if (tagCatagory === category || + (documentCount === 0 && type === FieldType.String && format === FieldFormat.NotSpecified)) { onTagClick(tag); deselect = false; - break; - default: - toast.warn(strings.tags.warnings.notCompatibleTagType); - break; + } else { + toast.warn(strings.tags.warnings.notCompatibleTagType); } } this.setState({ @@ -492,6 +489,15 @@ export class TagInput extends React.Component { } } + private getTagCatagory = (tagType: string) => { + switch (tagType) { + case FieldType.SelectionMark: + return "checkbox"; + default: + return "text"; + } + } + private onSearchKeyDown = (event: KeyboardEvent): void => { if (event.key === "Escape") { this.setState({ From 7b323d6a72863fd5d828d5969035384031ddc4fa Mon Sep 17 00:00:00 2001 From: alex-krasn Date: Tue, 5 May 2020 17:10:51 -0700 Subject: [PATCH 2/3] refactor and spelling --- src/react/components/common/tagInput/tagInput.tsx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/react/components/common/tagInput/tagInput.tsx b/src/react/components/common/tagInput/tagInput.tsx index 97821be1c..52e67b663 100644 --- a/src/react/components/common/tagInput/tagInput.tsx +++ b/src/react/components/common/tagInput/tagInput.tsx @@ -472,8 +472,8 @@ export class TagInput extends React.Component { if (selectedRegions && selectedRegions.length && onTagClick) { const { category } = selectedRegions[0]; const { format, type, documentCount } = tag; - const tagCatagory = this.getTagCatagory(type); - if (tagCatagory === category || + const tagCategory = this.getTagCategory(type); + if (tagCategory === category || (documentCount === 0 && type === FieldType.String && format === FieldFormat.NotSpecified)) { onTagClick(tag); deselect = false; @@ -489,14 +489,7 @@ export class TagInput extends React.Component { } } - private getTagCatagory = (tagType: string) => { - switch (tagType) { - case FieldType.SelectionMark: - return "checkbox"; - default: - return "text"; - } - } + private getTagCategory = (tagType: string) => tagType === FieldType.SelectionMark ? "checkbox" : "text"; private onSearchKeyDown = (event: KeyboardEvent): void => { if (event.key === "Escape") { From f3e167013ae518b63cd30da17439a98950737540 Mon Sep 17 00:00:00 2001 From: alex-krasn Date: Tue, 5 May 2020 17:15:13 -0700 Subject: [PATCH 3/3] refactor: getCategory back to switch --- src/react/components/common/tagInput/tagInput.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/react/components/common/tagInput/tagInput.tsx b/src/react/components/common/tagInput/tagInput.tsx index 52e67b663..e84588149 100644 --- a/src/react/components/common/tagInput/tagInput.tsx +++ b/src/react/components/common/tagInput/tagInput.tsx @@ -489,7 +489,14 @@ export class TagInput extends React.Component { } } - private getTagCategory = (tagType: string) => tagType === FieldType.SelectionMark ? "checkbox" : "text"; + private getTagCategory = (tagType: string) => { + switch (tagType) { + case FieldType.SelectionMark: + return "checkbox"; + default: + return "text"; + } + } private onSearchKeyDown = (event: KeyboardEvent): void => { if (event.key === "Escape") {