Skip to content

Commit

Permalink
Merge pull request #1070 from nataliauvarova/parallel_corpora
Browse files Browse the repository at this point in the history
Old version PerspectiveView and LexicalEntry
  • Loading branch information
nataliauvarova authored Nov 17, 2023
2 parents 166ca01 + 53ed528 commit 85e3b00
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 367 deletions.
79 changes: 25 additions & 54 deletions src/components/LexicalEntry/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import { Button, Checkbox, Input } from "semantic-ui-react";
import { find, isEqual } from "lodash";
import PropTypes from "prop-types";
import { onlyUpdateForKeys } from "recompose";
import { RegExpMarker } from "react-mark.js";

import Entities from "./index";

class TextEntityContent extends React.Component {
constructor(props) {
super(props);

const is_order_column = (props.number && props.column.english_translation === "Order");

this.state = {
edit: false,
read_only: is_order_column,
is_number: is_order_column
content: props.entity.content
};

this.onEdit = this.onEdit.bind(this);
Expand Down Expand Up @@ -49,12 +45,9 @@ class TextEntityContent extends React.Component {
checkedColumn,
resetCheckedColumn,
checkedAll,
resetCheckedAll,
number
resetCheckedAll
} = this.props;

const text = this.state.is_number ? number : entity.content;

if (checkEntries) {
if (checkedAll) {
if (checkedAll.checkedAll) {
Expand Down Expand Up @@ -97,50 +90,32 @@ class TextEntityContent extends React.Component {
}
}

const pg_ln = /\[\d+[ab]:\d+\]/;
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 + "|" +
missed.source
)
: new RegExp();

switch (mode) {
case "edit":
return (
<div className="lingvo-input-buttons-group">
{!(is_being_updated || this.state.edit) && (
<span className="lingvo-input-buttons-group__name"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
<span className="lingvo-input-buttons-group__name">{this.state.content}</span>
)}
{(is_being_updated || this.state.edit) && (
<Input
className="lingvo-input-action"
onChange={(event, target) => this.setState({ content: target.value })}
value={text}
value={this.state.content}
/>
)}
{ this.state.read_only || (
<Button.Group basic icon className="lingvo-buttons-group">
<Button icon={is_being_updated ? <i className="lingvo-icon lingvo-icon_spinner" /> : this.state.edit ? <i className="lingvo-icon lingvo-icon_save2" /> : <i className="lingvo-icon lingvo-icon_edit2" />}
onClick={this.onEdit}
disabled={is_being_updated || !text}
className={is_being_updated ? "lingvo-button-spinner" : ""}
/>
{is_being_removed ? (
<Button icon={<i className="lingvo-icon lingvo-icon_spinner" />} disabled className="lingvo-button-spinner" />
) : (
<Button icon={<i className="lingvo-icon lingvo-icon_delete2" />} onClick={() => remove(entity)} />
)}
</Button.Group>
)}
<Button.Group basic icon className="lingvo-buttons-group">
<Button icon={is_being_updated ? <i className="lingvo-icon lingvo-icon_spinner" /> : this.state.edit ? <i className="lingvo-icon lingvo-icon_save2" /> : <i className="lingvo-icon lingvo-icon_edit2" />}
onClick={this.onEdit}
disabled={is_being_updated || !this.state.content}
className={is_being_updated ? "lingvo-button-spinner" : ""}
/>
{is_being_removed ? (
<Button icon={<i className="lingvo-icon lingvo-icon_spinner" />} disabled className="lingvo-button-spinner" />
) : (
<Button icon={<i className="lingvo-icon lingvo-icon_delete2" />} onClick={() => remove(entity)} />
)}
</Button.Group>
</div>
);
case "publish":
Expand All @@ -155,11 +130,11 @@ class TextEntityContent extends React.Component {
href={`/dictionary/${entity.parent_id[0]}/${entity.parent_id[1]}/perspective/${entity.id[0]}/${entity.id[1]}/edit`}
className="lingvo-languages-link"
>
{text}
{entity.content}
</a>
</span>
) : (
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
<span className="lingvo-entry-content">{entity.content}</span>
)}
<Checkbox
className="lingvo-checkbox lingvo-entry-text__checkbox"
Expand All @@ -185,14 +160,14 @@ class TextEntityContent extends React.Component {

case "view":
return (
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
<span className="lingvo-entry-content">{entity.content}</span>
);
case "contributions":
return entity.accepted ? (
<span className="lingvo-entry-content"><RegExpMarker mark={metatext}>{text}</RegExpMarker></span>
<span className="lingvo-entry-content">{entity.content}</span>
) : (
<Button.Group basic icon className="lingvo-buttons-group">
<Button content={text} className="lingvo-buttons-group__text" />
<Button content={entity.content} className="lingvo-buttons-group__text" />
<Button
icon={<i className="lingvo-icon lingvo-icon_check2" />}
onClick={() => accept(entity, true)}
Expand All @@ -213,8 +188,7 @@ const Text = onlyUpdateForKeys([
"is_being_updated",
"checkedRow",
"checkedColumn",
"checkedAll",
"number"
"checkedAll"
])(props => {
const {
perspectiveId,
Expand All @@ -239,8 +213,7 @@ const Text = onlyUpdateForKeys([
remove,
update,
is_being_removed,
is_being_updated,
number
is_being_updated
} = props;

const subColumn = find(columns, c => isEqual(c.self_id, column.column_id));
Expand All @@ -264,7 +237,6 @@ const Text = onlyUpdateForKeys([
update={update}
is_being_removed={is_being_removed}
is_being_updated={is_being_updated}
number={number}
/>
{subColumn && (
<Entities
Expand Down Expand Up @@ -305,8 +277,7 @@ Text.propTypes = {
update: PropTypes.func,
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
number: PropTypes.string
resetCheckedAll: PropTypes.func
};

Text.defaultProps = {
Expand Down Expand Up @@ -388,4 +359,4 @@ Edit.defaultProps = {

Text.Edit = Edit;

export default Text;
export default Text;
14 changes: 5 additions & 9 deletions src/components/LexicalEntry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ class Entities extends React.Component {
checkedColumn,
resetCheckedColumn,
checkedAll,
resetCheckedAll,
number
resetCheckedAll
} = this.props;

const Component = getComponent(column.data_type);
Expand All @@ -405,7 +404,6 @@ class Entities extends React.Component {
ens => (!parentEntity ? ens : ens.filter(e => isEqual(e.self_id, parentEntity.id)))
];
const entities = flow(filters)(entry.entities);
const is_order_column = column.english_translation === "Order";

return (
<ul>
Expand Down Expand Up @@ -437,15 +435,14 @@ class Entities extends React.Component {
disabled={disabled}
is_being_removed={this.state.remove_set.hasOwnProperty(id2str(entity.id))}
is_being_updated={this.state.update_set.hasOwnProperty(id2str(entity.id))}
number={number}
/>
))}
{mode === "edit" && !is_order_column && (
{mode === "edit" && (
<li className="last">
{!this.state.edit && (
<Button.Group basic className="lingvo-buttons-group">
<Button icon={<i className="lingvo-icon lingvo-icon_plus" />}
onClick={() => this.setState({ edit: true })}
onClick={() => this.setState({ edit: true })}
/>
</Button.Group>
)}
Expand Down Expand Up @@ -484,8 +481,7 @@ Entities.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func,
number: PropTypes.string
reRender: PropTypes.func
};

Entities.defaultProps = {
Expand All @@ -500,4 +496,4 @@ export default compose(
graphql(updateEntityMutation, { name: "updateEntity" }),
withApollo,
pure
)(Entities);
)(Entities);
12 changes: 4 additions & 8 deletions src/components/PerspectiveView/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const Cell = ({
mode,
entitiesMode,
disabled,
reRender,
number
reRender
// eslint-disable-next-line arrow-body-style
}) => {
return (
Expand All @@ -47,7 +46,6 @@ const Cell = ({
entitiesMode={entitiesMode}
disabled={disabled}
reRender={reRender}
number={number}
/>
</Table.Cell>
);
Expand All @@ -68,8 +66,7 @@ Cell.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func,
number: PropTypes.string
reRender: PropTypes.func
};

Cell.defaultProps = {
Expand All @@ -84,6 +81,5 @@ export default onlyUpdateForKeys([
"column",
"checkedRow",
"checkedColumn",
"checkedAll",
"number"
])(Cell);
"checkedAll"
])(Cell);
15 changes: 5 additions & 10 deletions src/components/PerspectiveView/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ const Column = ({
onSortModeChange,
onSortModeReset
}) => {
const be_sorted = field.english_translation === "Order" ? false : true;

const subFields = fields.filter(f => isEqual(f.self_id, field.column_id));

const sort_flag = field && sortByField && id2str(field.id) == id2str(sortByField.field);

const sort_f = () =>
!be_sorted
? onSortModeReset()
: !sort_flag
!sort_flag
? onSortModeChange(field.id, "a")
: sortByField.order == "a"
: sortByField.order == "a"
? onSortModeChange(field.id, "d")
: onSortModeReset();

Expand All @@ -55,7 +51,7 @@ const Column = ({
) : (
<label>{T(field.translations)}</label>
)}
{onSortModeChange && be_sorted &&
{onSortModeChange &&
(sort_flag ? (
<span className="lingvo-perspective-sort">
{sortByField.order == "a" ? (
Expand Down Expand Up @@ -86,8 +82,7 @@ const Column = ({
onClick={e => (e.stopPropagation(), onSortModeChange(field.id, "d"))}
/>
</span>
))}

))}
<ul>
{subFields.map((subField, index) => {
const cls = index + 1 === subFields.length ? { className: "last" } : {};
Expand Down Expand Up @@ -124,4 +119,4 @@ Column.defaultProps = {
onCheckColumn: () => {}
};

export default onlyUpdateForKeys(["field", "selectedColumns"])(Column);
export default onlyUpdateForKeys(["field", "selectedColumns"])(Column);
10 changes: 3 additions & 7 deletions src/components/PerspectiveView/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const Row = ({
resetCheckedColumn,
resetCheckedAll,
reRender,
number,
/* eslint-disable react/prop-types */
showEntryId,
selectDisabled,
Expand Down Expand Up @@ -98,7 +97,6 @@ const Row = ({
entitiesMode={entitiesMode}
disabled={disabled_flag}
reRender={reRender}
number={number}
/>
))}

Expand Down Expand Up @@ -151,8 +149,7 @@ Row.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func,
number: PropTypes.string
reRender: PropTypes.func
};

Row.defaultProps = {
Expand Down Expand Up @@ -181,6 +178,5 @@ export default onlyUpdateForKeys([
"checkedRow",
"checkedColumn",
"checkedAll",
"columns",
"number"
])(Row);
"columns"
])(Row);
6 changes: 3 additions & 3 deletions src/components/PerspectiveView/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Row from "./Row";

const TableBody = ({ entries, ...rest }) => (
<Table.Body>
{entries.map((entry, index) => (
<Row key={entry.id} entry={entry} number={(index + 1).toString()} {...rest} />
{entries.map(entry => (
<Row key={entry.id} entry={entry} {...rest} />
))}
</Table.Body>
);
Expand Down Expand Up @@ -61,4 +61,4 @@ export default onlyUpdateForKeys([
"checkedRow",
"checkedColumn",
"checkedAll"
])(TableBody);
])(TableBody);
2 changes: 1 addition & 1 deletion src/components/PerspectiveView/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ TableHeader.defaultProps = {
onCheckAll: () => {}
};

export default onlyUpdateForKeys(["columns", "entries", "selectedRows", "selectedColumns"])(TableHeader);
export default onlyUpdateForKeys(["columns", "entries", "selectedRows", "selectedColumns"])(TableHeader);
Loading

0 comments on commit 85e3b00

Please sign in to comment.