@trackunit/react-graphql-hooks 0.0.12-alpha-3fd0172a5e.0 → 0.0.15

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 }) => {
@@ -194,7 +203,7 @@ const usePaginationQuery = (document, props) => {
194
203
  setData(undefined);
195
204
  }, [props.variables]);
196
205
  react.useEffect(() => {
197
- const abortController = doFetchMore({ first: first, last: undefined, before: undefined, after: undefined }, undefined);
206
+ const abortController = doFetchMore({ first, last: undefined, before: undefined, after: undefined }, undefined);
198
207
  return () => {
199
208
  abortController.abort();
200
209
  };
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 }) => {
@@ -170,7 +179,7 @@ const usePaginationQuery = (document, props) => {
170
179
  setData(undefined);
171
180
  }, [props.variables]);
172
181
  useEffect(() => {
173
- const abortController = doFetchMore({ first: first, last: undefined, before: undefined, after: undefined }, undefined);
182
+ const abortController = doFetchMore({ first, last: undefined, before: undefined, after: undefined }, undefined);
174
183
  return () => {
175
184
  abortController.abort();
176
185
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-hooks",
3
- "version": "0.0.12-alpha-3fd0172a5e.0",
3
+ "version": "0.0.15",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -9,13 +9,25 @@ export type PaginationQuery<TData> = {
9
9
  lastFetchedData?: TData;
10
10
  pagination: RelayTableSupport;
11
11
  };
12
- export type PaginationQueryProps<TData, TVariables extends ApolloClient.OperationVariables = ApolloClient.OperationVariables> = {
12
+ export interface PaginationQueryProps<TData, TVariables extends ApolloClient.OperationVariables = ApolloClient.OperationVariables> extends ApolloClient.LazyQueryHookOptions<TData, TVariables> {
13
+ /**
14
+ * A function that is used to update the query results with new data.
15
+ *
16
+ * @param previous The previous data from the query, which can be undefined if no previous data exists.
17
+ * @param newData The new data to merge with the previous data.
18
+ * @returns an object containing the merged data, with an optional pageInfo field of type RelayPageInfo or null.
19
+ */
13
20
  updateQuery: (previous: TData | undefined, newData: TData) => {
14
21
  data: TData;
15
22
  pageInfo?: RelayPageInfo | null;
16
23
  };
24
+ /**
25
+ * A number specifying the size of each page of data.
26
+ * This is an optional field.
27
+ * If not specified, the default page size is 50.
28
+ */
17
29
  pageSize?: number;
18
- } & ApolloClient.LazyQueryHookOptions<TData, TVariables>;
30
+ }
19
31
  /**
20
32
  * This hook is used to fetch data from a GraphQL query and support pagination, it will help maintain the data and the pagination.
21
33
  *
@@ -0,0 +1,11 @@
1
+ import * as ApolloClient from "@apollo/client";
2
+ import { PaginationQueryProps } from "./usePaginationQuery";
3
+ export interface UsePaginationQueryDemoComponentProps<TData, TVariables extends ApolloClient.OperationVariables> extends PaginationQueryProps<TData, TVariables> {
4
+ document: ApolloClient.TypedDocumentNode<TData, TVariables>;
5
+ }
6
+ /**
7
+ * The `usePaginationQuery` Hook provides pagination when fetching data
8
+ *
9
+ * It returns an object containing methods and values related to pagination.
10
+ */
11
+ export declare const UsePaginationQueryDemoComponent: <TData, TVariables extends ApolloClient.OperationVariables>({ document, variables, pageSize, updateQuery, }: UsePaginationQueryDemoComponentProps<TData, TVariables>) => JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { Meta, StoryObj } from "@storybook/react";
2
+ import { UsePaginationQueryDemoComponent } from "./usePaginationQuery.demo";
3
+ type Story = StoryObj<typeof UsePaginationQueryDemoComponent>;
4
+ declare const meta: Meta<typeof UsePaginationQueryDemoComponent>;
5
+ export default meta;
6
+ export declare const packageName: () => JSX.Element;
7
+ export declare const Default: Story;