From 79474926895d343d28a6719c6140e7a66a0d4c61 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Mon, 18 Sep 2023 09:21:26 -0400 Subject: [PATCH] Disable GlossCell, DefinitionCell when sense being deleted (#2575) Also, finish work in DefinitionCell to match updates to GlossCell from #2493. --- src/components/Overlay/index.tsx | 18 ++++ .../CellComponents/DefinitionCell.tsx | 91 ++++++++++--------- .../CellComponents/DomainCell.tsx | 83 +++++++++-------- .../CellComponents/GlossCell.tsx | 40 ++++---- 4 files changed, 130 insertions(+), 102 deletions(-) create mode 100644 src/components/Overlay/index.tsx diff --git a/src/components/Overlay/index.tsx b/src/components/Overlay/index.tsx new file mode 100644 index 0000000000..921b2147ae --- /dev/null +++ b/src/components/Overlay/index.tsx @@ -0,0 +1,18 @@ +import { ReactElement, ReactNode } from "react"; + +interface OverlayProps { + children?: ReactNode; + on?: boolean; +} + +export default function Overlay(props: OverlayProps): ReactElement { + return ( +
+ {props.children} +
+ ); +} diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DefinitionCell.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DefinitionCell.tsx index 83abb70f5b..bade811c7c 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DefinitionCell.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DefinitionCell.tsx @@ -1,18 +1,20 @@ -import { Input } from "@mui/material"; +import { Typography } from "@mui/material"; import { ReactElement } from "react"; import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; -import { Definition } from "api/models"; +import { Definition, WritingSystem } from "api/models"; +import Overlay from "components/Overlay"; import { FieldParameterStandard } from "goals/ReviewEntries/ReviewEntriesComponent/CellColumns"; import AlignedList, { SPACER, } from "goals/ReviewEntries/ReviewEntriesComponent/CellComponents/AlignedList"; -import { ReviewEntriesSense } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; import { StoreState } from "types"; -import { themeColors } from "types/theme"; import { newDefinition } from "types/word"; -import { TextFieldWithFont } from "utilities/fontComponents"; +import { + TextFieldWithFont, + TypographyWithFont, +} from "utilities/fontComponents"; interface DefinitionCellProps extends FieldParameterStandard { editable?: boolean; @@ -24,20 +26,19 @@ export default function DefinitionCell( ): ReactElement { const analysisLang = useSelector( (state: StoreState) => - state.currentProjectState.project.analysisWritingSystems[0].bcp47 + state.currentProjectState.project.analysisWritingSystems[0] ); - const { t } = useTranslation(); return ( - props.editable ? ( + contents={props.rowData.senses.map((sense, index) => ( + props.onRowDataChange && props.onRowDataChange({ @@ -53,54 +54,59 @@ export default function DefinitionCell( }) } /> - ) : ( - - ) - )} + + ))} bottomCell={props.editable ? SPACER : undefined} /> ); } interface DefinitionListProps { + defaultLang: WritingSystem; definitions: Definition[]; - defaultLang: string; - keyPrefix: string; + editable?: boolean; + idPrefix: string; onChange: (definitions: Definition[]) => void; } function DefinitionList(props: DefinitionListProps): ReactElement { - const langs = props.definitions.map((g) => g.language); - const definitions = langs.includes(props.defaultLang) + const { t } = useTranslation(); + + if (!props.editable) { + if (!props.definitions.find((d) => d.text)) { + return {t("reviewEntries.noDefinition")}; + } + return ( + <> + {props.definitions + .filter((d) => d.text) + .map((d, i) => ( + + {d.text} + + ))} + + ); + } + + const definitions = props.definitions.find( + (d) => d.language === props.defaultLang.bcp47 + ) ? props.definitions - : [...props.definitions, newDefinition("", props.defaultLang)]; + : [...props.definitions, newDefinition("", props.defaultLang.bcp47)]; return ( <> - {definitions.map((g, i) => ( + {definitions.map((d, i) => ( { const updatedDefinitions = [...definitions]; updatedDefinitions.splice(i, 1, definition); props.onChange(updatedDefinitions); }} + textFieldId={`${props.idPrefix}-${i}-text`} /> ))} @@ -125,10 +131,9 @@ function DefinitionField(props: DefinitionFieldProps): ReactElement { value={props.definition.text} error={props.definition.text.length === 0} onChange={(event) => - props.onChange({ - language: props.definition.language, - text: event.target.value, - }) + props.onChange( + newDefinition(event.target.value, props.definition.language) + ) } /> ); diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx index 76f8809bcb..b20de93704 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx @@ -1,12 +1,13 @@ import { Add } from "@mui/icons-material"; import { Chip, Dialog, Grid, IconButton } from "@mui/material"; -import React, { ReactElement, useState } from "react"; +import { ReactElement, useState } from "react"; import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; import { toast } from "react-toastify"; import { SemanticDomain } from "api/models"; import { getCurrentUser } from "backend/localStorage"; +import Overlay from "components/Overlay"; import TreeView from "components/TreeView"; import AlignedList, { SPACER, @@ -96,51 +97,53 @@ export default function DomainCell(props: DomainCellProps): ReactElement { const { t } = useTranslation(); return ( - + <> ( - - {sense.domains.length > 0 ? ( - sense.domains.map((domain, domainIndex) => ( - + + + {sense.domains.length > 0 ? ( + sense.domains.map((domain, domainIndex) => ( + + deleteDomain(domain, sense) + : undefined + } + id={`sense-${sense.guid}-domain-${domainIndex}`} + /> + + )) + ) : ( + deleteDomain(domain, sense) - : undefined - } - id={`sense-${sense.guid}-domain-${domainIndex}`} + label={t("reviewEntries.noDomain")} + color={props.sortingByThis ? "default" : "secondary"} + style={getChipStyle(senseIndex, 0)} /> - )) - ) : ( - - - - )} - {props.editDomains && !sense.deleted && ( - prepAddDomain(sense)} - id={`sense-${sense.guid}-domain-add`} - size="large" - > - - - )} - + )} + {props.editDomains && !sense.deleted && ( + prepAddDomain(sense)} + id={`sense-${sense.guid}-domain-add`} + size="large" + > + + + )} + + ))} bottomCell={props.editDomains ? SPACER : undefined} /> @@ -150,6 +153,6 @@ export default function DomainCell(props: DomainCellProps): ReactElement { returnControlToCaller={addDomain} /> - + ); } diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/GlossCell.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/GlossCell.tsx index 057e252964..72e66f37e6 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/GlossCell.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/GlossCell.tsx @@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next"; import { useSelector } from "react-redux"; import { Gloss, WritingSystem } from "api/models"; +import Overlay from "components/Overlay"; import { FieldParameterStandard } from "goals/ReviewEntries/ReviewEntriesComponent/CellColumns"; import AlignedList, { SPACER, @@ -30,24 +31,25 @@ export default function GlossCell(props: GlossCellProps): ReactElement { ( - - props.onRowDataChange && - props.onRowDataChange({ - ...props.rowData, - senses: [ - ...props.rowData.senses.slice(0, index), - { ...sense, glosses }, - ...props.rowData.senses.slice(index + 1), - ], - }) - } - /> + + + props.onRowDataChange && + props.onRowDataChange({ + ...props.rowData, + senses: [ + ...props.rowData.senses.slice(0, index), + { ...sense, glosses }, + ...props.rowData.senses.slice(index + 1), + ], + }) + } + /> + ))} bottomCell={props.editable ? SPACER : undefined} /> @@ -94,12 +96,12 @@ function GlossList(props: GlossListProps): ReactElement { { const updatedGlosses = [...glosses]; updatedGlosses.splice(i, 1, gloss); props.onChange(updatedGlosses); }} + textFieldId={`${props.idPrefix}-${i}-text`} /> ))}