@trackunit/react-table 0.0.220 → 0.0.222-alpha-71e42cacef.0

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
@@ -588,60 +588,6 @@ const Sorting = ({ columns, }) => {
588
588
  }) }), jsxRuntime.jsxs(reactFormComponents.RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
589
589
  };
590
590
 
591
- /**
592
- * Custom hook for handling Relay pagination in tables.
593
- *
594
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
595
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
596
- */
597
- const useRelayPagination = (props = { pageSize: 50 }) => {
598
- const [variables, setVariables] = React.useState({ first: props.pageSize });
599
- const [pageInfo, setPageInfo] = React.useState();
600
- const [isLoading, setIsLoading] = React.useState(false);
601
- const nextPage = React.useCallback(() => {
602
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
603
- setVariables({
604
- after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
605
- first: props.pageSize,
606
- });
607
- }
608
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
609
- const previousPage = React.useCallback(() => {
610
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
611
- setVariables({
612
- before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
613
- last: props.pageSize,
614
- });
615
- }
616
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
617
- const reset = React.useCallback(() => {
618
- setVariables({
619
- last: undefined,
620
- before: undefined,
621
- after: undefined,
622
- first: props.pageSize,
623
- });
624
- if (props.onReset) {
625
- props.onReset();
626
- }
627
- // eslint-disable-next-line react-hooks/exhaustive-deps
628
- }, [props.onReset, props.pageSize]);
629
- return React.useMemo(() => {
630
- return {
631
- variables,
632
- table: {
633
- nextPage,
634
- previousPage,
635
- isLoading,
636
- setIsLoading,
637
- reset,
638
- pageInfo: pageInfo === null ? undefined : pageInfo,
639
- setPageInfo,
640
- },
641
- };
642
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
643
- };
644
-
645
591
  /**
646
592
  * Hook for managing and controlling a table's state and behavior.
647
593
  *
@@ -862,6 +808,5 @@ exports.fromTUSortToTanStack = fromTUSortToTanStack;
862
808
  exports.fromTUSortToTanStackSite = fromTUSortToTanStackSite;
863
809
  exports.fromTanStackToTUSort = fromTanStackToTUSort;
864
810
  exports.fromTanStackToTUSortSite = fromTanStackToTUSortSite;
865
- exports.useRelayPagination = useRelayPagination;
866
811
  exports.useTable = useTable;
867
812
  exports.useTableSelection = useTableSelection;
package/index.esm.js CHANGED
@@ -563,60 +563,6 @@ const Sorting = ({ columns, }) => {
563
563
  }) }), jsxs(RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsx(RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsx(RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
564
564
  };
565
565
 
566
- /**
567
- * Custom hook for handling Relay pagination in tables.
568
- *
569
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
570
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
571
- */
572
- const useRelayPagination = (props = { pageSize: 50 }) => {
573
- const [variables, setVariables] = useState({ first: props.pageSize });
574
- const [pageInfo, setPageInfo] = useState();
575
- const [isLoading, setIsLoading] = useState(false);
576
- const nextPage = useCallback(() => {
577
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage) {
578
- setVariables({
579
- after: pageInfo.endCursor === null ? undefined : pageInfo.endCursor,
580
- first: props.pageSize,
581
- });
582
- }
583
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.endCursor, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasNextPage, props.pageSize]);
584
- const previousPage = useCallback(() => {
585
- if (pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage) {
586
- setVariables({
587
- before: pageInfo.startCursor === null ? undefined : pageInfo.startCursor,
588
- last: props.pageSize,
589
- });
590
- }
591
- }, [pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.hasPreviousPage, pageInfo === null || pageInfo === void 0 ? void 0 : pageInfo.startCursor, props.pageSize]);
592
- const reset = useCallback(() => {
593
- setVariables({
594
- last: undefined,
595
- before: undefined,
596
- after: undefined,
597
- first: props.pageSize,
598
- });
599
- if (props.onReset) {
600
- props.onReset();
601
- }
602
- // eslint-disable-next-line react-hooks/exhaustive-deps
603
- }, [props.onReset, props.pageSize]);
604
- return useMemo(() => {
605
- return {
606
- variables,
607
- table: {
608
- nextPage,
609
- previousPage,
610
- isLoading,
611
- setIsLoading,
612
- reset,
613
- pageInfo: pageInfo === null ? undefined : pageInfo,
614
- setPageInfo,
615
- },
616
- };
617
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
618
- };
619
-
620
566
  /**
621
567
  * Hook for managing and controlling a table's state and behavior.
622
568
  *
@@ -824,4 +770,4 @@ const fromTanStackToTUSortSite = (input) => {
824
770
  */
825
771
  setupLibraryTranslations();
826
772
 
827
- export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useRelayPagination, useTable, useTableSelection };
773
+ export { ActionSheet, ColumnFilter, RowSpacing, Sorting, Table, fromTUSortToTanStack, fromTUSortToTanStackSite, fromTanStackToTUSort, fromTanStackToTUSortSite, useTable, useTableSelection };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-table",
3
- "version": "0.0.220",
3
+ "version": "0.0.222-alpha-71e42cacef.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -12,6 +12,7 @@
12
12
  "react-router-dom": "6.18.0",
13
13
  "@tanstack/react-table": "^8.10.7",
14
14
  "@trackunit/react-table-base-components": "*",
15
+ "@trackunit/react-table-pagination": "*",
15
16
  "@trackunit/react-form-components": "*",
16
17
  "immutability-helper": "^3.1.1",
17
18
  "react-dnd": "14.0.5",
package/src/Table.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { Table as ReactTable, Row } from "@tanstack/react-table";
3
3
  import { CommonProps } from "@trackunit/react-components";
4
- import { RelayPagination } from "./types";
4
+ import { RelayPagination } from "@trackunit/react-table-pagination";
5
5
  export interface TableProps<TData extends object> extends ReactTable<TData>, CommonProps {
6
6
  pagination: RelayPagination;
7
7
  headerLeftActions?: React.ReactNode;
package/src/index.d.ts CHANGED
@@ -5,7 +5,6 @@ export * from "./menus/ColumnFilter";
5
5
  export * from "./menus/RowSpacing";
6
6
  export * from "./menus/Sorting";
7
7
  export * from "./types";
8
- export * from "./useRelayPagination";
9
8
  export * from "./useTable";
10
9
  export * from "./useTableSelection";
11
10
  export * from "./utils";
package/src/types.d.ts CHANGED
@@ -9,17 +9,4 @@ declare module "@tanstack/react-table" {
9
9
  isCustomField?: boolean;
10
10
  }
11
11
  }
12
- export interface RelayPageInfo {
13
- count?: number | null;
14
- endCursor?: string | null;
15
- hasNextPage?: boolean;
16
- hasPreviousPage?: boolean;
17
- startCursor?: string | null;
18
- }
19
- export interface RelayPagination {
20
- nextPage: () => void;
21
- previousPage: () => void;
22
- pageInfo?: RelayPageInfo;
23
- isLoading: boolean;
24
- }
25
12
  export type Alignment = "left" | "center" | "right";
@@ -1,6 +1,6 @@
1
1
  import { VirtualItem } from "@tanstack/react-virtual";
2
+ import { RelayPagination } from "@trackunit/react-table-pagination";
2
3
  import { RefObject } from "react";
3
- import { RelayPagination } from "./types";
4
4
  interface InfiniteScrollProps {
5
5
  pagination: RelayPagination;
6
6
  containerRef: RefObject<HTMLDivElement>;
@@ -1,29 +0,0 @@
1
- import { Dispatch, SetStateAction } from "react";
2
- import { RelayPageInfo, RelayPagination } from "./types";
3
- export interface RelayPaginationProps {
4
- pageSize?: number;
5
- onReset?: () => void;
6
- }
7
- export interface RelayPaginationQueryVariables {
8
- first?: number | null;
9
- last?: number | null;
10
- before?: string | null;
11
- after?: string | null;
12
- }
13
- export interface RelayTableSupport extends RelayPagination {
14
- isLoading: boolean;
15
- setIsLoading: Dispatch<SetStateAction<boolean>>;
16
- reset: () => void;
17
- setPageInfo: Dispatch<SetStateAction<RelayPageInfo | null | undefined>>;
18
- }
19
- export interface RelayPaginationSupport {
20
- variables: RelayPaginationQueryVariables;
21
- table: RelayTableSupport;
22
- }
23
- /**
24
- * Custom hook for handling Relay pagination in tables.
25
- *
26
- * @param {RelayPaginationProps} props - The props object containing pagination configuration.
27
- * @returns {RelayPaginationSupport} An object containing functions and state for managing Relay pagination.
28
- */
29
- export declare const useRelayPagination: (props?: RelayPaginationProps) => RelayPaginationSupport;