Skip to content

Commit

Permalink
[DataEntry] Auto merge new entry with empty selected dup sense (#2866)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored and jmgrady committed Mar 6, 2024
1 parent 245bca7 commit 2db5aff
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface SenseDialogProps {
selectedWord: Word;
open: boolean;
// Call handleClose with no input to indicate no selection was made.
handleClose: (gloss?: string) => void;
handleClose: (guid?: string) => void;
analysisLang: string;
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function SenseDialog(props: SenseDialogProps): ReactElement {

interface SenseListProps {
selectedWord: Word;
closeDialog: (gloss?: string) => void;
closeDialog: (guid?: string) => void;
analysisLang: string;
}

Expand All @@ -71,7 +71,7 @@ export function SenseList(props: SenseListProps): ReactElement {
<StyledMenuItem
id={sense.guid}
key={sense.guid}
onClick={() => props.closeDialog(gloss)}
onClick={() => props.closeDialog(sense.guid)}
>
<Grid
container
Expand Down
33 changes: 18 additions & 15 deletions src/components/DataEntry/DataEntryTable/NewEntry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface NewEntryProps {
// Parent component handles new entry state:
addNewEntry: () => Promise<void>;
resetNewEntry: () => void;
updateWordWithNewGloss: (wordId: string) => Promise<void>;
updateWordWithNewGloss: () => Promise<void>;
newAudio: Pronunciation[];
addNewAudio: (file: FileWithSpeakerId) => void;
delNewAudio: (url: string) => void;
Expand All @@ -59,7 +59,9 @@ interface NewEntryProps {
vernInput: RefObject<HTMLInputElement>;
// Parent component handles vern suggestion state:
selectedDup?: Word;
selectedSenseGuid?: string;
setSelectedDup: (id?: string) => void;
setSelectedSense: (guid?: string) => void;
suggestedVerns: string[];
suggestedDups: Word[];
}
Expand Down Expand Up @@ -88,7 +90,9 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
vernInput,
// Parent component handles vern suggestion state:
selectedDup,
selectedSenseGuid,
setSelectedDup,
setSelectedSense,
suggestedVerns,
suggestedDups,
} = props;
Expand Down Expand Up @@ -136,6 +140,11 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
}
}, [isTreeOpen, resetState, wasTreeClosed]);

/** Update whether the Sense dialog should be open. */
useEffect(() => {
setSenseOpen(!!selectedDup?.id && selectedSenseGuid === undefined);
}, [selectedDup, selectedSenseGuid]);

/** When the vern/sense dialogs are closed, focus needs to return to text fields.
* The following sets a flag (shouldFocus) to be triggered by conditionalFocus(),
* which is passed to each input component to call on update. */
Expand Down Expand Up @@ -172,7 +181,7 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
setVernOpen(true);
} else if (selectedDup.id) {
// Case 1b: User has selected an entry to modify
await updateWordWithNewGloss(selectedDup.id);
await updateWordWithNewGloss();
resetState();
} else {
// Case 1c: User has selected new entry
Expand Down Expand Up @@ -203,25 +212,19 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
if (id !== undefined) {
setSelectedDup(id);
}

if (id) {
setSenseOpen(true);
}

setVernOpen(false);
};

const handleCloseSenseDialog = (gloss?: string): void => {
if (gloss) {
setNewGloss(gloss);
} else if (gloss === undefined) {
// If gloss is undefined, the user exited the dialog without a selection.
const handleCloseSenseDialog = (guid?: string): void => {
if (guid === undefined) {
// If undefined, the user exited the dialog without a selection.
setSelectedDup();
setVernOpen(true);
} else {
// Set the selected dup sense to the one with the specified guid;
// an empty string indicates new sense for the selectedDup.
setSelectedSense(guid);
}
// else: an empty string indicates new sense for the selectedWord.

setSenseOpen(false);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe("NewEntry", () => {
vernInput={createRef<HTMLInputElement>()}
// Parent component handles vern suggestion state:
setSelectedDup={jest.fn()}
setSelectedSense={jest.fn()}
suggestedVerns={[]}
suggestedDups={[]}
/>
Expand Down
Loading

0 comments on commit 2db5aff

Please sign in to comment.