Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Dec 17, 2024
1 parent 1a761ef commit d852609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
11 changes: 1 addition & 10 deletions src/components/CorporaView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,7 @@ class P extends React.Component {

/* new!!!! */
const onJoinMarkups = () => {
openNewModal(JoinMarkupsModal, {
perspectiveId: id,
onClose: () => {
closeNewModal(JoinMarkupsModal);
},
onCloseUpdate: () => {
closeNewModal(JoinMarkupsModal);
data.refetch();
}
});
openNewModal(JoinMarkupsModal, { perspectiveId: id });
};
/* /new!!!! */

Expand Down
29 changes: 12 additions & 17 deletions src/components/JoinMarkupsModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,22 @@ export const refetchLexicalEntries = (
)
);

const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
const JoinMarkupsModal = ({ perspectiveId, onClose }) => {
const getTranslation = useContext(TranslationContext);

const [firstTextRelation, setFirstTextRelation] = useState(null);
const [secondTextRelation, setSecondTextRelation] = useState(null);
const [typeRelation, setTypeRelation] = useState(null);
const [selectedRelations, setSelectedRelations] = useState(null);
const [isDirty, setIsDirty] = useState(false);

const joinActive = firstTextRelation && secondTextRelation && typeRelation;
const deleteActive = selectedRelations;
const onCleverClose = isDirty ? onCloseUpdate : onClose;
const [selectedRelations, setSelectedRelations] = useState([]);

const [markupDict, setMarkupDict] = useState({});
const [groupDict, setGroupDict] = useState({});
const [groupTotal, setGroupTotal] = useState(0);
const [selectedTotal, setSelectedTotal] = useState(0);

const joinActive = firstTextRelation && secondTextRelation && typeRelation;
const deleteActive = !!selectedTotal;

const [warnMessage, setWarnMessage] = useState(null);
const [errorMessage, setErrorMessage] = useState(null);
const [successMessage, setSuccessMessage] = useState(null);
Expand Down Expand Up @@ -191,7 +189,6 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
setFirstTextRelation(null);
setSecondTextRelation(null);
setTypeRelation(null);
//setIsDirty(true);

setSuccessMessage("The group was successfully added.");

Expand All @@ -201,11 +198,11 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {

resetMessages();

const groupIds = (selectedRelations || []).map(
const groupIds = selectedRelations.map(
id => id.split('_'));

const markups = [];
(selectedRelations || []).forEach(id => {
selectedRelations.forEach(id => {
const group_markups = groupDict[id].markups.map(m => m.id.split('_'));
markups.push(...group_markups);
});
Expand All @@ -222,9 +219,8 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
variables: { groupIds, markups }
}).then(refetch);

setSelectedRelations(null);
setSelectedRelations([]);
setSelectedTotal(0);
//setIsDirty(true);

setSuccessMessage("The group was successfully deleted.");

Expand All @@ -233,7 +229,7 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
const onRelationSelect = (relation_id, checked) => {
//console.log("onRelationSelect!!!!!!!");

const selectedIds = (selectedRelations || []);
const selectedIds = selectedRelations;

const position = selectedIds.indexOf(relation_id);

Expand All @@ -247,7 +243,7 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
//console.log(selectedIds);

const selectedTotal = selectedIds.length;
setSelectedRelations(selectedTotal ? selectedIds : null);
setSelectedRelations(selectedIds);
setSelectedTotal(selectedTotal);
};

Expand Down Expand Up @@ -280,7 +276,7 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
const secondText = markupDict[secondField].map(m => m.id === secondTextRelation ? m.text : "");

return (
<Modal className="lingvo-modal2" dimmer open closeIcon onClose={onCleverClose} size="fullscreen">
<Modal className="lingvo-modal2" dimmer open closeIcon onClose={onClose} size="fullscreen">
<Modal.Header>{getTranslation("Join markups")}</Modal.Header>
<Modal.Content>
{ error || loading ? (
Expand Down Expand Up @@ -451,15 +447,14 @@ const JoinMarkupsModal = ({ perspectiveId, onCloseUpdate, onClose }) => {
disabled={!deleteActive}
style={{float: "left"}}
/>
<Button content={getTranslation("Close")} onClick={onCleverClose} className="lingvo-button-basic-black" />
<Button content={getTranslation("Close")} onClick={onClose} className="lingvo-button-basic-black" />
</Modal.Actions>
</Modal>
);
};

JoinMarkupsModal.propTypes = {
perspectiveId: PropTypes.arrayOf(PropTypes.number).isRequired,
onCloseUpdate: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired
};

Expand Down

0 comments on commit d852609

Please sign in to comment.