Skip to content

Commit

Permalink
Count missed words and hide dashes (#1049)
Browse files Browse the repository at this point in the history
* fix styles dnd

* fix dnd

* fix dnd and styles

* blob.values.dedash

* fix shortcut

* fix

* Fixed "dedash"

* Tuned frontend

* Minor

* Count missed words

---------

Co-authored-by: nataliauvarova <[email protected]>
Co-authored-by: nataliauvarova <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2023
1 parent 43016ca commit 1a4b810
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 70 deletions.
14 changes: 7 additions & 7 deletions src/components/CorporaView/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const Row = ({
id, /* new!!!!! */
moveListItem, /* new!!!!! */
dragAndDropEntries, /* new!!!!! */

entries /* new!!!!! */
/* eslint-enable react/prop-types */
}) => {
Expand Down Expand Up @@ -100,8 +99,9 @@ const Row = ({
return;
}
// Determine rectangle on screen
//const hoverBoundingRect = ref.current?.getBoundingClientRect();
const hoverBoundingRect = ref.current.parentElement.parentElement?.getBoundingClientRect(); // fix!!!!!
const hoverBoundingRect = ref.current?.getBoundingClientRect();
//const hoverBoundingRect = ref.current.parentElement.parentElement?.getBoundingClientRect(); // fix!!!!!

// Get vertical middle
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
// Determine mouse position
Expand Down Expand Up @@ -137,8 +137,6 @@ const Row = ({

const dragDropRef = dragRef(dropRef(ref));

/*const opacity = isDragging ? 0 : 1;*/

/* /new!!!!!! */

const entry_id_str = id2str(entry.id);
Expand All @@ -154,7 +152,9 @@ const Row = ({
{/* new!!!!! */}
<Table.Cell style={(mode === "edit") ? {} : { display: "none" }}>
<div ref={dragDropRef}>
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />} />
<Button.Group basic className="lingvo-buttons-group">
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />} />
</Button.Group>
</div>
</Table.Cell>
{/* /new!!!!! */}
Expand Down Expand Up @@ -298,6 +298,6 @@ export default onlyUpdateForKeys([
"columns",
"id", /* ????? new!!!!! */
"index", /* ????? new!!!!! */
"moveListItem", /* new!!!!! */
/*"moveListItem",*/ /* new!!!!! */
"entries" /* new!!!!! */
])(Row);
5 changes: 4 additions & 1 deletion src/components/CorporaView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import smoothScroll from "utils/smoothscroll";
import TableBody from "./TableBody";
import TableHeader from "./TableHeader";

import "./styles.scss";

const ROWS_PER_PAGE = 20;

const ModalContentWrapper = styled("div")`
Expand Down Expand Up @@ -992,7 +994,8 @@ class P extends React.Component {
onSortModeChange={(fieldId, order) => setSort(fieldId, order)}
onSortModeReset={() => resetSort()}
selectEntries={mode === "edit"}
entries={items}
/*entries={items}*/
entries={this.state.cards.length && this.state.cards || items} /* new!!!!! */
checkEntries={isTableLanguagesPublish}
selectedRows={selectedRows}
selectedColumns={selectedColumns}
Expand Down
11 changes: 11 additions & 0 deletions src/components/CorporaView/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* parallel corpora */
.lingvo-scrolling-content {
padding-bottom: 20px !important;

& .lingvo-scrolling-tab {
@media only screen and (max-device-width: 1000px), only screen and (max-width: 1000px) {
margin-bottom: 0 !important;
}
}
}
/* /parallel corpora */
5 changes: 4 additions & 1 deletion src/components/LexicalEntry/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ class TextEntityContent extends React.Component {
const pg = /\[\d+[ab]?\]/;
const ln = /\(\d+\)/;
const snt = /\/{2}/;
const missed = /[/]missed text[/]/;
// TODO: change 'number' to something meaningful
const metatext = number
? new RegExp(
pg_ln.source + "|" +
pg.source + "|" +
ln.source + "|" +
snt.source)
snt.source + "|" +
missed.source
)
: new RegExp();

switch (mode) {
Expand Down
47 changes: 16 additions & 31 deletions src/components/LexicalEntryCorp/Text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useState } from "react";
import { useDrag } from "react-dnd";
import TextareaAutosize from 'react-textarea-autosize';
import { Button, Checkbox, Input } from "semantic-ui-react";
import { Button, Checkbox } from "semantic-ui-react";
import { find, isEqual } from "lodash";
import PropTypes from "prop-types";
import { onlyUpdateForKeys } from "recompose";
Expand Down Expand Up @@ -31,8 +31,6 @@ const TextEntityContent = ({
id /* new!!!!!! */
}) => {

/*console.log('render TextEntityContent!!!!!');*/

const [edit, setEdit] = useState(false);
const [content, setContent] = useState(entity.content);

Expand All @@ -53,13 +51,9 @@ const TextEntityContent = ({

const onKeyDown = useCallback((event) => {

console.log('event=====');
console.log(event);

breakdown(event, parentEntity, entity);
}, []);

/* /new!!!!! */
}, []);

// useDrag - the list item is draggable
const [{ isDragging}, dragRef, preview] = useDrag({
Expand All @@ -75,6 +69,8 @@ const TextEntityContent = ({
}
});

/* /new!!!!! */

if (checkEntries) {
if (checkedAll) {
if (checkedAll.checkedAll) {
Expand Down Expand Up @@ -120,9 +116,9 @@ const TextEntityContent = ({
switch (mode) {
case "edit":
return !dropped ? (
<div className="lingvo-input-buttons-group" ref={preview} id={id}>
<div /* new!!!! */ className={isDragging && "lingvo-input-buttons-group lingvo-input-buttons-group_drag" || "lingvo-input-buttons-group"} ref={preview} id={id}>
{!(is_being_updated || edit) && (
<span className="lingvo-input-buttons-group__name">{content} {isDragging && 'Oops'}</span>
<span className="lingvo-input-buttons-group__name">{content}</span>
)}
{(is_being_updated || edit) && (
/* new!!!!!! */
Expand All @@ -136,9 +132,8 @@ const TextEntityContent = ({
)}
<Button.Group basic icon className="lingvo-buttons-group">
{/* new!!!!! */}
<div ref={dragRef}>
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />}
/>
<div ref={dragRef} className="lingvo-buttons-group__drag">
<Button icon={<i className="lingvo-icon lingvo-icon_dnd" />} />
</div>
{/* new!!!!! */}
<Button icon={is_being_updated ? <i className="lingvo-icon lingvo-icon_spinner" /> : edit ? <i className="lingvo-icon lingvo-icon_save2" /> : <i className="lingvo-icon lingvo-icon_edit2" />}
Expand Down Expand Up @@ -371,56 +366,46 @@ const Edit = ({

const onChange = useCallback((event) => {

console.log('func onChange!!!!!!');

/*
console.log('target.value=====');
console.log(target.value);*/

setContent(event.target.value);

}, [content]);

const onKeyDown = useCallback((event) => {

console.log('func onKeyDown!!!!!!');

console.log('event=====');
breakdown(event, parentEntity);

console.log(event);
if (event.code === "Enter" && !event.ctrlKey) {

if (event.code === "Enter") {
if (content) {
onSave(content);
}
}

breakdown(event, parentEntity);

if (event.keyCode === 27) {
onCancel();
}
}, [content]);

const onBlur = useCallback(() => {
const onHandlerSave = useCallback((event) => {

console.log('func onBlur!!!!!!');

if (content) {
onSave(content);
}

}, [content]);

return (
<div className="lingvo-input-buttons-group">
<TextareaAutosize
onChange={onChange}
onKeyDown={onKeyDown}
onBlur={onBlur}
/*onBlur={onBlur}*/
className="lingvo-input-action lingvo-input-action_textarea"
/>
<Button.Group basic className="lingvo-buttons-group">
<Button icon={is_being_created ? <i className="lingvo-icon lingvo-icon_spinner" /> : <i className="lingvo-icon lingvo-icon_save2" />}
<Button
icon={is_being_created ? <i className="lingvo-icon lingvo-icon_spinner" /> : <i className="lingvo-icon lingvo-icon_save2" />}
onClick={onHandlerSave} /* new!!!!! */
disabled={is_being_created || !content}
className={is_being_created ? "lingvo-button-spinner" : ""}
/>
Expand Down
12 changes: 5 additions & 7 deletions src/components/LexicalEntryCorp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useState} from "react";
import React, {useCallback, useContext, useState} from "react";
import { useDrop } from "react-dnd";
import { Button } from "semantic-ui-react";
import { gql } from "@apollo/client";
Expand All @@ -11,6 +11,7 @@ import { queryCounter } from "backend";
/* new!!!!! */
/*import { queryLexicalEntries } from "components/PerspectiveView";*/
import { queryLexicalEntries } from "components/CorporaView";
import TranslationContext from "Layout/TranslationContext";
/* /new!!!!! */
import { compositeIdToString, compositeIdToString as id2str } from "utils/compositeId";

Expand Down Expand Up @@ -174,6 +175,8 @@ const Entities = ({
const [remove_set, setRemoveSet] = useState({});
const [update_set, setUpdateSet] = useState({});

const getTranslation = useContext(TranslationContext);

/* new!!!!! */
const [{ isOver }, dropRef] = useDrop({
accept: 'entity',
Expand Down Expand Up @@ -440,10 +443,6 @@ const Entities = ({
/* Shortcut "ctrl+Enter" */
const breakdown = useCallback((event, parentEntity, entity) => {

/*console.log('Breakdown!!!!!!');
console.log('Breakdown: event.target======');
console.log(event.target);*/

if (event.ctrlKey && event.code === "Enter") {
event.preventDefault();
//console.log("Breakdown: ShortCut !!!!!!!!!!!");
Expand Down Expand Up @@ -540,15 +539,14 @@ const Entities = ({
{!edit && (
<div ref={dropRef} /* new!!!! */>
{/* new!!!!! */}
{isOver && <div>Drop Here!</div>}
{isOver && <div className="lingvo-drop-here">{getTranslation("Drop Here!")}</div>}
{/* /new!!!!! */}

<Button.Group basic className="lingvo-buttons-group">
<Button icon={<i className="lingvo-icon lingvo-icon_plus" />}
onClick={() => setEdit(true)}
/>
</Button.Group>

</div>
)}

Expand Down
11 changes: 4 additions & 7 deletions src/pages/CorpImport/ColumnMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ function Column({ index, fieldOptions, type, onSetColumnType, actions }) {
placeholder={`${getTranslation("Field selection")}...`}
options={fieldOptions}
value={selectedField && selectedField.value}
onChange={(e, { value }) => {
onSetColumnType(fieldOptions[value].id, fieldOptions[value].name);
}}
onChange={(e, { value }) => onSetColumnType(fieldOptions[value])}
/>
<Popup.Content className="popup-field-type">
{fieldOptions.map(f => (
<FieldButton key={f.key} onClick={() => onSetColumnType(f.id, f.name)} text={f.text} isSelected={is(type, f.id)} />
<FieldButton key={f.key} onClick={() => onSetColumnType(f.id)} text={f.text} isSelected={is(type, f.id)} />
))}
</Popup.Content>
</Popup>
Expand Down Expand Up @@ -104,16 +102,15 @@ function ColumnMapper({ state, types, columnTypes, onSetColumnType }) {
for (const type of typesSortedFiltered) {
const id = type.get("id");
const idStr = id.join("/");
const name = T(type.get("translations").toJS());

fieldOptions.push({
key: idStr,
value: idStr,
text: `${T(type.get("translations").toJS())} (${type.get("data_type")})`,
id, name
id
});

fieldOptions[idStr] = { id, name };
fieldOptions[idStr] = id;
}

let i = 0;
Expand Down
11 changes: 9 additions & 2 deletions src/pages/CorpImport/Linker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useEffect } from "react";
import { Button, Dropdown } from "semantic-ui-react";
import { Button, Dropdown, Checkbox } from "semantic-ui-react";
import { pure } from "recompose";

import TranslationContext from "Layout/TranslationContext";
Expand All @@ -8,7 +8,8 @@ function Columns({ blob, index, onDelete, onUpdateColumn }) {
const getTranslation = useContext(TranslationContext);
const color = index ? "yellow" : "green";
const name = index ? "sentence" : "base sentence";
useEffect(() => { onUpdateColumn("sentence", "noname") }, [blob]);
const value = blob.getIn(["values", "sentence"], "dash");
useEffect(() => { onUpdateColumn("sentence", value) }, []);

return (
<div className="blob blob_corp">
Expand All @@ -19,6 +20,12 @@ function Columns({ blob, index, onDelete, onUpdateColumn }) {
{getTranslation(name)}
</Button>
</div>
{ !index && (
<Checkbox className="blob-checkbox"
label={getTranslation("Hide dashes")}
onClick={() => onUpdateColumn("sentence", value === "dash" ? "dedash" : "dash", value)}
checked={value === "dedash"} />
) || <div className="blob-checkbox" />}
</div>
);
}
Expand Down
11 changes: 4 additions & 7 deletions src/pages/CorpImport/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ export function corpusInfo({ linking, languages, licenses }) {

function blobExport(blob, columnType) {
const blob_id = blob.get("id").toArray();
const values = blob.get("values", new Map());

const field_map = {
column_name: values.get("sentence", "Sentence in transliteration"),
field_id: columnType.get("sentence", new Map()).toArray()
};
const dedash = (blob.getIn(["values", "sentence"], "dash") === "dedash");
const field_id = columnType.get("sentence", new Map()).toArray();

return {
blob_id,
field_map
field_id,
dedash
};
}

Expand Down
9 changes: 5 additions & 4 deletions src/pages/CorpImport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ class Info extends React.Component {
}

onSetColumnType(id) {
return column => (field, name) => {
this.props.setColumnType(id, column, field);
this.props.updateColumn(id, column, name, null);
};
return column => field => this.props.setColumnType(id, column, field);
}

onUpdateColumn(id) {
return (column, value, oldValue) => this.props.updateColumn(id, column, value, oldValue);
}

onUpdateColumn(id) {
Expand Down
Loading

0 comments on commit 1a4b810

Please sign in to comment.