@apia/table 4.0.28 → 4.0.29

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/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ import React__default, { FunctionComponent, ReactNode, FC } from 'react';
3
3
  import { BoxProps } from '@apia/theme';
4
4
  import { IconType } from '@meronex/icons';
5
5
  import * as _apia_util from '@apia/util';
6
- import { TApiaFilter, TModify, TId, TRequireOnlyOne, EventEmitter } from '@apia/util';
6
+ import { TApiaFilter, TModify, TRequireOnlyOne, EventEmitter } from '@apia/util';
7
+ import { IPagination } from '@apia/components';
7
8
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
8
9
  import { PayloadAction } from '@reduxjs/toolkit';
9
10
  import * as _apia_store from '@apia/store';
@@ -546,48 +547,9 @@ declare const Responsive: React__default.MemoExoticComponent<({ tableName }: {
546
547
  tableName?: string;
547
548
  }) => React__default.JSX.Element>;
548
549
 
549
- interface IPagination {
550
- appliedFilters?: number;
551
- /**
552
- * Este valor determina si el boton de eliminar filtros debe mostrarse como si hubieran filtros sin aplicar (en caso de que haya filtros aplicados por defecto) o si debe mostrarse como si todos los filtros con valor estan aplicados a la busqueda actual. Se deberia verificar con el slice de redux correspondiente a la tabla.
553
- */
554
- areAllFiltersApplied?: boolean;
555
- className?: string;
556
- currentPage: number | string;
557
- disabled?: boolean;
558
- disableReduced?: boolean;
559
- hideInfo?: boolean;
560
- hideMaximizeButton?: boolean;
561
- hideRefreshButton?: boolean;
562
- isLoading?: boolean;
563
- /**
564
- * Valor obtenido del buttonsSlice para bloquear los botones de la paginacion mientras se estan ejecutando acciones
565
- */
566
- isPerforming?: boolean;
567
- /**
568
- * Se usa principalmente en grillas de ejecución para indicar al pagination
569
- * que debe usar el fieldId de la misma y no el de un listado global.
570
- */
571
- listId?: TId;
572
- /**
573
- * Si se pasa un método onDeleteFilters, aparece el botón "Eliminar filtros"
574
- * cerca del refresh
575
- */
576
- onDeleteFilters?: () => unknown;
577
- onPageChange: (page: number) => unknown;
578
- onRefresh: (page: number) => unknown;
579
- pageCount: number | string;
580
- reachedMax?: boolean | undefined;
581
- hasMore?: boolean | undefined;
582
- /**
583
- * Si la cantidad de registros se obtiene desde un lugar distinto de Redux,
584
- * se puede pasar como number directamente
585
- */
586
- recordsCount?: number;
587
- showMaximizeOnSmallBreakpoints?: boolean;
588
- variant?: 'primary' | 'secondary' | 'datagrid';
589
- }
590
- declare const Pagination: React__default.MemoExoticComponent<({ appliedFilters, areAllFiltersApplied, className, currentPage, disabled, disableReduced, hasMore, hideInfo, hideMaximizeButton, hideRefreshButton, isLoading, isPerforming, listId: outerListId, onDeleteFilters, onPageChange, onRefresh, pageCount, recordsCount: outerRecordsCount, reachedMax, showMaximizeOnSmallBreakpoints, variant, }: IPagination) => React__default.JSX.Element>;
550
+ declare const Pagination: React__default.MemoExoticComponent<({ listId: outerListId, ...props }: Omit<IPagination, "isMaximized" | "onMaximize"> & {
551
+ listId: string;
552
+ }) => React__default.JSX.Element>;
591
553
 
