Skip to content

Commit

Permalink
beauty
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Dec 20, 2024
1 parent 9995577 commit 7259a50
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/components/JoinMarkupsModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const JoinMarkupsModal = ({ perspectiveId, onClose }) => {

if (Object.keys(markupDict).length < 2) {
onClose();
throw new Error("Please set markups in both fields of the table");
window.logger.warn(getTranslation("Please set markups in both fields of the table"));
}

setMarkupDict(markupDict);
Expand All @@ -156,7 +156,7 @@ const JoinMarkupsModal = ({ perspectiveId, onClose }) => {
for (const group of Object.values(groupDict)) {
const ids = group["markups"].map(markup => markup.id);
if (ids.includes(firstTextRelation) && ids.includes(secondTextRelation) && group.type === typeRelation) {
setWarnMessage("Such group already exists.");
window.logger.warn(getTranslation("Such group already exists."));
return;
}
}
Expand All @@ -173,7 +173,7 @@ const JoinMarkupsModal = ({ perspectiveId, onClose }) => {
setSecondTextRelation(null);
setTypeRelation(null);

setSuccessMessage("The group was successfully added.");
window.logger.suc(getTranslation("The group was successfully added."));
}, [firstTextRelation, secondTextRelation, typeRelation, groupDict]);

const onDeleteRelation = useCallback(() => {
Expand All @@ -194,7 +194,7 @@ const JoinMarkupsModal = ({ perspectiveId, onClose }) => {
setSelectedRelations([]);
setSelectedTotal(0);

setSuccessMessage("The group was successfully deleted.");
window.logger.suc(getTranslation("The group was successfully deleted."));
}, [groupDict, selectedRelations]);

const onRelationSelect = (relation_id, checked) => {
Expand Down
17 changes: 13 additions & 4 deletions src/components/LexicalEntryCorp/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const TextEntityContent = ({

const client = useApolloClient();
const [deleteMarkupGroup] = useMutation(deleteMarkupGroupMutation, {
onCompleted: data => refetchLexicalEntries(data.delete_markup_group.entry_ids, client)
onCompleted: data => {
refetchLexicalEntries(data.delete_markup_group.entry_ids, client);
window.logger.suc(getTranslation("Markup(s) with related groups were removed"));
}
});

const getTranslation = useContext(TranslationContext);
Expand Down Expand Up @@ -220,6 +223,12 @@ const TextEntityContent = ({
});
} else {
update(entity, undefined, result);

if (action === "create_markup") {
window.logger.suc(getTranslation("Markup was created"));
} else if (action === "delete_markup") {
window.logger.suc(getTranslation("Markup was deleted"));
}
}
setBrowserSelection(null);
};
Expand Down Expand Up @@ -390,7 +399,7 @@ const TextEntityContent = ({
{marking.action === "create_markup" && (
<Button
className="lingvo-button-markup lingvo-button-markup_create"
content="M"
content="+M"
title={getTranslation("Create markup")}
onClick={onMarkupAction}
disabled={is_being_updated}
Expand All @@ -399,7 +408,7 @@ const TextEntityContent = ({
{marking.action === "delete_markup" && (
<Button
className="lingvo-button-markup lingvo-button-markup_delete"
content="M"
content="-M"
title={getTranslation("Delete markup(s)")}
onClick={onMarkupAction}
disabled={is_being_updated}
Expand All @@ -408,7 +417,7 @@ const TextEntityContent = ({
{marking.action === "delete_with_group" && (
<Button
className="lingvo-button-markup lingvo-button-markup_delete"
content="G"
content="-G"
title={getTranslation("Delete markup(s) with related groups")}
onClick={onMarkupAction}
disabled={is_being_updated}
Expand Down
32 changes: 27 additions & 5 deletions src/components/LexicalEntryCorp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ const Entities = ({
const [confirmation, setConfirmation] = useState(null);

const [deleteMarkupGroup] = useMutation(deleteMarkupGroupMutation, {
onCompleted: data => refetchLexicalEntries(data.delete_markup_group.entry_ids, client)
onCompleted: data => {
refetchLexicalEntries(data.delete_markup_group.entry_ids, client);
window.logger.warn(getTranslation("Markup(s) with related groups were removed"));
}
});

const getTranslation = useContext(TranslationContext);
Expand Down Expand Up @@ -373,6 +376,24 @@ const Entities = ({
remove_set2[entity_id_str] = null;
setRemoveSet(remove_set2);

const groupsToDelete = [];

for (const markup of (entity.additional_metadata?.markups ?? [])) {
if (!markup.length) {
continue;
}

const [_, ...groupIds] = markup;

if (groupIds.length > 0) {
groupsToDelete.push(...groupIds);
}
}

if (groupsToDelete.length > 0) {
deleteMarkupGroup({ variables: { groupIds: groupsToDelete, perspectiveId }});
}

removeEntity({
variables: { id: entity.id },
refetchQueries: [
Expand Down Expand Up @@ -444,16 +465,17 @@ const Entities = ({
}
}

if (startOffset < endOffset) {
console.log("=== Markup was moved");
// Markup must be not empty and have at least one letter char
if (startOffset < endOffset &&
/\w/.test(content.slice(startOffset, endOffset))) {
markups.push([[startOffset, endOffset], ...groupIds]);
window.logger.suc(getTranslation("Markup was moved"));

} else if (groupIds.length > 0) {
console.log("=== Markup with groups were deleted");
deleteMarkupGroup({ variables: { groupIds, perspectiveId } });

} else {
console.log("=== Markup was deleted");
window.logger.warn(getTranslation("Markup was deleted"));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4400,7 +4400,7 @@ body {
/* Markup button */
.lingvo-button-markup {
font-weight: 900 !important;
width: 36px !important;
width: 40px !important;
font-size: 14px !important;
color: #999ca0 !important;

Expand Down

0 comments on commit 7259a50

Please sign in to comment.