From 75c2fb0b24e6968696e551a86a0667dbd7b1647b Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Tue, 3 Nov 2020 16:21:41 -0500 Subject: [PATCH 1/2] [NewEntry] Allow submission with no gloss --- .../DataEntryTable/NewEntry/NewEntry.tsx | 27 ++++++++++--------- src/types/word.tsx | 7 +++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx index 9674cc845d..04727428c1 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx @@ -6,7 +6,7 @@ import DupFinder, { DefaultParams, } from "../../../../goals/MergeDupGoal/DuplicateFinder/DuplicateFinder"; import theme from "../../../../types/theme"; -import { SemanticDomain, Word } from "../../../../types/word"; +import { SemanticDomain, Sense, Word } from "../../../../types/word"; import Pronunciations from "../../../Pronunciations/PronunciationsComponent"; import Recorder from "../../../Pronunciations/Recorder"; import GlossWithSuggestions from "../GlossWithSuggestions/GlossWithSuggestions"; @@ -99,12 +99,7 @@ export default class NewEntry extends React.Component< this.setState((prevState, props) => ({ newEntry: { ...prevState.newEntry, - senses: [ - { - glosses: [{ language: props.analysisLang, def: newValue }], - semanticDomains: [props.semanticDomain], - }, - ], + senses: [new Sense(newValue, props.analysisLang, props.semanticDomain)], }, activeGloss: newValue, })); @@ -161,7 +156,15 @@ export default class NewEntry extends React.Component< } addNewWordAndReset() { - this.props.addNewWord(this.state.newEntry, this.state.audioFileURLs); + const newEntry: Word = this.state.newEntry.senses.length + ? this.state.newEntry + : { + ...this.state.newEntry, + senses: [ + new Sense("", this.props.analysisLang, this.props.semanticDomain), + ], + }; + this.props.addNewWord(newEntry, this.state.audioFileURLs); this.resetState(); } @@ -193,10 +196,10 @@ export default class NewEntry extends React.Component< } } - handleEnterAndTab(e: React.KeyboardEvent) { + handleEnter(e: React.KeyboardEvent, checkGloss = true) { if (!this.state.vernOpen && e.key === "Enter") { if (this.state.newEntry.vernacular) { - if (this.state.activeGloss) { + if (this.state.activeGloss || !checkGloss) { this.addOrUpdateWord(); this.focusVernInput(); } else { @@ -312,7 +315,7 @@ export default class NewEntry extends React.Component< }} suggestedVerns={this.state.suggestedVerns} handleEnterAndTab={(e: React.KeyboardEvent) => - this.handleEnterAndTab(e) + this.handleEnter(e) } /> - this.handleEnterAndTab(e) + this.handleEnter(e, false) } analysisLang={this.props.analysisLang} /> diff --git a/src/types/word.tsx b/src/types/word.tsx index 2ca51db946..4751571c4d 100644 --- a/src/types/word.tsx +++ b/src/types/word.tsx @@ -22,8 +22,11 @@ export class Sense { semanticDomains: SemanticDomain[] = []; accessibility?: State; - constructor(gloss: string, language?: string) { - this.glosses = [{ def: gloss, language: language ? language : "" }]; + constructor(gloss: string, language?: string, semDom?: SemanticDomain) { + this.glosses = [{ def: gloss, language: language ?? "" }]; + if (semDom) { + this.semanticDomains.push(semDom); + } } } From 57681c72ba43a7c6d1e09d96cb18029dfd2a83e5 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Tue, 3 Nov 2020 17:54:08 -0500 Subject: [PATCH 2/2] Add comments --- .../DataEntry/DataEntryTable/NewEntry/NewEntry.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx index 04727428c1..1ffb6a2804 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/NewEntry.tsx @@ -196,9 +196,11 @@ export default class NewEntry extends React.Component< } } - handleEnter(e: React.KeyboardEvent, checkGloss = true) { + handleEnter(e: React.KeyboardEvent, checkGloss: boolean) { if (!this.state.vernOpen && e.key === "Enter") { + // The user can never submit a new entry without a vernacular if (this.state.newEntry.vernacular) { + // The user can conditionally submit a new entry without a gloss if (this.state.activeGloss || !checkGloss) { this.addOrUpdateWord(); this.focusVernInput(); @@ -315,7 +317,10 @@ export default class NewEntry extends React.Component< }} suggestedVerns={this.state.suggestedVerns} handleEnterAndTab={(e: React.KeyboardEvent) => - this.handleEnter(e) + // To prevent unintentional no-gloss submissions: + // If enter pressed from the vern field, + // check whether gloss is empty + this.handleEnter(e, true) } /> + // To allow intentional no-gloss submissions: + // If enter pressed from the gloss field, + // don't check whether gloss is empty this.handleEnter(e, false) } analysisLang={this.props.analysisLang}