Skip to content

Commit

Permalink
pass queryArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Aug 26, 2024
1 parent 7fd45fd commit 8e41170
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 49 deletions.
30 changes: 14 additions & 16 deletions src/components/LexicalEntry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from "prop-types";
import { compose, pure } from "recompose";

import { queryCounter } from "backend";
import { queryLexicalEntries, fragmentPerspectivePageVariables } from "components/PerspectiveView";
import { queryLexicalEntries } from "components/PerspectiveView";
import { compositeIdToString, compositeIdToString as id2str } from "utils/compositeId";

import GroupingTag from "./GroupingTag";
Expand Down Expand Up @@ -128,7 +128,7 @@ class Entities extends React.Component {
update_check() {
/* Checking if we need to manually update perspective data. */

const { entry, client, perspectiveId, entitiesMode } = this.props;
const { entry, client, perspectiveId, entitiesMode, queryArgs } = this.props;

const data_entities = client.readQuery({
query: lexicalEntryQuery,
Expand All @@ -138,20 +138,16 @@ class Entities extends React.Component {
}
});

// Current variables for queryLexicalEntries are stored as fragment
const data_perspective_variables = client.readFragment(fragmentPerspectivePageVariables);

const data_perspective = client.readQuery({
const data_perspective = queryArgs
? client.readQuery({
query: queryLexicalEntries,
variables: data_perspective_variables ?? {}
});
variables: queryArgs
})
: { perspective: { perspective_page: { lexical_entries: [] }}};

const {
perspective: { perspective_page: { lexical_entries } }
} = data_perspective ? data_perspective : {
// TODO: here is a dirty workaround, readQuery above should have
// full set of variables and work correctly
perspective: { perspective_page: { lexical_entries: [] } } };
} = data_perspective;

const entry_id_str = id2str(entry.id);

Expand Down Expand Up @@ -182,12 +178,12 @@ class Entities extends React.Component {
/* If for some reason queryLexicalEntries failed to update (e.g. when there are several thousand
* entries and Apollo GraphQL cache glitches), we update it manually. */

if (change_flag) {
if (change_flag && queryArgs) {
lexical_entry.entities = data_entities.lexicalentry.entities;

client.writeQuery({
query: queryLexicalEntries,
variables: data_perspective_variables ?? {},
variables: queryArgs,
data: data_perspective
});
}
Expand Down Expand Up @@ -481,11 +477,13 @@ Entities.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func
reRender: PropTypes.func,
queryArgs: PropTypes.object
};

Entities.defaultProps = {
parentEntity: null
parentEntity: null,
queryArgs: null
};

export default compose(
Expand Down
13 changes: 9 additions & 4 deletions src/components/PerspectiveView/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const Cell = ({
mode,
entitiesMode,
disabled,
reRender
reRender,
queryArgs
// eslint-disable-next-line arrow-body-style
}) => {
return (
Expand All @@ -46,6 +47,7 @@ const Cell = ({
entitiesMode={entitiesMode}
disabled={disabled}
reRender={reRender}
queryArgs={queryArgs}
/>
</Table.Cell>
);
Expand All @@ -66,11 +68,13 @@ Cell.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func
reRender: PropTypes.func,
queryArgs: PropTypes.object
};

Cell.defaultProps = {
disabled: undefined
disabled: undefined,
queryArgs: null
};

export default onlyUpdateForKeys([
Expand All @@ -81,5 +85,6 @@ export default onlyUpdateForKeys([
"column",
"checkedRow",
"checkedColumn",
"checkedAll"
"checkedAll",
"queryArgs"
])(Cell);
11 changes: 8 additions & 3 deletions src/components/PerspectiveView/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Row = ({
resetCheckedColumn,
resetCheckedAll,
reRender,
queryArgs,
/* eslint-disable react/prop-types */
showEntryId,
selectDisabled,
Expand Down Expand Up @@ -97,6 +98,7 @@ const Row = ({
entitiesMode={entitiesMode}
disabled={disabled_flag}
reRender={reRender}
queryArgs={queryArgs}
/>
))}

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

Row.defaultProps = {
Expand All @@ -166,7 +169,8 @@ Row.defaultProps = {
resetCheckedRow: () => {},
resetCheckedColumn: () => {},
resetCheckedAll: () => {},
reRender: () => console.debug('Fake refetch')
reRender: () => console.debug('Fake refetch'),
queryArgs: null
};

export default onlyUpdateForKeys([
Expand All @@ -178,5 +182,6 @@ export default onlyUpdateForKeys([
"checkedRow",
"checkedColumn",
"checkedAll",
"columns"
"columns",
"queryArgs"
])(Row);
9 changes: 6 additions & 3 deletions src/components/PerspectiveView/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ TableBody.propTypes = {
resetCheckedRow: PropTypes.func,
resetCheckedColumn: PropTypes.func,
resetCheckedAll: PropTypes.func,
reRender: PropTypes.func
reRender: PropTypes.func,
queryArgs: PropTypes.object
};

TableBody.defaultProps = {
Expand All @@ -49,7 +50,8 @@ TableBody.defaultProps = {
resetCheckedRow: () => {},
resetCheckedColumn: () => {},
resetCheckedAll: () => {},
reRender: () => console.log('Fake refetch')
reRender: () => console.log('Fake refetch'),
queryArgs: null
};

export default onlyUpdateForKeys([
Expand All @@ -60,5 +62,6 @@ export default onlyUpdateForKeys([
"selectedRows",
"checkedRow",
"checkedColumn",
"checkedAll"
"checkedAll",
"queryArgs"
])(TableBody);
24 changes: 1 addition & 23 deletions src/components/PerspectiveView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,6 @@ export const queryLexicalEntries = gql`
}
`;

export const fragmentPerspectivePageVariables = {
id: 'PerspectivePageVariables:',
fragment: gql`
fragment current on PerspectivePageVariables {
id
entitiesMode
filter
isRegexp
isCaseSens
isEditMode
isAscending
sortingField
limit
offset
}`
};

const createLexicalEntryMutation = gql`
mutation createLexicalEntry($id: LingvodocID!, $entitiesMode: String!) {
create_lexicalentry(perspective_id: $id) {
Expand Down Expand Up @@ -389,12 +372,6 @@ class P extends React.Component {
createdEntries
}

// TODO: doesn't work yet
client.writeFragment({
...fragmentPerspectivePageVariables,
data: query_args
});

const { loading, error } = data;

if (loading || (!loading && !error && !data.perspective)) {
Expand Down Expand Up @@ -683,6 +660,7 @@ class P extends React.Component {
resetCheckedAll={this.resetCheckedAll}
onEntrySelect={onEntrySelect}
reRender={reRender}
queryArgs={query_args}
/>
</Table>
</div>
Expand Down

0 comments on commit 8e41170

Please sign in to comment.