Skip to content

Commit 72d059f

Browse files
authored
[DataEntry] Migrate from deprecated Grid (#3880)
1 parent 2d0319d commit 72d059f

File tree

9 files changed

+182
-253
lines changed

9 files changed

+182
-253
lines changed

src/components/DataEntry/DataEntryHeader.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useTranslation } from "react-i18next";
55
import { Key } from "ts-key-enum";
66

77
import { SemanticDomainFull } from "api/models";
8-
import theme from "types/theme";
98

109
interface DataEntryHeaderProps {
1110
domain: SemanticDomainFull;
@@ -23,23 +22,19 @@ export default function DataEntryHeader(
2322
const { t } = useTranslation();
2423

2524
return (
26-
<Typography
27-
variant="h4"
28-
align="center"
29-
style={{ marginBottom: theme.spacing(2) }}
30-
>
25+
<Typography align="center" variant="h4">
3126
{t("addWords.domainTitle", { val1: domain.name, val2: domain.id })}
3227
<bdi>
3328
<Typography>{domain.description}</Typography>
3429
</bdi>
3530
<Switch
3631
id="questionVisibilitySwitch"
3732
onChange={() => props.setQuestionVisibility(!props.questionsVisible)}
38-
icon={<Help style={{ fontSize: 21 }} />}
39-
checkedIcon={<Help style={{ fontSize: 21 }} />}
33+
icon={<Help sx={{ fontSize: 19 }} />}
34+
checkedIcon={<Help sx={{ fontSize: 19 }} />}
4035
checked={props.questionsVisible}
4136
color="primary"
42-
style={{ paddingTop: "8px" }}
37+
sx={{ pt: "11px" }}
4338
disabled={!domain.questions.length}
4439
onKeyDown={(e) => {
4540
if (e.key === Key.Enter) {

src/components/DataEntry/DataEntryTable/NewEntry/VernDialog.tsx

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Dialog,
33
DialogContent,
4-
Grid,
4+
Grid2,
55
ListItemText,
66
MenuList,
77
Typography,
@@ -117,7 +117,7 @@ export function VernList(props: VernListProps): ReactElement {
117117
<StyledMenuItem
118118
key={sense?.guid ?? word.id}
119119
onClick={() => props.onSelect(word.id, sense?.guid)}
120-
sx={isSense ? { marginInlineStart: theme.spacing(4) } : conditionalGrey}
120+
sx={isSense ? { marginInlineStart: 4 } : conditionalGrey}
121121
>
122122
<DialogListItemText
123123
isSubitem={isSense}
@@ -163,7 +163,7 @@ export function VernList(props: VernListProps): ReactElement {
163163
<StyledMenuItem
164164
key={`${word.id}-new-sense`}
165165
onClick={() => props.onSelect(word.id, "")}
166-
sx={{ marginInlineStart: theme.spacing(4) }}
166+
sx={{ marginInlineStart: 4 }}
167167
>
168168
<DialogListItemText isSubitem text={t("addWords.newSense")} />
169169
</StyledMenuItem>
@@ -214,51 +214,38 @@ interface DialogListItemTextProps {
214214
const DialogListItemText = (props: DialogListItemTextProps): ReactElement => {
215215
return (
216216
<ListItemText>
217-
<Grid
217+
<Grid2
218218
alignItems="center"
219219
columnSpacing={4}
220220
container
221221
justifyContent="align-start"
222222
rowSpacing={1}
223223
>
224-
<Grid item xs="auto">
225-
<Typography variant={props.isSubitem ? "h6" : "h5"}>
226-
{props.text}
227-
</Typography>
228-
</Grid>
224+
<Typography variant={props.isSubitem ? "h6" : "h5"}>
225+
{props.text}
226+
</Typography>
227+
229228
{!!props.word && (
230229
<>
231230
{props.showGlosses && (
232-
<Grid item xs="auto">
233-
<SensesTextSummary
234-
definitionsOrGlosses="glosses"
235-
maxLengthPerSense={20}
236-
senses={props.word.senses}
237-
/>
238-
</Grid>
231+
<SensesTextSummary
232+
definitionsOrGlosses="glosses"
233+
maxLengthPerSense={20}
234+
senses={props.word.senses}
235+
/>
239236
)}
240237
{props.showDefinitions && (
241-
<Grid item xs="auto">
242-
<SensesTextSummary
243-
definitionsOrGlosses="definitions"
244-
maxLengthPerSense={50}
245-
senses={props.word.senses}
246-
/>
247-
</Grid>
248-
)}
249-
{props.showPartOfSpeech && (
250-
<Grid item xs="auto">
251-
<PartOfSpeechCell word={props.word} />
252-
</Grid>
253-
)}
254-
{props.showDomain && (
255-
<Grid item xs>
256-
<DomainsCell word={props.word} />
257-
</Grid>
238+
<SensesTextSummary
239+
definitionsOrGlosses="definitions"
240+
maxLengthPerSense={50}
241+
senses={props.word.senses}
242+
/>
258243
)}
244+
{props.showPartOfSpeech && <PartOfSpeechCell word={props.word} />}
245+
{props.showDomain && <DomainsCell word={props.word} />}
259246
</>
260247
)}
261-
</Grid>
248+
</Grid2>
262249
</ListItemText>
263250
);
264251
};

src/components/DataEntry/DataEntryTable/NewEntry/index.tsx

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { AutocompleteCloseReason, Grid, Typography } from "@mui/material";
1+
import { AutocompleteCloseReason, Grid2, Typography } from "@mui/material";
22
import {
3-
CSSProperties,
43
ReactElement,
54
RefObject,
65
useCallback,
@@ -22,7 +21,6 @@ import VernDialog from "components/DataEntry/DataEntryTable/NewEntry/VernDialog"
2221
import { focusInput } from "components/DataEntry/utilities";
2322
import PronunciationsFrontend from "components/Pronunciations/PronunciationsFrontend";
2423
import { type StoreState } from "rootRedux/types";
25-
import theme from "types/theme";
2624
import { FileWithSpeakerId } from "types/word";
2725

2826
export enum NewEntryId {
@@ -38,11 +36,6 @@ export enum FocusTarget {
3836
Vernacular,
3937
}
4038

41-
const gridItemStyle = (spacing: number): CSSProperties => ({
42-
paddingInline: theme.spacing(spacing),
43-
position: "relative",
44-
});
45-
4639
interface NewEntryProps {
4740
analysisLang: WritingSystem;
4841
vernacularLang: WritingSystem;
@@ -224,44 +217,48 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
224217
};
225218

226219
return (
227-
<Grid alignItems="center" container id={NewEntryId.GridNewEntry}>
228-
<Grid container item xs={4} style={gridItemStyle(2)}>
229-
<Grid item xs={12}>
230-
<VernWithSuggestions
231-
isNew
232-
vernacular={newVern}
233-
vernInput={vernInput}
234-
updateVernField={(newValue: string, openDialog?: boolean) =>
235-
updateVernField(newValue, openDialog)
220+
<Grid2
221+
alignItems="center"
222+
container
223+
id={NewEntryId.GridNewEntry}
224+
spacing={1}
225+
>
226+
<Grid2 size={4}>
227+
<VernWithSuggestions
228+
isNew
229+
vernacular={newVern}
230+
vernInput={vernInput}
231+
updateVernField={(newValue: string, openDialog?: boolean) =>
232+
updateVernField(newValue, openDialog)
233+
}
234+
onBlur={() => setVernOpen(true)}
235+
onClose={(_, reason: AutocompleteCloseReason) => {
236+
// Handle if the user fully types an identical vernacular to a suggestion
237+
// and selects it from the Autocomplete. This should open the dialog.
238+
if (reason === "selectOption") {
239+
// User pressed Enter or Left Click on an item.
240+
setVernOpen(true);
236241
}
237-
onBlur={() => setVernOpen(true)}
238-
onClose={(_, reason: AutocompleteCloseReason) => {
239-
// Handle if the user fully types an identical vernacular to a suggestion
240-
// and selects it from the Autocomplete. This should open the dialog.
241-
if (reason === "selectOption") {
242-
// User pressed Enter or Left Click on an item.
243-
setVernOpen(true);
244-
}
245-
}}
246-
onFocus={handleOnVernFocus}
247-
suggestedVerns={suggestedVerns}
248-
// To prevent unintentional no-gloss or wrong-gloss submissions
249-
// and to simplify interactions with Autocomplete and with the dialogs:
250-
// if Enter is pressed from the vern field, move focus to gloss field.
251-
handleEnter={() => focus(FocusTarget.Gloss)}
252-
vernacularLang={vernacularLang}
253-
textFieldId={NewEntryId.TextFieldVern}
254-
onUpdate={() => conditionalFocus(FocusTarget.Vernacular)}
255-
/>
256-
<VernDialog
257-
open={vernOpen && !!suggestedDups.length && !selectedDup}
258-
handleClose={handleCloseVernDialog}
259-
vernacularWords={suggestedDups}
260-
analysisLang={analysisLang.bcp47}
261-
/>
262-
</Grid>
263-
</Grid>
264-
<Grid item xs={4} style={gridItemStyle(1)}>
242+
}}
243+
onFocus={handleOnVernFocus}
244+
suggestedVerns={suggestedVerns}
245+
// To prevent unintentional no-gloss or wrong-gloss submissions
246+
// and to simplify interactions with Autocomplete and with the dialogs:
247+
// if Enter is pressed from the vern field, move focus to gloss field.
248+
handleEnter={() => focus(FocusTarget.Gloss)}
249+
vernacularLang={vernacularLang}
250+
textFieldId={NewEntryId.TextFieldVern}
251+
onUpdate={() => conditionalFocus(FocusTarget.Vernacular)}
252+
/>
253+
<VernDialog
254+
open={vernOpen && !!suggestedDups.length && !selectedDup}
255+
handleClose={handleCloseVernDialog}
256+
vernacularWords={suggestedDups}
257+
analysisLang={analysisLang.bcp47}
258+
/>
259+
</Grid2>
260+
261+
<Grid2 size={4}>
265262
<GlossWithSuggestions
266263
isNew
267264
gloss={newGloss}
@@ -272,8 +269,9 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
272269
textFieldId={NewEntryId.TextFieldGloss}
273270
onUpdate={() => conditionalFocus(FocusTarget.Gloss)}
274271
/>
275-
</Grid>
276-
<Grid item xs={1} style={gridItemStyle(1)}>
272+
</Grid2>
273+
274+
<Grid2 size={1}>
277275
{!selectedDup?.id && (
278276
// note is not available if user selected to modify an existing entry
279277
<NoteButton
@@ -282,32 +280,35 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
282280
updateNote={setNewNote}
283281
/>
284282
)}
285-
</Grid>
286-
<Grid item xs={2} style={gridItemStyle(1)}>
283+
</Grid2>
284+
285+
<Grid2 size={2}>
287286
<PronunciationsFrontend
288287
audio={newAudio}
289288
deleteAudio={delNewAudio}
290289
replaceAudio={repNewAudio}
291290
uploadAudio={addNewAudio}
292291
onClick={() => focus(FocusTarget.Gloss)}
293292
/>
294-
</Grid>
295-
<Grid item xs={1} style={gridItemStyle(1)}>
293+
</Grid2>
294+
295+
<Grid2 size={1}>
296296
<DeleteEntry
297297
buttonId={NewEntryId.ButtonDelete}
298298
removeEntry={() => resetState()}
299299
/>
300-
</Grid>
300+
</Grid2>
301+
301302
<EnterGrid />
302-
</Grid>
303+
</Grid2>
303304
);
304305
}
305306

306307
function EnterGrid(): ReactElement {
307308
const { t } = useTranslation();
308309
return (
309-
<Grid item xs={12} style={{ paddingInlineStart: theme.spacing(2) }}>
310+
<Grid2 size={12} sx={{ paddingInlineStart: 1 }}>
310311
<Typography variant="body2">{t("addWords.pressEnter")}</Typography>
311-
</Grid>
312+
</Grid2>
312313
);
313314
}

0 commit comments

Comments
 (0)