592
554
  declare const Grouped: React__default.MemoExoticComponent<({ group, tableName, }: {
593
555
  group: string;
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
- import React, { useMemo, useRef, useState, createContext, useContext, memo, useEffect, useCallback, createRef, forwardRef } from 'react';
2
+ import React, { useMemo, useRef, useState, createContext, useContext, memo, forwardRef, useCallback } from 'react';
3
3
  import { Box, getVariant, Input, Select, useBreakpointIndex, Label, Link, Spinner } from '@apia/theme';
4
4
  import { useMount, useUpdateEffect, useUnmount, useThrottleFn } from 'ahooks';
5
5
  import uniqueId from 'lodash-es/uniqueId';
6
6
  import { injectReducers, createSlice, shallowEqual as shallowEqual$1 } from '@apia/store';
7
- import { addBoundary, useLatest, useUpdateEffect as useUpdateEffect$1, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, persistentStorage, EventEmitter, debugDispatcher, usePrevious, useIntermediateValue, getLabel, formatMessage, getDateFormat, noNaN, getIndex, downloadUrl, arrayOrArray, useMount as useMount$1 } from '@apia/util';
7
+ import { addBoundary, useLatest, useUpdateEffect as useUpdateEffect$1, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, persistentStorage, EventEmitter, debugDispatcher, usePrevious, useIntermediateValue, getLabel, formatMessage, getDateFormat, getIndex, noNaN, downloadUrl, arrayOrArray, useMount as useMount$1 } from '@apia/util';
8
8
  import { shallowEqual } from 'react-redux';
9
- import { useOtherTagButton, AutoEllipsis, ApiaFilter, IconButton, AccordionItem, Accordion, RequiredMark, ApiaUtil, SimpleButton } from '@apia/components';
9
+ import { useOtherTagButton, AutoEllipsis, ApiaFilter, IconButton, AccordionItem, Accordion, RequiredMark, Pagination as Pagination$1 } from '@apia/components';
10
10
  import { Icon } from '@apia/icons';
11
11
  import { FaSortUp, FaSortDown, FaSort, FaSquare } from '@meronex/icons/fa';
12
12
  import { MdKeyboardArrowDown, MdKeyboardArrowRight } from '@meronex/icons/md/';
@@ -2765,292 +2765,14 @@ function useIsMaximized(id) {
2765
2765
  }
2766
2766
 
2767
2767
  const NoMemoPagination = ({
2768
- appliedFilters,
2769
- areAllFiltersApplied,
2770
- className,
2771
- currentPage,
2772
- disabled,
2773
- disableReduced,
2774
- hasMore,
2775
- hideInfo,
2776
- hideMaximizeButton,
2777
- hideRefreshButton,
2778
- isLoading,
2779
- isPerforming,
2780
2768
  listId: outerListId,
2781
- onDeleteFilters,
2782
- onPageChange,
2783
- onRefresh,
2784
- pageCount,
2785
- recordsCount: outerRecordsCount,
2786
- reachedMax,
2787
- showMaximizeOnSmallBreakpoints,
2788
- variant = "primary"
2769
+ ...props
2789
2770
  }) => {
2790
- const numberPageCount = Number(pageCount);
2791
- const breakPoint = useBreakpointIndex();
2792
- const numberCurrentPage = Number(currentPage);
2793
- const recordsCount = outerRecordsCount;
2794
- const [internCurrentPage, setCurrentPage] = useState(
2795
- numberCurrentPage ?? 1
2796
- );
2797
- const [lastEmittedPage, setLastEmittedPage] = useState(
2798
- numberCurrentPage ?? 1
2799
- );
2800
- const [hasNoValue, setHasNoValue] = useState(false);
2801
- useEffect(() => {
2802
- setCurrentPage(numberCurrentPage);
2803
- }, [numberCurrentPage]);
2804
- const setCurrentAndDispatch = useCallback(
2805
- (page) => {
2806
- setCurrentPage(page);
2807
- onPageChange(page);
2808
- setLastEmittedPage(page);
2809
- },
2810
- [onPageChange]
2811
- );
2812
- const InputRef = createRef();
2813
2771
  const listId = useResponsiveTableContext().name;
2814
2772
  const { isMaximized, toggleIsMaximized } = useIsMaximized(
2815
2773
  outerListId ?? listId
2816
2774
  );
2817
- const options = [];
2818
- for (let i = 1; i <= numberPageCount; i++) {
2819
- options.push(i);
2820
- }
2821
- const [infoButtonRef, setInfoButtonRef] = React.useState(
2822
- null
2823
- );
2824
- const recordsCountLabel = `${window.GNR_TOT_RECORDS}: ${recordsCount}`;
2825
- const tooltipProps = React.useMemo(
2826
- () => ({
2827
- text: breakPoint <= 3 ? `${recordsCountLabel}.${!reachedMax && !hasMore ? "" : reachedMax && window.GNR_TOT_RECORDS_REACHED || hasMore && window.QUERY_MORE_DATA}` : `${!reachedMax && !hasMore ? "" : reachedMax && window.GNR_TOT_RECORDS_REACHED || hasMore && window.QUERY_MORE_DATA}`,
2828
- attachToElement: { current: infoButtonRef },
2829
- closeOnClickOut: true
2830
- // closeOnClickOutChecker(element) {
2831
- // return !getSpecificParent(element, (current) =>
2832
- // current.classList.contains('pagination__information'),
2833
- // );
2834
- // },
2835
- }),
2836
- [breakPoint, hasMore, infoButtonRef, reachedMax, recordsCountLabel]
2837
- );
2838
- return /* @__PURE__ */ jsxs(
2839
- Box,
2840
- {
2841
- as: "nav",
2842
- variant: `layout.common.components.pagination.${variant}`,
2843
- "aria-label": getLabel("lblQryParamPag").text,
2844
- className: `pagination ${numberPageCount <= 1 && !disableReduced ? "onlyRefresh" : ""} ${className ?? ""}`,
2845
- children: [
2846
- /* @__PURE__ */ jsxs(Box, { className: "pagination__leftToolbar", children: [
2847
- !hideMaximizeButton && (showMaximizeOnSmallBreakpoints || breakPoint > 4) && /* @__PURE__ */ jsx(
2848
- IconButton,
2849
- {
2850
- variant: "icon",
2851
- className: "pagination__fullScreenButton",
2852
- onClick: toggleIsMaximized.bind(toggleIsMaximized, void 0),
2853
- icon: !isMaximized ? "Maximize" : "Minimize",
2854
- title: !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2855
- "aria-label": !isMaximized ? window.LBL_MAXIMIZE : window.LBL_MINIMIZE,
2856
- iconSize: "Md"
2857
- }
2858
- ),
2859
- !hideInfo && /* @__PURE__ */ jsxs(Fragment, { children: [
2860
- ((reachedMax || hasMore) && breakPoint > 3 || breakPoint <= 3) && className !== "grid__pagination" ? /* @__PURE__ */ jsx(
2861
- IconButton,
2862
- {
2863
- variant: "icon-primary",
2864
- icon: "Info",
2865
- className: `pagination__information ${reachedMax || hasMore ? "pagination__alertInfo" : ""}`,
2866
- onClick: () => ApiaUtil.instance.tooltips.open(tooltipProps),
2867
- ref: setInfoButtonRef,
2868
- iconSize: "Md",
2869
- "aria-label": window.BTN_FILE_INFO_TOOLTIP,
2870
- title: window.BTN_FILE_INFO_TOOLTIP
2871
- }
2872
- ) : "",
2873
- breakPoint > 3 && /* @__PURE__ */ jsx(
2874
- Box,
2875
- {
2876
- as: "span",
2877
- className: "recordsCounter pagination__deleteLabels",
2878
- title: recordsCountLabel,
2879
- children: recordsCount !== -1 && `${window.GNR_TOT_RECORDS}: ${recordsCount} `
2880
- }
2881
- )
2882
- ] })
2883
- ] }),
2884
- /* @__PURE__ */ jsx(Box, { className: "pagination__controls", children: (numberPageCount > 0 || disableReduced) && /* @__PURE__ */ jsxs(Fragment, { children: [
2885
- breakPoint > 2 && /* @__PURE__ */ jsx(
2886
- IconButton,
2887
- {
2888
- variant: "icon-primary",
2889
- disabled: disabled || internCurrentPage === 1 || isLoading || isPerforming,
2890
- "aria-label": window.NAV_FIRST_PAGE,
2891
- type: "button",
2892
- onClick: () => {
2893
- setCurrentAndDispatch(1);
2894
- },
2895
- icon: "First",
2896
- iconSize: "Sm"
2897
- }
2898
- ),
2899
- /* @__PURE__ */ jsx(
2900
- IconButton,
2901
- {
2902
- variant: "icon-primary",
2903
- disabled: disabled || internCurrentPage <= 1 || isLoading || isPerforming,
2904
- "aria-label": window.NAV_PREVIOUS_PAGE,
2905
- type: "button",
2906
- onClick: () => {
2907
- setCurrentAndDispatch(internCurrentPage - 1);
2908
- },
2909
- icon: "Previous",
2910
- iconSize: "Sm"
2911
- }
2912
- ),
2913
- breakPoint > 2 && /* @__PURE__ */ jsxs(Box, { className: "input", children: [
2914
- /* @__PURE__ */ jsx(
2915
- Input,
2916
- {
2917
- className: "pagination__controls__input",
2918
- "aria-label": window.NAV_INPUT_LABEL,
2919
- title: `${window.PAGE}: ${internCurrentPage} `,
2920
- ref: InputRef,
2921
- value: hasNoValue ? "" : internCurrentPage,
2922
- onKeyDown: (ev) => {
2923
- const regex = /([0-9])|(Backspace)|(Tab)/;
2924
- if (!ev.key.match(regex)) {
2925
- ev.stopPropagation();
2926
- ev.preventDefault();
2927
- }
2928
- if (ev.key === "Enter") {
2929
- ev.stopPropagation();
2930
- ev.preventDefault();
2931
- setCurrentAndDispatch(internCurrentPage);
2932
- }
2933
- },
2934
- onBlur: () => {
2935
- if (lastEmittedPage !== internCurrentPage) {
2936
- setCurrentAndDispatch(internCurrentPage);
2937
- }
2938
- },
2939
- onFocus: (ev) => {
2940
- ev.currentTarget.select();
2941
- },
2942
- onChange: (ev) => {
2943
- setHasNoValue(ev.target.value === "");
2944
- setCurrentPage(
2945
- Math.max(
2946
- 1,
2947
- Math.min(
2948
- noNaN(Number(ev.currentTarget.value)),
2949
- pageCount
2950
- )
2951
- )
2952
- );
2953
- },
2954
- disabled: disabled || isLoading || isPerforming
2955
- }
2956
- ),
2957
- " ",
2958
- "/",
2959
- " ",
2960
- /* @__PURE__ */ jsx(
2961
- Box,
2962
- {
2963
- as: "span",
2964
- title: recordsCount !== -1 ? `${window.GNR_TOT_RECORDS} ${recordsCount}` : window.NAV_INPUT_LABEL,
2965
- children: pageCount
2966
- }
2967
- )
2968
- ] }),
2969
- breakPoint <= 2 && /* @__PURE__ */ jsxs(
2970
- Select,
2971
- {
2972
- className: "pagination__selectPage",
2973
- value: internCurrentPage,
2974
- onChange: (e) => {
2975
- setCurrentAndDispatch(Number(e.target.value));
2976
- },
2977
- children: [
2978
- /* @__PURE__ */ jsxs("option", { disabled: true, children: [
2979
- "Total: ",
2980
- numberPageCount
2981
- ] }),
2982
- options.map((current) => {
2983
- return /* @__PURE__ */ jsx("option", { children: current }, current);
2984
- })
2985
- ]
2986
- }
2987
- ),
2988
- /* @__PURE__ */ jsx(
2989
- IconButton,
2990
- {
2991
- variant: "icon-primary",
2992
- disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
2993
- "aria-label": window.NAV_NEXT_PAGE,
2994
- type: "button",
2995
- onClick: () => {
2996
- setCurrentAndDispatch(internCurrentPage + 1);
2997
- },
2998
- icon: "Next",
2999
- iconSize: "Sm"
3000
- }
3001
- ),
3002
- breakPoint > 2 && /* @__PURE__ */ jsx(
3003
- IconButton,
3004
- {
3005
- variant: "icon-primary",
3006
- type: "button",
3007
- "aria-label": window.NAV_LAST_PAGE,
3008
- disabled: disabled || internCurrentPage >= numberPageCount || isLoading || isPerforming,
3009
- onClick: () => {
3010
- setCurrentAndDispatch(numberPageCount);
3011
- },
3012
- icon: "Last",
3013
- iconSize: "Sm"
3014
- }
3015
- )
3016
- ] }) }),
3017
- /* @__PURE__ */ jsx(Box, { className: "pagination__rightToolbar", children: (!hideRefreshButton || onDeleteFilters) && /* @__PURE__ */ jsxs(Fragment, { children: [
3018
- onDeleteFilters && /* @__PURE__ */ jsxs(
3019
- SimpleButton,
3020
- {
3021
- disabled: isPerforming,
3022
- className: "pagination__deleteFiltersButton",
3023
- onClick: onDeleteFilters,
3024
- children: [
3025
- breakPoint > 3 && /* @__PURE__ */ jsx(Box, { as: "span", className: "pagination__deleteLabels", children: window.BTN_DELETE_FILTERS }),
3026
- /* @__PURE__ */ jsx(
3027
- Box,
3028
- {
3029
- as: "span",
3030
- className: `pagination__appliedFiltersLabel ${areAllFiltersApplied ? "" : "withFilters"}`,
3031
- children: appliedFilters
3032
- }
3033
- )
3034
- ]
3035
- }
3036
- ),
3037
- !hideRefreshButton && /* @__PURE__ */ jsx(
3038
- IconButton,
3039
- {
3040
- "aria-label": window.NAV_REFRESH,
3041
- onClick: () => onRefresh(numberCurrentPage),
3042
- icon: "Refresh",
3043
- iconSize: "Md",
3044
- disabled: disabled || isLoading,
3045
- variant: "icon-primary",
3046
- isLoading: isPerforming,
3047
- className: "pagiantion__refreshIcon"
3048
- }
3049
- )
3050
- ] }) })
3051
- ]
3052
- }
3053
- );
2775
+ return /* @__PURE__ */ jsx(Pagination$1, { ...{ ...props, isMaximized, onMaximize: toggleIsMaximized } });
3054
2776
  };
3055
2777
  const Pagination = React.memo(NoMemoPagination);
3056
2778