Skip to content

Commit

Permalink
Gloss autocomplete (#512)
Browse files Browse the repository at this point in the history
Replace gloss spelling suggestions with dropdown menu
  • Loading branch information
imnasnainaec authored Jul 24, 2020
1 parent 15896f8 commit 4bf11c6
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 669 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.56",
"@material-ui/styles": "^4.10.0",
"@matt-block/react-recaptcha-v2": "^1.0.6",
"axios": "^0.19.2",
Expand Down
93 changes: 31 additions & 62 deletions src/components/DataEntry/DataEntryTable/DataEntryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import DomainTree from "../../../types/SemanticDomain";
import theme from "../../../types/theme";
import { SemanticDomain, Word } from "../../../types/word";
import Recorder from "../../Pronunciations/Recorder";
import SpellChecker from "../spellChecker";
import { ExistingEntry } from "./ExistingEntry/ExistingEntry";
import { ImmutableExistingEntry } from "./ExistingEntry/ImmutableExistingEntry";
import { NewEntry } from "./NewEntry/NewEntry";
Expand Down Expand Up @@ -66,11 +65,9 @@ export class DataEntryTable extends React.Component<
};
this.refNewEntry = React.createRef<NewEntry>();
this.recorder = new Recorder();
this.spellChecker = new SpellChecker();
}
refNewEntry: React.RefObject<NewEntry>;
recorder: Recorder;
spellChecker: SpellChecker;

async componentDidMount() {
let allWords = await this.props.getWordsFromBackend();
Expand Down Expand Up @@ -239,40 +236,29 @@ export class DataEntryTable extends React.Component<

{this.state.recentlyAddedWords.map((wordAccess, index) =>
wordAccess.mutable ? (
<React.Fragment key={wordAccess.word.id}>
<ExistingEntry
key={wordAccess.word.id}
wordsBeingAdded={this.state.recentlyAddedWords.map(
(wordAccess) => wordAccess.word
)}
existingWords={this.state.existingWords}
entryIndex={index}
entry={wordAccess.word}
updateWord={(wordToUpdate: Word, wordToDelete?: Word) =>
this.updateExistingWord(wordToUpdate, wordToDelete)
}
removeWord={(word: Word) => this.removeWord(word)}
recorder={this.recorder}
spellChecker={this.spellChecker}
semanticDomain={this.props.semanticDomain}
displayDuplicates={
this.state.displayDuplicatesIndex === index
}
toggleDisplayDuplicates={() => {
this.toggleDisplayDuplicates(index);
}}
displaySpellingSuggestions={
this.state.displaySpellingSuggestionsIndex === index
}
toggleDisplaySpellingSuggestions={() => {
this.toggleDisplaySpellingSuggestions(index);
}}
focusNewEntry={() => {
if (this.refNewEntry.current)
this.refNewEntry.current.focusVernInput();
}}
/>
</React.Fragment>
<ExistingEntry
key={wordAccess.word.id}
wordsBeingAdded={this.state.recentlyAddedWords.map(
(wordAccess) => wordAccess.word
)}
existingWords={this.state.existingWords}
entryIndex={index}
entry={wordAccess.word}
updateWord={(wordToUpdate: Word, wordToDelete?: Word) =>
this.updateExistingWord(wordToUpdate, wordToDelete)
}
removeWord={(word: Word) => this.removeWord(word)}
recorder={this.recorder}
semanticDomain={this.props.semanticDomain}
displayDuplicates={this.state.displayDuplicatesIndex === index}
toggleDisplayDuplicates={() => {
this.toggleDisplayDuplicates(index);
}}
focusNewEntry={() => {
if (this.refNewEntry.current)
this.refNewEntry.current.focusVernInput();
}}
/>
) : (
<ImmutableExistingEntry
key={wordAccess.word.id}
Expand All @@ -292,7 +278,6 @@ export class DataEntryTable extends React.Component<
this.updateWordForNewEntry(wordToUpdate, glossIndex)
}
addNewWord={(word: Word) => this.addNewWord(word)}
spellChecker={this.spellChecker}
semanticDomain={this.props.semanticDomain}
autocompleteSetting={this.state.autoComplete}
displayDuplicates={
Expand All @@ -305,15 +290,6 @@ export class DataEntryTable extends React.Component<
this.state.recentlyAddedWords.length
);
}}
displaySpellingSuggestions={
this.state.displaySpellingSuggestionsIndex ===
this.state.recentlyAddedWords.length
}
toggleDisplaySpellingSuggestions={() => {
this.toggleDisplaySpellingSuggestions(
this.state.recentlyAddedWords.length
);
}}
setIsReadyState={(isReady: boolean) =>
this.setState({ isReady: isReady })
}
Expand All @@ -340,29 +316,22 @@ export class DataEntryTable extends React.Component<
color={this.state.isReady ? "primary" : "secondary"}
style={{ marginTop: theme.spacing(2) }}
onClick={() => {
// Check if there is a new word, but the user clicked complete instead of pressing enter
if (this.refNewEntry.current) {
let newEntry = this.refNewEntry.current.state.newEntry;
if (
newEntry &&
newEntry.vernacular &&
newEntry.vernacular !== ""
) {
this.addNewWord(newEntry).then(() => {
// When the server responds clear out recently added words so
// this word doesn't appear in the next domain
let recentlyAddedWords: WordAccess[] = [];
this.setState({ recentlyAddedWords });
});
// clear the data from the NewEntry fields
if (newEntry && newEntry.vernacular) {
this.addNewWord(newEntry);
this.refNewEntry.current.resetState();
}
}

// Reset everything
this.props.hideQuestions();
let recentlyAddedWords: WordAccess[] = [];
this.props.displaySemanticDomainView(true);
this.setState({ recentlyAddedWords });

//Since DataEntryComponent isn't rerendered, just hidden, this will enforce questions being hidden as a default
this.props.hideQuestions();
// Reveal the TreeView, hiding DataEntry
this.props.displaySemanticDomainView(true);
}}
>
<Translate id="addWords.done" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React from "react";
import ReactDOM from "react-dom";
import { DuplicateResolutionView } from "../DuplicateResolutionView";
import renderer from "react-test-renderer";

import { Word, Sense } from "../../../../../types/word";
import { mockWord } from "../../../tests/MockWord";
import { DuplicateResolutionView } from "../DuplicateResolutionView";

describe("Tests DeleteEntry", () => {
describe("Tests DuplicateResolutionView", () => {
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(
<DuplicateResolutionView
existingEntry={mockWord}
newSense={""}
addSense={(existingWord: Word, newSense: string) => null}
addSemanticDomain={(
existingWord: Word,
sense: Sense,
index: number
) => {}}
/>,
div
);
ReactDOM.unmountComponentAtNode(div);
renderer.act(() => {
renderer.create(
<DuplicateResolutionView
existingEntry={mockWord}
newSense={""}
addSense={(existingWord: Word, newSense: string) => null}
addSemanticDomain={(
existingWord: Word,
sense: Sense,
index: number
) => {}}
duplicateInput={React.createRef<HTMLDivElement>()}
/>
);
});
});
});
Loading

0 comments on commit 4bf11c6

Please sign in to comment.