Skip to content

Commit

Permalink
Improved for #1020 (#1025)
Browse files Browse the repository at this point in the history
* Clear title

* Split Lexical Entries and Morphology perspectives

* Request

* perspectiveId: props.lexicalEntry.parent_id

* more reliable
  • Loading branch information
vmonakhov authored Sep 5, 2023
1 parent a1be3b5 commit 74429d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/components/GroupingTagModal/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,16 @@ export const languageTreeSourceQuery = gql`
}
}
`;

export const perspectiveFieldsQuery = gql`
query perspectiveFields($perspectiveId: LingvodocID!) {
perspective(id: $perspectiveId) {
columns {
field {
id
english_translation: translation(locale_id: 2)
}
}
}
}
`;
31 changes: 22 additions & 9 deletions src/components/GroupingTagModal/search.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { Dimmer, Header, Icon, Input, Segment } from "semantic-ui-react";
import { withApollo } from "@apollo/client/react/hoc";
import { graphql, withApollo } from "@apollo/client/react/hoc";
import PropTypes from "prop-types";
import { compose, pure } from "recompose";

import { branch, compose, pure, renderComponent, renderNothing } from "recompose";
import Placeholder from "components/Placeholder";
import TranslationContext from "Layout/TranslationContext";

import { searchQuery } from "./graphql";
import { searchQuery, perspectiveFieldsQuery } from "./graphql";
import buildPartialLanguageTree from "./partialTree";
import Tree from "./Tree";
import { isEqual } from "lodash";
Expand All @@ -15,10 +15,17 @@ class SearchLexicalEntries extends React.Component {
constructor(props) {
super(props);

const { lexicalEntry } = props;
// field_id for 'Affix Meaning' is hardcoded here
// May be better to look for the field name and field id in cache
const aff_meaning_field_id = [66, 2042];
const { data: {perspective: {columns}}, lexicalEntry } = props;
let aff_meaning_field_id = null;

for (const column of columns) {
const { field: { id: field_id, english_translation: field_name }} = column;
if (field_name === "Meaning of affix") {
aff_meaning_field_id = field_id;
break;
}
}

const aff_meaning = lexicalEntry.entities.find(e => e.content && isEqual(e.field_id, aff_meaning_field_id));
const some_entity = lexicalEntry.entities.find(e => e.content && e.content.length >= 2 && e.content.length < 8);
const entity = aff_meaning ? aff_meaning : some_entity;
Expand Down Expand Up @@ -118,4 +125,10 @@ SearchLexicalEntries.propTypes = {
connectedWords: PropTypes.object
};

export default compose(withApollo, pure)(SearchLexicalEntries);
export default compose(
graphql(perspectiveFieldsQuery, { options: ({lexicalEntry}) => ({ variables: { perspectiveId: lexicalEntry.parent_id }}) }),
branch(({ data: { loading } }) => loading, renderComponent(Placeholder)),
branch(({ data: { error } }) => !!error, renderNothing),
withApollo,
pure
)(SearchLexicalEntries);
13 changes: 9 additions & 4 deletions src/pages/Perspective/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ const toolsQuery = gql`
perspective(id: $id) {
id
english_status: status(locale_id: 2)
translations
created_by {
id
}
edit_check: role_check(subject: "perspective", action: "edit")
columns {
field {
english_translation: translation(locale_id: 2)
}
}
}
}
`;
Expand Down Expand Up @@ -933,12 +937,13 @@ const Tools = ({
english_status,
created_by: { id: author_id },
edit_check,
translations
columns
}
} = data;

const titles = Object.values(translations)
const glottMode = titles.some(t => t.includes("Morpholog")) ? "morphology" : "swadesh";
const isMorphology = ({field: {english_translation: field_name}}) =>
field_name.toLowerCase().includes("affix");
const glottMode = columns.some(isMorphology) ? "morphology" : "swadesh";
const published = english_status === "Published" || english_status === "Limited access";

return (
Expand Down

0 comments on commit 74429d2

Please sign in to comment.