@trackunit/react-graphql-hooks 0.0.13 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -162,10 +162,19 @@ const usePaginationQuery = (document, props) => {
162
162
  /**
163
163
  * To support pagination with page and pageSize, we need to convert the variables from first and after.
164
164
  */
165
- const fetchMoreVariables = Object.assign(Object.assign({}, props.variables), (props.variables && "page" in props.variables && "pageSize" in props.variables
165
+ let fetchMoreVariables = Object.assign(Object.assign({}, props.variables), (props.variables && "page" in props.variables && "pageSize" in props.variables
166
166
  ? // eslint-disable-next-line local-rules/no-typescript-assertion
167
167
  { pageSize: variables.first, page: Number(variables.after) || 0 }
168
168
  : Object.assign({}, variables)));
169
+ // To support "pageable" queries we do it here! REMOVE once the serviceplans are updated to use the new pagination.
170
+ fetchMoreVariables = Object.assign({}, ("pageable" in fetchMoreVariables
171
+ ? Object.assign(Object.assign({}, fetchMoreVariables), { pageable: {
172
+ first: fetchMoreVariables.first,
173
+ last: fetchMoreVariables.last,
174
+ before: fetchMoreVariables.before,
175
+ after: fetchMoreVariables.after,
176
+ pageSize: fetchMoreVariables.pageSize,
177
+ } }) : Object.assign({}, fetchMoreVariables)));
169
178
  fetchMore({
170
179
  variables: fetchMoreVariables,
171
180
  updateQuery: (_, { fetchMoreResult }) => {
@@ -192,9 +201,10 @@ const usePaginationQuery = (document, props) => {
192
201
  }, [setIsLoading, props, fetchMore, setPageInfo]);
193
202
  react.useEffect(() => {
194
203
  setData(undefined);
195
- }, [props.variables]);
204
+ reset();
205
+ }, [props.variables, reset]);
196
206
  react.useEffect(() => {
197
- const abortController = doFetchMore({ first: first, last: undefined, before: undefined, after: undefined }, undefined);
207
+ const abortController = doFetchMore({ first, last: undefined, before: undefined, after: undefined }, undefined);
198
208
  return () => {
199
209
  abortController.abort();
200
210
  };
package/index.esm.js CHANGED
@@ -138,10 +138,19 @@ const usePaginationQuery = (document, props) => {
138
138
  /**
139
139
  * To support pagination with page and pageSize, we need to convert the variables from first and after.
140
140
  */
141
- const fetchMoreVariables = Object.assign(Object.assign({}, props.variables), (props.variables && "page" in props.variables && "pageSize" in props.variables
141
+ let fetchMoreVariables = Object.assign(Object.assign({}, props.variables), (props.variables && "page" in props.variables && "pageSize" in props.variables
142
142
  ? // eslint-disable-next-line local-rules/no-typescript-assertion
143
143
  { pageSize: variables.first, page: Number(variables.after) || 0 }
144
144
  : Object.assign({}, variables)));
145
+ // To support "pageable" queries we do it here! REMOVE once the serviceplans are updated to use the new pagination.
146
+ fetchMoreVariables = Object.assign({}, ("pageable" in fetchMoreVariables
147
+ ? Object.assign(Object.assign({}, fetchMoreVariables), { pageable: {
148
+ first: fetchMoreVariables.first,
149
+ last: fetchMoreVariables.last,
150
+ before: fetchMoreVariables.before,
151
+ after: fetchMoreVariables.after,
152
+ pageSize: fetchMoreVariables.pageSize,
153
+ } }) : Object.assign({}, fetchMoreVariables)));
145
154
  fetchMore({
146
155
  variables: fetchMoreVariables,
147
156
  updateQuery: (_, { fetchMoreResult }) => {
@@ -168,9 +177,10 @@ const usePaginationQuery = (document, props) => {
168
177
  }, [setIsLoading, props, fetchMore, setPageInfo]);
169
178
  useEffect(() => {
170
179
  setData(undefined);
171
- }, [props.variables]);
180
+ reset();
181
+ }, [props.variables, reset]);
172
182
  useEffect(() => {
173
- const abortController = doFetchMore({ first: first, last: undefined, before: undefined, after: undefined }, undefined);
183
+ const abortController = doFetchMore({ first, last: undefined, before: undefined, after: undefined }, undefined);
174
184
  return () => {
175
185
  abortController.abort();
176
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-hooks",
3
- "version": "0.0.13",
3
+ "version": "0.0.17",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {