@trackunit/react-graphql-hooks 0.0.172 → 0.0.174
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 +41 -63
- package/index.esm.js +37 -53
- package/package.json +5 -4
- package/src/translation.d.ts +1 -2
- package/src/usePaginationQuery.demo.d.ts +1 -2
- package/src/usePaginationQuery.stories.d.ts +1 -2
- package/translation.cjs.js +1 -1
- package/translation.cjs10.js +1 -1
- package/translation.cjs11.js +1 -1
- package/translation.cjs12.js +1 -1
- package/translation.cjs13.js +1 -1
- package/translation.cjs14.js +1 -1
- package/translation.cjs15.js +1 -1
- package/translation.cjs16.js +1 -1
- package/translation.cjs17.js +1 -1
- package/translation.cjs2.js +1 -1
- package/translation.cjs3.js +1 -1
- package/translation.cjs4.js +1 -1
- package/translation.cjs5.js +1 -1
- package/translation.cjs6.js +1 -1
- package/translation.cjs7.js +1 -1
- package/translation.cjs8.js +1 -1
- package/translation.cjs9.js +1 -1
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
require('react/jsx-runtime');
|
|
6
4
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
5
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
@@ -10,10 +8,7 @@ var reactTablePagination = require('@trackunit/react-table-pagination');
|
|
|
10
8
|
var isEqual = require('lodash/isEqual');
|
|
11
9
|
var react = require('react');
|
|
12
10
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
function _interopNamespace(e) {
|
|
16
|
-
if (e && e.__esModule) return e;
|
|
11
|
+
function _interopNamespaceDefault(e) {
|
|
17
12
|
var n = Object.create(null);
|
|
18
13
|
if (e) {
|
|
19
14
|
Object.keys(e).forEach(function (k) {
|
|
@@ -26,12 +21,11 @@ function _interopNamespace(e) {
|
|
|
26
21
|
}
|
|
27
22
|
});
|
|
28
23
|
}
|
|
29
|
-
n
|
|
24
|
+
n.default = e;
|
|
30
25
|
return Object.freeze(n);
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
var ApolloClient__namespace = /*#__PURE__*/
|
|
34
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
28
|
+
var ApolloClient__namespace = /*#__PURE__*/_interopNamespaceDefault(ApolloClient);
|
|
35
29
|
|
|
36
30
|
var defaultTranslations = {
|
|
37
31
|
|
|
@@ -98,38 +92,6 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
|
|
|
98
92
|
.filter(sharedUtils.truthy);
|
|
99
93
|
};
|
|
100
94
|
|
|
101
|
-
/******************************************************************************
|
|
102
|
-
Copyright (c) Microsoft Corporation.
|
|
103
|
-
|
|
104
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
105
|
-
purpose with or without fee is hereby granted.
|
|
106
|
-
|
|
107
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
108
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
109
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
110
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
111
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
112
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
113
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
114
|
-
***************************************************************************** */
|
|
115
|
-
|
|
116
|
-
function __rest(s, e) {
|
|
117
|
-
var t = {};
|
|
118
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
119
|
-
t[p] = s[p];
|
|
120
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
121
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
122
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
123
|
-
t[p[i]] = s[p[i]];
|
|
124
|
-
}
|
|
125
|
-
return t;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
129
|
-
var e = new Error(message);
|
|
130
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
95
|
/**
|
|
134
96
|
* This hook is used to fetch data from a GraphQL query and support pagination, it will help maintain the data and the pagination.
|
|
135
97
|
*
|
|
@@ -171,8 +133,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
171
133
|
* @param {PaginationQueryProps<TData, TVariables>} props - The properties for configuring the query. This includes the `updateQuery` function for merging new and existing data, and options for pagination such as `pageSize`. Also includes other lazy query hook options from Apollo Client.
|
|
172
134
|
* @returns {*} {PaginationQuery}
|
|
173
135
|
*/
|
|
174
|
-
const usePaginationQuery = (document,
|
|
175
|
-
var props = __rest(_a, []);
|
|
136
|
+
const usePaginationQuery = (document, { ...props }) => {
|
|
176
137
|
const [lastFetchedData, setLastFetchedData] = react.useState();
|
|
177
138
|
const [resetTrigger, setResetTrigger] = react.useState(0);
|
|
178
139
|
// Makes **sure** query variables are stable.
|
|
@@ -181,21 +142,29 @@ const usePaginationQuery = (document, _a) => {
|
|
|
181
142
|
// If ever a better solution is found, please remove this ugliness.
|
|
182
143
|
const stableVariables = react.useRef(props.variables);
|
|
183
144
|
const internalProps = react.useMemo(() => {
|
|
184
|
-
if (!
|
|
145
|
+
if (!isEqual(props.variables, stableVariables.current)) {
|
|
185
146
|
stableVariables.current = props.variables;
|
|
186
147
|
}
|
|
187
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
...props,
|
|
150
|
+
variables: stableVariables.current,
|
|
151
|
+
};
|
|
188
152
|
}, [props]);
|
|
189
|
-
const [, { fetchMore, networkStatus }] = ApolloClient__namespace.useLazyQuery(document,
|
|
153
|
+
const [, { fetchMore, networkStatus }] = ApolloClient__namespace.useLazyQuery(document, {
|
|
154
|
+
...internalProps,
|
|
155
|
+
notifyOnNetworkStatusChange: true, // Needed to update networkStatus
|
|
156
|
+
onCompleted: () => {
|
|
190
157
|
if (networkStatus === ApolloClient__namespace.NetworkStatus.refetch) {
|
|
191
158
|
// trigger reset for refetchQueries for the provided document.
|
|
192
159
|
setResetTrigger(prev => prev + 1);
|
|
193
160
|
}
|
|
194
|
-
},
|
|
161
|
+
},
|
|
195
162
|
// This is safe since we have no cache
|
|
196
163
|
// and without it it will make a magic extra call to the query check this
|
|
197
164
|
// https://stackoverflow.com/questions/66441463/fetchmore-request-executed-twice-every-time
|
|
198
|
-
nextFetchPolicy: "network-only",
|
|
165
|
+
nextFetchPolicy: "network-only",
|
|
166
|
+
initialFetchPolicy: "network-only",
|
|
167
|
+
});
|
|
199
168
|
const [data, setData] = react.useState();
|
|
200
169
|
const onReset = react.useCallback(() => {
|
|
201
170
|
setResetTrigger(prev => prev + 1);
|
|
@@ -210,22 +179,31 @@ const usePaginationQuery = (document, _a) => {
|
|
|
210
179
|
/**
|
|
211
180
|
* To support pagination with page and pageSize, we need to convert the variables from first and after.
|
|
212
181
|
*/
|
|
213
|
-
let fetchMoreVariables =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
182
|
+
let fetchMoreVariables = {
|
|
183
|
+
...internalProps.variables,
|
|
184
|
+
...(internalProps.variables && "page" in internalProps.variables && "pageSize" in internalProps.variables
|
|
185
|
+
? // eslint-disable-next-line local-rules/no-typescript-assertion
|
|
186
|
+
{
|
|
187
|
+
pageSize: variables.first,
|
|
188
|
+
page: Number(variables.after) || 0,
|
|
189
|
+
}
|
|
190
|
+
: { ...variables }),
|
|
191
|
+
};
|
|
220
192
|
// To support "pageable" queries we do it here! REMOVE once the serviceplans are updated to use the new pagination.
|
|
221
|
-
fetchMoreVariables =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
193
|
+
fetchMoreVariables = {
|
|
194
|
+
...("pageable" in fetchMoreVariables
|
|
195
|
+
? {
|
|
196
|
+
...fetchMoreVariables,
|
|
197
|
+
pageable: {
|
|
198
|
+
first: fetchMoreVariables.first,
|
|
199
|
+
last: fetchMoreVariables.last,
|
|
200
|
+
before: fetchMoreVariables.before,
|
|
201
|
+
after: fetchMoreVariables.after,
|
|
202
|
+
pageSize: fetchMoreVariables.pageSize,
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
: { ...fetchMoreVariables }),
|
|
206
|
+
};
|
|
229
207
|
fetchMore({
|
|
230
208
|
variables: fetchMoreVariables,
|
|
231
209
|
updateQuery: (_, { fetchMoreResult }) => {
|
package/index.esm.js
CHANGED
|
@@ -71,38 +71,6 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
|
|
|
71
71
|
.filter(truthy);
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
/******************************************************************************
|
|
75
|
-
Copyright (c) Microsoft Corporation.
|
|
76
|
-
|
|
77
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
78
|
-
purpose with or without fee is hereby granted.
|
|
79
|
-
|
|
80
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
81
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
82
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
83
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
84
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
85
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
86
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
87
|
-
***************************************************************************** */
|
|
88
|
-
|
|
89
|
-
function __rest(s, e) {
|
|
90
|
-
var t = {};
|
|
91
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
92
|
-
t[p] = s[p];
|
|
93
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
94
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
95
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
96
|
-
t[p[i]] = s[p[i]];
|
|
97
|
-
}
|
|
98
|
-
return t;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
102
|
-
var e = new Error(message);
|
|
103
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
74
|
/**
|
|
107
75
|
* This hook is used to fetch data from a GraphQL query and support pagination, it will help maintain the data and the pagination.
|
|
108
76
|
*
|
|
@@ -144,8 +112,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
144
112
|
* @param {PaginationQueryProps<TData, TVariables>} props - The properties for configuring the query. This includes the `updateQuery` function for merging new and existing data, and options for pagination such as `pageSize`. Also includes other lazy query hook options from Apollo Client.
|
|
145
113
|
* @returns {*} {PaginationQuery}
|
|
146
114
|
*/
|
|
147
|
-
const usePaginationQuery = (document,
|
|
148
|
-
var props = __rest(_a, []);
|
|
115
|
+
const usePaginationQuery = (document, { ...props }) => {
|
|
149
116
|
const [lastFetchedData, setLastFetchedData] = useState();
|
|
150
117
|
const [resetTrigger, setResetTrigger] = useState(0);
|
|
151
118
|
// Makes **sure** query variables are stable.
|
|
@@ -157,18 +124,26 @@ const usePaginationQuery = (document, _a) => {
|
|
|
157
124
|
if (!isEqual(props.variables, stableVariables.current)) {
|
|
158
125
|
stableVariables.current = props.variables;
|
|
159
126
|
}
|
|
160
|
-
return
|
|
127
|
+
return {
|
|
128
|
+
...props,
|
|
129
|
+
variables: stableVariables.current,
|
|
130
|
+
};
|
|
161
131
|
}, [props]);
|
|
162
|
-
const [, { fetchMore, networkStatus }] = ApolloClient.useLazyQuery(document,
|
|
132
|
+
const [, { fetchMore, networkStatus }] = ApolloClient.useLazyQuery(document, {
|
|
133
|
+
...internalProps,
|
|
134
|
+
notifyOnNetworkStatusChange: true, // Needed to update networkStatus
|
|
135
|
+
onCompleted: () => {
|
|
163
136
|
if (networkStatus === ApolloClient.NetworkStatus.refetch) {
|
|
164
137
|
// trigger reset for refetchQueries for the provided document.
|
|
165
138
|
setResetTrigger(prev => prev + 1);
|
|
166
139
|
}
|
|
167
|
-
},
|
|
140
|
+
},
|
|
168
141
|
// This is safe since we have no cache
|
|
169
142
|
// and without it it will make a magic extra call to the query check this
|
|
170
143
|
// https://stackoverflow.com/questions/66441463/fetchmore-request-executed-twice-every-time
|
|
171
|
-
nextFetchPolicy: "network-only",
|
|
144
|
+
nextFetchPolicy: "network-only",
|
|
145
|
+
initialFetchPolicy: "network-only",
|
|
146
|
+
});
|
|
172
147
|
const [data, setData] = useState();
|
|
173
148
|
const onReset = useCallback(() => {
|
|
174
149
|
setResetTrigger(prev => prev + 1);
|
|
@@ -183,22 +158,31 @@ const usePaginationQuery = (document, _a) => {
|
|
|
183
158
|
/**
|
|
184
159
|
* To support pagination with page and pageSize, we need to convert the variables from first and after.
|
|
185
160
|
*/
|
|
186
|
-
let fetchMoreVariables =
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
161
|
+
let fetchMoreVariables = {
|
|
162
|
+
...internalProps.variables,
|
|
163
|
+
...(internalProps.variables && "page" in internalProps.variables && "pageSize" in internalProps.variables
|
|
164
|
+
? // eslint-disable-next-line local-rules/no-typescript-assertion
|
|
165
|
+
{
|
|
166
|
+
pageSize: variables.first,
|
|
167
|
+
page: Number(variables.after) || 0,
|
|
168
|
+
}
|
|
169
|
+
: { ...variables }),
|
|
170
|
+
};
|
|
193
171
|
// To support "pageable" queries we do it here! REMOVE once the serviceplans are updated to use the new pagination.
|
|
194
|
-
fetchMoreVariables =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
172
|
+
fetchMoreVariables = {
|
|
173
|
+
...("pageable" in fetchMoreVariables
|
|
174
|
+
? {
|
|
175
|
+
...fetchMoreVariables,
|
|
176
|
+
pageable: {
|
|
177
|
+
first: fetchMoreVariables.first,
|
|
178
|
+
last: fetchMoreVariables.last,
|
|
179
|
+
before: fetchMoreVariables.before,
|
|
180
|
+
after: fetchMoreVariables.after,
|
|
181
|
+
pageSize: fetchMoreVariables.pageSize,
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
: { ...fetchMoreVariables }),
|
|
185
|
+
};
|
|
202
186
|
fetchMore({
|
|
203
187
|
variables: fetchMoreVariables,
|
|
204
188
|
updateQuery: (_, { fetchMoreResult }) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-graphql-hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.174",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@apollo/client": "3.10.4",
|
|
11
|
-
"react": "
|
|
11
|
+
"react": "18.3.1",
|
|
12
12
|
"@trackunit/i18n-library-translation": "*",
|
|
13
13
|
"@trackunit/shared-utils": "*",
|
|
14
14
|
"@trackunit/react-table-pagination": "*",
|
|
15
15
|
"lodash": "4.17.21"
|
|
16
16
|
},
|
|
17
17
|
"module": "./index.esm.js",
|
|
18
|
-
"main": "./index.cjs.js"
|
|
19
|
-
|
|
18
|
+
"main": "./index.cjs.js",
|
|
19
|
+
"types": "./index.esm.d.ts"
|
|
20
|
+
}
|
package/src/translation.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { NamespaceTransProps, TransForLibs, TranslationResource } from "@trackunit/i18n-library-translation";
|
|
3
2
|
import defaultTranslations from "./locales/en/translation.json";
|
|
4
3
|
/** A type for all available translation keys in this library */
|
|
@@ -27,7 +26,7 @@ export type TranslationFunction = TransForLibs<TranslationKeys>;
|
|
|
27
26
|
/**
|
|
28
27
|
* Trans for this specific library.
|
|
29
28
|
*/
|
|
30
|
-
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => JSX.Element;
|
|
29
|
+
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => import("react/jsx-runtime").JSX.Element;
|
|
31
30
|
/**
|
|
32
31
|
* Registers the translations for this library
|
|
33
32
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import * as ApolloClient from "@apollo/client";
|
|
3
2
|
import { PaginationQueryProps } from "./usePaginationQuery";
|
|
4
3
|
export interface UsePaginationQueryDemoComponentProps<TData, TVariables extends ApolloClient.OperationVariables> extends PaginationQueryProps<TData, TVariables> {
|
|
@@ -9,4 +8,4 @@ export interface UsePaginationQueryDemoComponentProps<TData, TVariables extends
|
|
|
9
8
|
*
|
|
10
9
|
* It returns an object containing methods and values related to pagination.
|
|
11
10
|
*/
|
|
12
|
-
export declare const UsePaginationQueryDemoComponent: <TData, TVariables extends ApolloClient.OperationVariables>({ document, variables, pageSize, updateQuery, }: UsePaginationQueryDemoComponentProps<TData, TVariables>) => JSX.Element;
|
|
11
|
+
export declare const UsePaginationQueryDemoComponent: <TData, TVariables extends ApolloClient.OperationVariables>({ document, variables, pageSize, updateQuery, }: UsePaginationQueryDemoComponentProps<TData, TVariables>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Meta, StoryObj } from "@storybook/react";
|
|
3
2
|
import { UsePaginationQueryDemoComponent } from "./usePaginationQuery.demo";
|
|
4
3
|
type Story = StoryObj<typeof UsePaginationQueryDemoComponent>;
|
|
5
4
|
declare const meta: Meta<typeof UsePaginationQueryDemoComponent>;
|
|
6
5
|
export default meta;
|
|
7
|
-
export declare const packageName: () => JSX.Element;
|
|
6
|
+
export declare const packageName: () => import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export declare const Default: Story;
|
package/translation.cjs.js
CHANGED
package/translation.cjs10.js
CHANGED
package/translation.cjs11.js
CHANGED
package/translation.cjs12.js
CHANGED
package/translation.cjs13.js
CHANGED
package/translation.cjs14.js
CHANGED
package/translation.cjs15.js
CHANGED
package/translation.cjs16.js
CHANGED
package/translation.cjs17.js
CHANGED
package/translation.cjs2.js
CHANGED
package/translation.cjs3.js
CHANGED
package/translation.cjs4.js
CHANGED
package/translation.cjs5.js
CHANGED
package/translation.cjs6.js
CHANGED
package/translation.cjs7.js
CHANGED
package/translation.cjs8.js
CHANGED
package/translation.cjs9.js
CHANGED