From 8e411706f7b1160a877e3caf2a5a095b2be76098 Mon Sep 17 00:00:00 2001 From: vmonakhov Date: Mon, 26 Aug 2024 16:44:07 +0300 Subject: [PATCH] pass queryArgs --- src/components/LexicalEntry/index.js | 30 ++++++++++----------- src/components/PerspectiveView/Cell.js | 13 ++++++--- src/components/PerspectiveView/Row.js | 11 +++++--- src/components/PerspectiveView/TableBody.js | 9 ++++--- src/components/PerspectiveView/index.js | 24 +---------------- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/components/LexicalEntry/index.js b/src/components/LexicalEntry/index.js index f2983426..49a8ee05 100644 --- a/src/components/LexicalEntry/index.js +++ b/src/components/LexicalEntry/index.js @@ -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"; @@ -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, @@ -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); @@ -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 }); } @@ -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( diff --git a/src/components/PerspectiveView/Cell.js b/src/components/PerspectiveView/Cell.js index 9e3c2534..cab92369 100644 --- a/src/components/PerspectiveView/Cell.js +++ b/src/components/PerspectiveView/Cell.js @@ -24,7 +24,8 @@ const Cell = ({ mode, entitiesMode, disabled, - reRender + reRender, + queryArgs // eslint-disable-next-line arrow-body-style }) => { return ( @@ -46,6 +47,7 @@ const Cell = ({ entitiesMode={entitiesMode} disabled={disabled} reRender={reRender} + queryArgs={queryArgs} /> ); @@ -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([ @@ -81,5 +85,6 @@ export default onlyUpdateForKeys([ "column", "checkedRow", "checkedColumn", - "checkedAll" + "checkedAll", + "queryArgs" ])(Cell); \ No newline at end of file diff --git a/src/components/PerspectiveView/Row.js b/src/components/PerspectiveView/Row.js index ce95ea3f..29f2b8d5 100644 --- a/src/components/PerspectiveView/Row.js +++ b/src/components/PerspectiveView/Row.js @@ -29,6 +29,7 @@ const Row = ({ resetCheckedColumn, resetCheckedAll, reRender, + queryArgs, /* eslint-disable react/prop-types */ showEntryId, selectDisabled, @@ -97,6 +98,7 @@ const Row = ({ entitiesMode={entitiesMode} disabled={disabled_flag} reRender={reRender} + queryArgs={queryArgs} /> ))} @@ -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 = { @@ -166,7 +169,8 @@ Row.defaultProps = { resetCheckedRow: () => {}, resetCheckedColumn: () => {}, resetCheckedAll: () => {}, - reRender: () => console.debug('Fake refetch') + reRender: () => console.debug('Fake refetch'), + queryArgs: null }; export default onlyUpdateForKeys([ @@ -178,5 +182,6 @@ export default onlyUpdateForKeys([ "checkedRow", "checkedColumn", "checkedAll", - "columns" + "columns", + "queryArgs" ])(Row); \ No newline at end of file diff --git a/src/components/PerspectiveView/TableBody.js b/src/components/PerspectiveView/TableBody.js index a87bcf5e..c625e641 100644 --- a/src/components/PerspectiveView/TableBody.js +++ b/src/components/PerspectiveView/TableBody.js @@ -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 = { @@ -49,7 +50,8 @@ TableBody.defaultProps = { resetCheckedRow: () => {}, resetCheckedColumn: () => {}, resetCheckedAll: () => {}, - reRender: () => console.log('Fake refetch') + reRender: () => console.log('Fake refetch'), + queryArgs: null }; export default onlyUpdateForKeys([ @@ -60,5 +62,6 @@ export default onlyUpdateForKeys([ "selectedRows", "checkedRow", "checkedColumn", - "checkedAll" + "checkedAll", + "queryArgs" ])(TableBody); \ No newline at end of file diff --git a/src/components/PerspectiveView/index.js b/src/components/PerspectiveView/index.js index ae53be9b..ca94fc78 100644 --- a/src/components/PerspectiveView/index.js +++ b/src/components/PerspectiveView/index.js @@ -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) { @@ -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)) { @@ -683,6 +660,7 @@ class P extends React.Component { resetCheckedAll={this.resetCheckedAll} onEntrySelect={onEntrySelect} reRender={reRender} + queryArgs={query_args} />