@trackunit/react-graphql-hooks 0.0.1-alpha-1820203754.0 → 0.0.1

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
@@ -6,6 +6,7 @@ require('react/jsx-runtime');
6
6
  var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
7
7
  var sharedUtils = require('@trackunit/shared-utils');
8
8
  var ApolloClient = require('@apollo/client');
9
+ var reactTable = require('@trackunit/react-table');
9
10
  var react = require('react');
10
11
 
11
12
  function _interopNamespace(e) {
@@ -93,60 +94,6 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
93
94
  .filter(sharedUtils.truthy);
94
95
  };
95
96
 
96
- /**
97
- * Custom hook for handling Relay pagination in tables.
98
- *
99
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
100
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
101
- */
102
- const useRelayPagination = (props = { pageSize: 50 }) => {
103
- const [variables, setVariables] = react.useState({ first: props.pageSize });
104
- const [pageInfo, setPageInfo] = react.useState();
105
- const [isLoading, setIsLoading] = react.useState(false);
106
- const nextPage = react.useCallback(() => {
107
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
108
- setVariables({
109
- after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
110
- first: props.pageSize,
111
- });
112
- }
113
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
114
- const previousPage = react.useCallback(() => {
115
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
116
- setVariables({
117
- before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
118
- last: props.pageSize,
119
- });
120
- }
121
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
122
- const reset = react.useCallback(() => {
123
- setVariables({
124
- last: undefined,
125
- before: undefined,
126
- after: undefined,
127
- first: props.pageSize,
128
- });
129
- if (props.onReset) {
130
- props.onReset();
131
- }
132
- // eslint-disable-next-line react-hooks/exhaustive-deps
133
- }, [props.onReset, props.pageSize]);
134
- return react.useMemo(() => {
135
- return {
136
- variables,
137
- table: {
138
- nextPage,
139
- previousPage,
140
- isLoading,
141
- setIsLoading,
142
- reset,
143
- pageInfo: pageInfo === null ? undefined : pageInfo,
144
- setPageInfo,
145
- },
146
- };
147
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
148
- };
149
-
150
97
  /**
151
98
  * This hook is used to fetch data from a GraphQL query and support pagination, it will help maintain the data and the pagination.
152
99
  *
@@ -205,7 +152,7 @@ const usePaginationQuery = (document, props) => {
205
152
  const onReset = react.useCallback(() => {
206
153
  setResetTrigger(prev => prev + 1);
207
154
  }, []);
208
- const { table: { setIsLoading, isLoading, setPageInfo, pageInfo, reset, nextPage, previousPage }, variables: { first, after }, } = useRelayPagination({
155
+ const { table: { setIsLoading, isLoading, setPageInfo, pageInfo, reset, nextPage, previousPage }, variables: { first, after }, } = reactTable.useRelayPagination({
209
156
  pageSize: props.pageSize || 50,
210
157
  onReset,
211
158
  });
@@ -280,4 +227,3 @@ setupLibraryTranslations();
280
227
 
281
228
  exports.unionEdgesByNodeKey = unionEdgesByNodeKey;
282
229
  exports.usePaginationQuery = usePaginationQuery;
283
- exports.useRelayPagination = useRelayPagination;
package/index.esm.js CHANGED
@@ -2,7 +2,8 @@ import 'react/jsx-runtime';
2
2
  import { registerTranslations } from '@trackunit/i18n-library-translation';
3
3
  import { truthy } from '@trackunit/shared-utils';
4
4
  import * as ApolloClient from '@apollo/client';
5
- import { useState, useCallback, useMemo, useEffect } from 'react';
5
+ import { useRelayPagination } from '@trackunit/react-table';
6
+ import { useState, useCallback, useEffect, useMemo } from 'react';
6
7
 
7
8
  var defaultTranslations = {
8
9
 
@@ -69,60 +70,6 @@ const unionEdgesByNodeKey = (key, previousEdges, newEdges) => {
69
70
  .filter(truthy);
70
71
  };
71
72
 
72
- /**
73
- * Custom hook for handling Relay pagination in tables.
74
- *
75
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
76
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
77
- */
78
- const useRelayPagination = (props = { pageSize: 50 }) => {
79
- const [variables, setVariables] = useState({ first: props.pageSize });
80
- const [pageInfo, setPageInfo] = useState();
81
- const [isLoading, setIsLoading] = useState(false);
82
- const nextPage = useCallback(() => {
83
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
84
- setVariables({
85
- after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
86
- first: props.pageSize,
87
- });
88
- }
89
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
90
- const previousPage = useCallback(() => {
91
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
92
- setVariables({
93
- before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
94
- last: props.pageSize,
95
- });
96
- }
97
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
98
- const reset = useCallback(() => {
99
- setVariables({
100
- last: undefined,
101
- before: undefined,
102
- after: undefined,
103
- first: props.pageSize,
104
- });
105
- if (props.onReset) {
106
- props.onReset();
107
- }
108
- // eslint-disable-next-line react-hooks/exhaustive-deps
109
- }, [props.onReset, props.pageSize]);
110
- return useMemo(() => {
111
- return {
112
- variables,
113
- table: {
114
- nextPage,
115
- previousPage,
116
- isLoading,
117
- setIsLoading,
118
- reset,
119
- pageInfo: pageInfo === null ? undefined : pageInfo,
120
- setPageInfo,
121
- },
122
- };
123
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
124
- };
125
-
126
73
  /**
127
74
  * This hook is used to fetch data from a GraphQL query and support pagination, it will help maintain the data and the pagination.
128
75
  *
@@ -254,4 +201,4 @@ const usePaginationQuery = (document, props) => {
254
201
  */
255
202
  setupLibraryTranslations();
256
203
 
257
- export { unionEdgesByNodeKey, usePaginationQuery, useRelayPagination };
204
+ export { unionEdgesByNodeKey, usePaginationQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-hooks",
3
- "version": "0.0.1-alpha-1820203754.0",
3
+ "version": "0.0.1",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,7 +10,8 @@
10
10
  "@apollo/client": "^3.7.10",
11
11
  "react": "^18.2.0",
12
12
  "@trackunit/i18n-library-translation": "*",
13
- "@trackunit/shared-utils": "*"
13
+ "@trackunit/shared-utils": "*",
14
+ "@trackunit/react-table": "*"
14
15
  },
15
16
  "module": "./index.esm.js",
16
17
  "main": "./index.cjs.js"
package/src/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./unionEdgesByNodeKey";
2
2
  export * from "./usePaginationQuery";
3
- export * from "./useRelayPagination";
@@ -1,5 +1,5 @@
1
1
  import * as ApolloClient from "@apollo/client";
2
- import { RelayPageInfo, RelayTableSupport } from "./useRelayPagination";
2
+ import { RelayPageInfo, RelayTableSupport } from "@trackunit/react-table";
3
3
  /**
4
4
  * This type is used to return the data from the query, the pagination object and the last fetched data.
5
5
  */
@@ -1,41 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- export interface RelayPaginationProps {
3
- pageSize?: number;
4
- onReset?: () => void;
5
- }
6
- export interface RelayPageInfo {
7
- count?: number | null;
8
- endCursor?: string | null;
9
- hasNextPage?: boolean;
10
- hasPreviousPage?: boolean;
11
- startCursor?: string | null;
12
- }
13
- export interface RelayPagination {
14
- nextPage: () => void;
15
- previousPage: () => void;
16
- pageInfo?: RelayPageInfo;
17
- isLoading: boolean;
18
- }
19
- export interface RelayPaginationQueryVariables {
20
- first?: number | null;
21
- last?: number | null;
22
- before?: string | null;
23
- after?: string | null;
24
- }
25
- export interface RelayTableSupport extends RelayPagination {
26
- isLoading: boolean;
27
- setIsLoading: Dispatch<SetStateAction<boolean>>;
28
- reset: () => void;
29
- setPageInfo: Dispatch<SetStateAction<RelayPageInfo | null | undefined>>;
30
- }
31
- export interface RelayPaginationSupport {
32
- variables: RelayPaginationQueryVariables;
33
- table: RelayTableSupport;
34
- }
35
- /**
36
- * Custom hook for handling Relay pagination in tables.
37
- *
38
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
39
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
40
- */
41
- export declare const useRelayPagination: (props?: RelayPaginationProps) => RelayPaginationSupport;