Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MergeDups] Fix column overflow & flag bug #2104

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { flagWord, setVern } from "goals/MergeDupGoal/Redux/MergeDupActions";
import { MergeTreeState } from "goals/MergeDupGoal/Redux/MergeDupReduxTypes";
import { useAppDispatch } from "types/hooks";
import theme from "types/theme";
import { newFlag } from "types/word";

interface DropWordProps {
mergeState: MergeTreeState;
Expand All @@ -25,7 +24,6 @@ export default function DropWord(props: DropWordProps): ReactElement {

const treeWord = props.mergeState.tree.words[props.wordId];
const data = props.mergeState.data;
const flag = data.words[props.wordId]?.flag ?? newFlag();
let protectedWithOneChild = false;
const verns: string[] = [];
if (treeWord) {
Expand Down Expand Up @@ -88,7 +86,7 @@ export default function DropWord(props: DropWordProps): ReactElement {
/>
)}
<FlagButton
flag={flag}
flag={treeWord.flag}
updateFlag={(newFlag: Flag) => {
dispatch(flagWord(props.wordId, newFlag));
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Delete } from "@mui/icons-material";
import { Drawer, ImageListItem, Tooltip } from "@mui/material";
import { Drawer, ImageList, ImageListItem, Tooltip } from "@mui/material";
import { ReactElement, useState } from "react";
import { DragDropContext, Droppable, DropResult } from "react-beautiful-dnd";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -118,39 +118,44 @@ export default function MergeDragDrop(): ReactElement {
}

const newId = v4();
const colCount = Object.keys(treeWords).length + 2; // +2 for trash and extra empty word

return (
<DragDropContext onDragEnd={handleDrop}>
<ImageListItem key={"trash"} style={{ marginTop: "70vh" }}>
<Droppable key={trashId} droppableId={trashId}>
{(provided): ReactElement => (
<div ref={provided.innerRef}>
<Tooltip title={t("mergeDups.helpText.delete")} placement="top">
<Delete fontSize="large" />
</Tooltip>
<div style={{ position: "absolute" }}>{provided.placeholder}</div>
</div>
)}
</Droppable>
</ImageListItem>
{Object.keys(treeWords).map((key) => (
<ImageListItem
key={key}
style={{ height: "70vh", margin: theme.spacing(1) }}
>
<DropWord mergeState={mergeState} wordId={key} />
<ImageList rowHeight="auto" cols={colCount}>
<ImageListItem key={"trash"} style={{ marginTop: "70vh" }}>
<Droppable key={trashId} droppableId={trashId}>
{(provided): ReactElement => (
<div ref={provided.innerRef}>
<Tooltip title={t("mergeDups.helpText.delete")} placement="top">
<Delete fontSize="large" />
</Tooltip>
<div style={{ position: "absolute" }}>
{provided.placeholder}
</div>
</div>
)}
</Droppable>
</ImageListItem>
))}
<ImageListItem key={newId} style={{ margin: theme.spacing(1) }}>
<DropWord mergeState={mergeState} wordId={newId} />
</ImageListItem>
{renderSidebar()}
<CancelConfirmDialog
open={!!senseToDelete}
textId="mergeDups.helpText.deleteDialog"
handleCancel={() => setSenseToDelete("")}
handleConfirm={performDelete}
/>
{Object.keys(treeWords).map((key) => (
<ImageListItem
key={key}
style={{ height: "70vh", margin: theme.spacing(1) }}
>
<DropWord mergeState={mergeState} wordId={key} />
</ImageListItem>
))}
<ImageListItem key={newId} style={{ margin: theme.spacing(1) }}>
<DropWord mergeState={mergeState} wordId={newId} />
</ImageListItem>
{renderSidebar()}
<CancelConfirmDialog
open={!!senseToDelete}
textId="mergeDups.helpText.deleteDialog"
handleCancel={() => setSenseToDelete("")}
handleConfirm={performDelete}
/>
</ImageList>
</DragDropContext>
);
}
11 changes: 2 additions & 9 deletions src/goals/MergeDupGoal/MergeDupStep/MergeDupStepComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Grid, ImageList, Typography } from "@mui/material";
import { Button, Grid, Typography } from "@mui/material";
import React, { ReactElement } from "react";
import { WithTranslation, withTranslation } from "react-i18next";

Expand Down Expand Up @@ -39,18 +39,11 @@ class MergeDupStep extends React.Component<
}

render(): ReactElement {
// number of columns = wordCount + 2:
// first column for the trash icon
// one column for each word
// last column for the blank card
const columnCount = this.props.wordCount + 2;
return this.props.wordCount ? (
<React.Fragment>
{/* Merging pane */}
<div style={{ background: "#eee", padding: theme.spacing(1) }}>
<ImageList rowHeight="auto" cols={columnCount}>
<MergeDragDrop />
</ImageList>
<MergeDragDrop />
</div>
{/* Merge/skip buttons */}
<Grid container justifyContent="flex-start">
Expand Down