@flipdish/ui-library 0.70.0 → 0.72.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/README.md +1 -1
- package/dist/components/__internal__/controlFill/controlFill.context.cjs +13 -0
- package/dist/components/__internal__/controlFill/controlFill.context.cjs.map +1 -0
- package/dist/components/__internal__/controlFill/controlFill.context.d.ts +7 -0
- package/dist/components/__internal__/controlFill/controlFill.context.d.ts.map +1 -0
- package/dist/components/__internal__/controlFill/controlFill.context.js +11 -0
- package/dist/components/__internal__/controlFill/controlFill.context.js.map +1 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.cjs +13 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.cjs.map +1 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.d.ts +8 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.d.ts.map +1 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.js +11 -0
- package/dist/components/__internal__/focusHandOff/focusHandOff.context.js.map +1 -0
- package/dist/components/atoms/Buttons/IconButton/IconButton.cjs +1 -1
- package/dist/components/atoms/Buttons/IconButton/IconButton.cjs.map +1 -1
- package/dist/components/atoms/Buttons/IconButton/IconButton.d.ts.map +1 -1
- package/dist/components/atoms/Buttons/IconButton/IconButton.js +1 -1
- package/dist/components/atoms/Buttons/IconButton/IconButton.js.map +1 -1
- package/dist/components/molecules/EmptyState/index.cjs +9 -1
- package/dist/components/molecules/EmptyState/index.cjs.map +1 -1
- package/dist/components/molecules/EmptyState/index.d.ts.map +1 -1
- package/dist/components/molecules/EmptyState/index.js +11 -3
- package/dist/components/molecules/EmptyState/index.js.map +1 -1
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.cjs +13 -0
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.cjs.map +1 -1
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.d.ts +8 -0
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.d.ts.map +1 -1
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.js +13 -1
- package/dist/components/molecules/EmptyState/utilities/emptyState.utils.js.map +1 -1
- package/dist/components/molecules/Modals/Modal/Modal.cjs +6 -5
- package/dist/components/molecules/Modals/Modal/Modal.cjs.map +1 -1
- package/dist/components/molecules/Modals/Modal/Modal.d.ts.map +1 -1
- package/dist/components/molecules/Modals/Modal/Modal.js +6 -5
- package/dist/components/molecules/Modals/Modal/Modal.js.map +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js +1 -1
- package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs +4 -1
- package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs.map +1 -1
- package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.d.ts.map +1 -1
- package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js +5 -2
- package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.cjs +11 -6
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.cjs.map +1 -1
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.d.ts +4 -2
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.d.ts.map +1 -1
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.js +12 -7
- package/dist/components/organisms/FilterBar/components/FilterDropdownMenu.js.map +1 -1
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.cjs +53 -0
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.cjs.map +1 -0
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.d.ts +41 -0
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.d.ts.map +1 -0
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.js +51 -0
- package/dist/components/organisms/FilterBar/hooks/useFilterDraft.js.map +1 -0
- package/dist/components/organisms/FilterBar/index.cjs +19 -7
- package/dist/components/organisms/FilterBar/index.cjs.map +1 -1
- package/dist/components/organisms/FilterBar/index.d.ts +1 -0
- package/dist/components/organisms/FilterBar/index.d.ts.map +1 -1
- package/dist/components/organisms/FilterBar/index.js +18 -7
- package/dist/components/organisms/FilterBar/index.js.map +1 -1
- package/dist/components/organisms/SlideoutMenu/index.cjs +3 -1
- package/dist/components/organisms/SlideoutMenu/index.cjs.map +1 -1
- package/dist/components/organisms/SlideoutMenu/index.d.ts.map +1 -1
- package/dist/components/organisms/SlideoutMenu/index.js +3 -1
- package/dist/components/organisms/SlideoutMenu/index.js.map +1 -1
- package/dist/components/organisms/Table/index.cjs +14 -285
- package/dist/components/organisms/Table/index.cjs.map +1 -1
- package/dist/components/organisms/Table/index.d.ts +29 -138
- package/dist/components/organisms/Table/index.d.ts.map +1 -1
- package/dist/components/organisms/Table/index.js +13 -284
- package/dist/components/organisms/Table/index.js.map +1 -1
- package/dist/components/organisms/Tables/Table/Table.cjs +305 -0
- package/dist/components/organisms/Tables/Table/Table.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/Table.d.ts +146 -0
- package/dist/components/organisms/Tables/Table/Table.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/Table.js +301 -0
- package/dist/components/organisms/Tables/Table/Table.js.map +1 -0
- package/dist/components/organisms/Tables/Table/Table.styles.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/Table.styles.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/Table.styles.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/Table.styles.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardList.cjs +2 -2
- package/dist/components/organisms/Tables/Table/components/TableCardList.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardList.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/components/TableCardList.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardList.js +2 -2
- package/dist/components/organisms/Tables/Table/components/TableCardList.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardRow.cjs +8 -4
- package/dist/components/organisms/Tables/Table/components/TableCardRow.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardRow.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/components/TableCardRow.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableCardRow.js +9 -5
- package/dist/components/organisms/Tables/Table/components/TableCardRow.js.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableCardsSelectAll.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableCardsSelectAll.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableCardsSelectAll.js.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.cjs +17 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.d.ts +5 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.js +15 -0
- package/dist/components/organisms/Tables/Table/components/TableEmptyState.js.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableFallbackCard.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableFallbackCard.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/components/TableFallbackCard.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableFallbackCard.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableRowCard.cjs +3 -3
- package/dist/components/organisms/Tables/Table/components/TableRowCard.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableRowCard.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/components/TableRowCard.js +3 -3
- package/dist/components/organisms/Tables/Table/components/TableRowCard.js.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableSortIcon.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableSortIcon.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/components/TableSortIcon.js.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useBusyCount.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useBusyCount.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useBusyCount.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useFirstSortDirection.cjs +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useFirstSortDirection.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useFirstSortDirection.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useFirstSortDirection.js +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useFirstSortDirection.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useIsPlaceholderPage.cjs +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useIsPlaceholderPage.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useIsPlaceholderPage.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useIsPlaceholderPage.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useIsPlaceholderPage.js +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useIsPlaceholderPage.js.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/usePlaceholderRows.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/usePlaceholderRows.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/hooks/usePlaceholderRows.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/usePlaceholderRows.js.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useSelectableRowRegistry.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useSelectableRowRegistry.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useSelectableRowRegistry.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useSelectableRowRegistry.js.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.cjs +83 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.d.ts +23 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.js +81 -0
- package/dist/components/organisms/Tables/Table/hooks/useTableFocusHandOff.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useTableSelection.cjs +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useTableSelection.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useTableSelection.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useTableSelection.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/hooks/useTableSelection.js +1 -1
- package/dist/components/organisms/Tables/Table/hooks/useTableSelection.js.map +1 -0
- package/dist/components/organisms/Tables/Table/providers/Table.context.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/providers/Table.context.d.ts +4 -1
- package/dist/components/organisms/Tables/Table/providers/Table.context.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/providers/Table.context.js.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.cjs +55 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.d.ts +25 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.js +51 -0
- package/dist/components/organisms/Tables/Table/utilities/tableFocusHandOff.utils.js.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/utilities/tableLoading.utils.cjs +1 -1
- package/dist/components/organisms/Tables/Table/utilities/tableLoading.utils.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/utilities/tableLoading.utils.d.ts +1 -1
- package/dist/components/organisms/Tables/Table/utilities/tableLoading.utils.d.ts.map +1 -0
- package/dist/components/organisms/{Table → Tables/Table}/utilities/tableLoading.utils.js +1 -1
- package/dist/components/organisms/Tables/Table/utilities/tableLoading.utils.js.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableSelection.utils.cjs.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableSelection.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/Table/utilities/tableSelection.utils.js.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.cjs +34 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.cjs.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.d.ts +37 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.d.ts.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.js +32 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/TableLayoutToggle.js.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.cjs +32 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.cjs.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.d.ts +21 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.d.ts.map +1 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.js +30 -0
- package/dist/components/organisms/Tables/TableLayoutToggle/hooks/useTableLayoutToggle.js.map +1 -0
- package/dist/components/organisms/{Table/components → Tables/TableSortMenu}/TableSortMenu.cjs +9 -2
- package/dist/components/organisms/Tables/TableSortMenu/TableSortMenu.cjs.map +1 -0
- package/dist/components/organisms/{Table/components → Tables/TableSortMenu}/TableSortMenu.d.ts +18 -6
- package/dist/components/organisms/Tables/TableSortMenu/TableSortMenu.d.ts.map +1 -0
- package/dist/components/organisms/{Table/components → Tables/TableSortMenu}/TableSortMenu.js +9 -2
- package/dist/components/organisms/Tables/TableSortMenu/TableSortMenu.js.map +1 -0
- package/dist/components/organisms/Tables/hooks/useIsAtLeastMd.cjs.map +1 -0
- package/dist/components/organisms/Tables/hooks/useIsAtLeastMd.d.ts.map +1 -0
- package/dist/components/organisms/Tables/hooks/useIsAtLeastMd.js.map +1 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.cjs +84 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.cjs.map +1 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.d.ts +20 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.d.ts.map +1 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.js +81 -0
- package/dist/components/organisms/Tables/hooks/useStoredTableLayout.js.map +1 -0
- package/dist/components/organisms/Tables/index.cjs +14 -0
- package/dist/components/organisms/Tables/index.cjs.map +1 -0
- package/dist/components/organisms/Tables/index.d.ts +19 -0
- package/dist/components/organisms/Tables/index.d.ts.map +1 -0
- package/dist/components/organisms/Tables/index.js +4 -0
- package/dist/components/organisms/Tables/index.js.map +1 -0
- package/dist/components/organisms/{Table/table.types.d.ts → Tables/tables.types.d.ts} +4 -2
- package/dist/components/organisms/Tables/tables.types.d.ts.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableCard.utils.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables}/utilities/tableCard.utils.d.ts +1 -1
- package/dist/components/organisms/Tables/utilities/tableCard.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableCard.utils.js.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableChildren.utils.cjs.map +1 -0
- package/dist/components/organisms/{Table → Tables}/utilities/tableChildren.utils.d.ts +1 -1
- package/dist/components/organisms/Tables/utilities/tableChildren.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableChildren.utils.js.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableIterable.utils.cjs.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableIterable.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableIterable.utils.js.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableSort.utils.cjs.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableSort.utils.d.ts.map +1 -0
- package/dist/components/organisms/Tables/utilities/tableSort.utils.js.map +1 -0
- package/dist/hooks/{useFocusHandOff/index.cjs → __internal__/useFocusHandOff/useFocusHandOff.cjs} +2 -2
- package/dist/hooks/__internal__/useFocusHandOff/useFocusHandOff.cjs.map +1 -0
- package/dist/hooks/{useFocusHandOff/index.d.ts → __internal__/useFocusHandOff/useFocusHandOff.d.ts} +1 -1
- package/dist/hooks/__internal__/useFocusHandOff/useFocusHandOff.d.ts.map +1 -0
- package/dist/hooks/{useFocusHandOff/index.js → __internal__/useFocusHandOff/useFocusHandOff.js} +2 -2
- package/dist/hooks/__internal__/useFocusHandOff/useFocusHandOff.js.map +1 -0
- package/dist/hooks/useFocusAfterRetry/index.cjs +2 -2
- package/dist/hooks/useFocusAfterRetry/index.d.ts +1 -1
- package/dist/hooks/useFocusAfterRetry/index.js +2 -2
- package/dist/hooks/useListQueryParams/index.cjs +238 -0
- package/dist/hooks/useListQueryParams/index.cjs.map +1 -0
- package/dist/hooks/useListQueryParams/index.d.ts +77 -0
- package/dist/hooks/useListQueryParams/index.d.ts.map +1 -0
- package/dist/hooks/useListQueryParams/index.js +236 -0
- package/dist/hooks/useListQueryParams/index.js.map +1 -0
- package/dist/hooks/useLoadState/index.cjs +69 -0
- package/dist/hooks/useLoadState/index.cjs.map +1 -0
- package/dist/hooks/useLoadState/index.d.ts +44 -0
- package/dist/hooks/useLoadState/index.d.ts.map +1 -0
- package/dist/hooks/useLoadState/index.js +67 -0
- package/dist/hooks/useLoadState/index.js.map +1 -0
- package/dist/hooks/usePagedList/index.cjs +61 -0
- package/dist/hooks/usePagedList/index.cjs.map +1 -0
- package/dist/hooks/usePagedList/index.d.ts +56 -0
- package/dist/hooks/usePagedList/index.d.ts.map +1 -0
- package/dist/hooks/usePagedList/index.js +59 -0
- package/dist/hooks/usePagedList/index.js.map +1 -0
- package/dist/native/{hooks/useFocusHandOff → components/organisms/Tables}/index.d.ts +3 -3
- package/dist/native/hooks/useListQueryParams/index.d.ts +12 -0
- package/dist/native/hooks/useLoadState/index.d.ts +12 -0
- package/dist/native/hooks/usePagedList/index.d.ts +12 -0
- package/dist/native/utilities/listQueryUtils/index.d.ts +12 -0
- package/dist/styles.css +3 -3
- package/dist/utilities/__internal__/listStateUtils/listState.utils.cjs +47 -0
- package/dist/utilities/__internal__/listStateUtils/listState.utils.cjs.map +1 -0
- package/dist/utilities/__internal__/listStateUtils/listState.utils.d.ts +51 -0
- package/dist/utilities/__internal__/listStateUtils/listState.utils.d.ts.map +1 -0
- package/dist/utilities/__internal__/listStateUtils/listState.utils.js +43 -0
- package/dist/utilities/__internal__/listStateUtils/listState.utils.js.map +1 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.cjs +67 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.cjs.map +1 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.d.ts +27 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.d.ts.map +1 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.js +64 -0
- package/dist/utilities/__internal__/stableKeyUtils/stableKey.utils.js.map +1 -0
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.cjs +28 -0
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.cjs.map +1 -1
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.d.ts +10 -0
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.d.ts.map +1 -1
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.js +28 -1
- package/dist/utilities/__internal__/webStorageUtils/webStorage.utils.js.map +1 -1
- package/dist/utilities/listQueryUtils/index.cjs +59 -0
- package/dist/utilities/listQueryUtils/index.cjs.map +1 -0
- package/dist/utilities/listQueryUtils/index.d.ts +46 -0
- package/dist/utilities/listQueryUtils/index.d.ts.map +1 -0
- package/dist/utilities/listQueryUtils/index.js +55 -0
- package/dist/utilities/listQueryUtils/index.js.map +1 -0
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.cjs +2 -0
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.cjs.map +1 -1
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.d.ts +2 -0
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.d.ts.map +1 -1
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.js +2 -0
- package/dist/utilities/localStorageUtils/localStorageUtils.constants.js.map +1 -1
- package/package.json +3 -3
- package/dist/components/organisms/Table/Table.styles.cjs.map +0 -1
- package/dist/components/organisms/Table/Table.styles.d.ts.map +0 -1
- package/dist/components/organisms/Table/Table.styles.js.map +0 -1
- package/dist/components/organisms/Table/components/TableCardList.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableCardList.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableCardList.js.map +0 -1
- package/dist/components/organisms/Table/components/TableCardRow.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableCardRow.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableCardRow.js.map +0 -1
- package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableCardsSelectAll.js.map +0 -1
- package/dist/components/organisms/Table/components/TableFallbackCard.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableFallbackCard.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableFallbackCard.js.map +0 -1
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs +0 -27
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts +0 -17
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableLayoutToggle.js +0 -25
- package/dist/components/organisms/Table/components/TableLayoutToggle.js.map +0 -1
- package/dist/components/organisms/Table/components/TableRowCard.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableRowCard.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableRowCard.js.map +0 -1
- package/dist/components/organisms/Table/components/TableSortIcon.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableSortIcon.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableSortIcon.js.map +0 -1
- package/dist/components/organisms/Table/components/TableSortMenu.cjs.map +0 -1
- package/dist/components/organisms/Table/components/TableSortMenu.d.ts.map +0 -1
- package/dist/components/organisms/Table/components/TableSortMenu.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useBusyCount.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useBusyCount.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useBusyCount.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsPlaceholderPage.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsPlaceholderPage.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useIsPlaceholderPage.js.map +0 -1
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js.map +0 -1
- package/dist/components/organisms/Table/hooks/useTableSelection.cjs.map +0 -1
- package/dist/components/organisms/Table/hooks/useTableSelection.d.ts.map +0 -1
- package/dist/components/organisms/Table/hooks/useTableSelection.js.map +0 -1
- package/dist/components/organisms/Table/providers/Table.context.cjs.map +0 -1
- package/dist/components/organisms/Table/providers/Table.context.d.ts.map +0 -1
- package/dist/components/organisms/Table/providers/Table.context.js.map +0 -1
- package/dist/components/organisms/Table/table.types.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableCard.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableCard.utils.js.map +0 -1
- package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableChildren.utils.js.map +0 -1
- package/dist/components/organisms/Table/utilities/tableIterable.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableIterable.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableIterable.utils.js.map +0 -1
- package/dist/components/organisms/Table/utilities/tableLoading.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableLoading.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableLoading.utils.js.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSelection.utils.js.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSort.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/utilities/tableSort.utils.js.map +0 -1
- package/dist/hooks/useFocusHandOff/index.cjs.map +0 -1
- package/dist/hooks/useFocusHandOff/index.d.ts.map +0 -1
- package/dist/hooks/useFocusHandOff/index.js.map +0 -1
- /package/dist/components/organisms/{Table → Tables/Table}/Table.styles.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/Table.styles.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableCardsSelectAll.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableCardsSelectAll.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableCardsSelectAll.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableFallbackCard.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableFallbackCard.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableRowCard.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableSortIcon.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableSortIcon.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/components/TableSortIcon.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useBusyCount.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useBusyCount.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useBusyCount.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useFirstSortDirection.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/usePlaceholderRows.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/usePlaceholderRows.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useSelectableRowRegistry.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/hooks/useSelectableRowRegistry.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/providers/Table.context.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/providers/Table.context.js +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/utilities/tableSelection.utils.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/utilities/tableSelection.utils.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables/Table}/utilities/tableSelection.utils.js +0 -0
- /package/dist/components/organisms/{Table → Tables}/hooks/useIsAtLeastMd.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables}/hooks/useIsAtLeastMd.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables}/hooks/useIsAtLeastMd.js +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableCard.utils.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableCard.utils.js +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableChildren.utils.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableChildren.utils.js +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableIterable.utils.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableIterable.utils.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableIterable.utils.js +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableSort.utils.cjs +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableSort.utils.d.ts +0 -0
- /package/dist/components/organisms/{Table → Tables}/utilities/tableSort.utils.js +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var listState_utils = require('../../utilities/__internal__/listStateUtils/listState.utils.cjs');
|
|
5
|
+
|
|
6
|
+
// Counted per key, so overlapping retries on one key hold it until the last of them settles.
|
|
7
|
+
const withRetryCount = (counts, key, change) => {
|
|
8
|
+
const next = new Map(counts);
|
|
9
|
+
const count = (counts.get(key) ?? 0) + change;
|
|
10
|
+
if (count > 0)
|
|
11
|
+
next.set(key, count);
|
|
12
|
+
else
|
|
13
|
+
next.delete(key);
|
|
14
|
+
return next;
|
|
15
|
+
};
|
|
16
|
+
const ignoreRejection = () => { };
|
|
17
|
+
const isPromiseLike = (value) => typeof value?.then === 'function';
|
|
18
|
+
/**
|
|
19
|
+
* Decides what a request shows, loading, stand-in data, an error or the data, and keeps a failed request's error on screen
|
|
20
|
+
* while its retry runs. TanStack Query drops the error as soon as the query fetches again, so whether a retry is running
|
|
21
|
+
* cannot be read back from the query; use it for a single record, and through `usePagedList` for a list.
|
|
22
|
+
*
|
|
23
|
+
* @param options The request's key and state as the data library reports it, and its `refetch`; see `UseLoadStateOptions`.
|
|
24
|
+
* @returns At most one of `isLoading`, `isSearching` and `isError`, with `showData`, which is `false` while the error shows, so
|
|
25
|
+
* a failed refetch's cached data and stand-in data stay hidden until a retry succeeds; `isRetrying` while a retry pressed on
|
|
26
|
+
* the current key's error runs, during which `isError` stays `true`; and `retry`, which only refetches when the request is
|
|
27
|
+
* not in error. A refetch on returning to a key that failed earlier is a load, not a retry, and a retry left running behind
|
|
28
|
+
* another key is still one when its key is shown again.
|
|
29
|
+
*/
|
|
30
|
+
const useLoadState = ({ key, isPending, isError, isPreviousData = false, refetch }) => {
|
|
31
|
+
const [retryCounts, setRetryCounts] = React.useState(() => new Map());
|
|
32
|
+
const isRetrying = retryCounts.has(key);
|
|
33
|
+
const state = listState_utils.loadStateOf({ isPending, isError, isPreviousData, isRetrying });
|
|
34
|
+
// A layout effect, so a press straight after the render that showed the error already reads it.
|
|
35
|
+
const latest = React.useRef({ key, refetch, isError: state.isError });
|
|
36
|
+
React.useLayoutEffect(() => {
|
|
37
|
+
latest.current = { key, refetch, isError: state.isError };
|
|
38
|
+
});
|
|
39
|
+
const retry = React.useCallback(() => {
|
|
40
|
+
const { key: retriedKey, refetch: run, isError: isInError } = latest.current;
|
|
41
|
+
// A refetch of a request that has not failed, such as a Refresh, must not show an error or hide the data.
|
|
42
|
+
if (!isInError) {
|
|
43
|
+
const refresh = run();
|
|
44
|
+
// The data library reports a failed refresh through `isError`; left unhandled, the rejection would reach the browser too.
|
|
45
|
+
if (isPromiseLike(refresh))
|
|
46
|
+
refresh.then(undefined, ignoreRejection);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const settle = () => setRetryCounts((counts) => withRetryCount(counts, retriedKey, -1));
|
|
50
|
+
setRetryCounts((counts) => withRetryCount(counts, retriedKey, 1));
|
|
51
|
+
let attempt;
|
|
52
|
+
try {
|
|
53
|
+
attempt = run();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// A refetch that throws started nothing, so the error must not hold behind a spinner that never ends.
|
|
57
|
+
settle();
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
if (isPromiseLike(attempt))
|
|
61
|
+
attempt.then(settle, settle);
|
|
62
|
+
else
|
|
63
|
+
settle();
|
|
64
|
+
}, []);
|
|
65
|
+
return { ...state, isRetrying, retry };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.useLoadState = useLoadState;
|
|
69
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/useLoadState/index.ts"],"sourcesContent":[null],"names":["useState","loadStateOf","useRef","useLayoutEffect","useCallback"],"mappings":";;;;;AAuCA;AACA,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAE,GAA+B,EAAE,MAAc,KAAiB;AAC3G,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC5B,IAAA,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM;IAC7C,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AACrB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,eAAe,GAAG,MAAK,EAAE,CAAC;AAEhC,MAAM,aAAa,GAAG,CAAC,KAAc,KAAoC,OAAQ,KAAqC,EAAE,IAAI,KAAK,UAAU;AAE3I;;;;;;;;;;;AAWG;AACI,MAAM,YAAY,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,GAAG,KAAK,EAAE,OAAO,EAAuB,KAAe;AAC3H,IAAA,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAGA,cAAQ,CAAc,MAAM,IAAI,GAAG,EAAE,CAAC;IAC5E,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;AACvC,IAAA,MAAM,KAAK,GAAGC,2BAAW,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC;;AAG7E,IAAA,MAAM,MAAM,GAAGC,YAAM,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/DC,qBAAe,CAAC,MAAK;AACnB,QAAA,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;AAC3D,IAAA,CAAC,CAAC;AAEF,IAAA,MAAM,KAAK,GAAGC,iBAAW,CAAC,MAAK;AAC7B,QAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,OAAO;;QAE5E,IAAI,CAAC,SAAS,EAAE;AACd,YAAA,MAAM,OAAO,GAAG,GAAG,EAAE;;YAErB,IAAI,aAAa,CAAC,OAAO,CAAC;AAAE,gBAAA,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC;YACpE;QACF;QACA,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AACvF,QAAA,cAAc,CAAC,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;AACjE,QAAA,IAAI,OAAgB;AACpB,QAAA,IAAI;YACF,OAAO,GAAG,GAAG,EAAE;QACjB;QAAE,OAAO,KAAK,EAAE;;AAEd,YAAA,MAAM,EAAE;AACR,YAAA,MAAM,KAAK;QACb;QACA,IAAI,aAAa,CAAC,OAAO,CAAC;AAAE,YAAA,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;;AACnD,YAAA,MAAM,EAAE;IACf,CAAC,EAAE,EAAE,CAAC;IAEN,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE;AACxC;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface UseLoadStateOptions {
|
|
2
|
+
/** Names the request on screen, such as a record's id or a list query's stable key; each `retry` is tracked under its key. */
|
|
3
|
+
key: string | number | null;
|
|
4
|
+
/** The request has no data yet, as TanStack Query's `isPending`. */
|
|
5
|
+
isPending: boolean;
|
|
6
|
+
/** The request failed. */
|
|
7
|
+
isError: boolean;
|
|
8
|
+
/** The previous request's data is standing in while this one lands, as TanStack Query's `isPlaceholderData`. */
|
|
9
|
+
isPreviousData?: boolean;
|
|
10
|
+
/** Starts the request again. A returned promise ends the retry when it settles; anything else ends it at once. */
|
|
11
|
+
refetch: () => unknown;
|
|
12
|
+
}
|
|
13
|
+
/** What `useLoadState` reports a request shows, and its retry. */
|
|
14
|
+
export interface LoadState {
|
|
15
|
+
/** Nothing to show yet: draw the loading state. */
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
/** The previous request's data stands in while this one lands, as for a search. */
|
|
18
|
+
isSearching: boolean;
|
|
19
|
+
/** Show the error and its retry button; it wins over the rest, and stays `true` while a retry runs. */
|
|
20
|
+
isError: boolean;
|
|
21
|
+
/** The data may be drawn; `false` while the error shows, so a failed refetch's cached data stays hidden behind it. */
|
|
22
|
+
showData: boolean;
|
|
23
|
+
/** A `retry` pressed on the current request's error has not settled; the error, and the spinner on its button, hold until it does. */
|
|
24
|
+
isRetrying: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Runs `refetch` for the current request. While it is in error, the retry is tracked until it settles; otherwise, as for a
|
|
27
|
+
* Refresh control, it only refetches. The same function on every render.
|
|
28
|
+
*/
|
|
29
|
+
retry: () => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decides what a request shows, loading, stand-in data, an error or the data, and keeps a failed request's error on screen
|
|
33
|
+
* while its retry runs. TanStack Query drops the error as soon as the query fetches again, so whether a retry is running
|
|
34
|
+
* cannot be read back from the query; use it for a single record, and through `usePagedList` for a list.
|
|
35
|
+
*
|
|
36
|
+
* @param options The request's key and state as the data library reports it, and its `refetch`; see `UseLoadStateOptions`.
|
|
37
|
+
* @returns At most one of `isLoading`, `isSearching` and `isError`, with `showData`, which is `false` while the error shows, so
|
|
38
|
+
* a failed refetch's cached data and stand-in data stay hidden until a retry succeeds; `isRetrying` while a retry pressed on
|
|
39
|
+
* the current key's error runs, during which `isError` stays `true`; and `retry`, which only refetches when the request is
|
|
40
|
+
* not in error. A refetch on returning to a key that failed earlier is a load, not a retry, and a retry left running behind
|
|
41
|
+
* another key is still one when its key is shown again.
|
|
42
|
+
*/
|
|
43
|
+
export declare const useLoadState: ({ key, isPending, isError, isPreviousData, refetch }: UseLoadStateOptions) => LoadState;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useLoadState/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,8HAA8H;IAC9H,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAC;IACnB,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,gHAAgH;IAChH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kHAAkH;IAClH,OAAO,EAAE,MAAM,OAAO,CAAC;CACxB;AAED,kEAAkE;AAClE,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,mFAAmF;IACnF,WAAW,EAAE,OAAO,CAAC;IACrB,uGAAuG;IACvG,OAAO,EAAE,OAAO,CAAC;IACjB,sHAAsH;IACtH,QAAQ,EAAE,OAAO,CAAC;IAClB,sIAAsI;IACtI,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAiBD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GAAI,sDAA8D,mBAAmB,KAAG,SAmChH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState, useRef, useLayoutEffect, useCallback } from 'react';
|
|
2
|
+
import { loadStateOf } from '../../utilities/__internal__/listStateUtils/listState.utils.js';
|
|
3
|
+
|
|
4
|
+
// Counted per key, so overlapping retries on one key hold it until the last of them settles.
|
|
5
|
+
const withRetryCount = (counts, key, change) => {
|
|
6
|
+
const next = new Map(counts);
|
|
7
|
+
const count = (counts.get(key) ?? 0) + change;
|
|
8
|
+
if (count > 0)
|
|
9
|
+
next.set(key, count);
|
|
10
|
+
else
|
|
11
|
+
next.delete(key);
|
|
12
|
+
return next;
|
|
13
|
+
};
|
|
14
|
+
const ignoreRejection = () => { };
|
|
15
|
+
const isPromiseLike = (value) => typeof value?.then === 'function';
|
|
16
|
+
/**
|
|
17
|
+
* Decides what a request shows, loading, stand-in data, an error or the data, and keeps a failed request's error on screen
|
|
18
|
+
* while its retry runs. TanStack Query drops the error as soon as the query fetches again, so whether a retry is running
|
|
19
|
+
* cannot be read back from the query; use it for a single record, and through `usePagedList` for a list.
|
|
20
|
+
*
|
|
21
|
+
* @param options The request's key and state as the data library reports it, and its `refetch`; see `UseLoadStateOptions`.
|
|
22
|
+
* @returns At most one of `isLoading`, `isSearching` and `isError`, with `showData`, which is `false` while the error shows, so
|
|
23
|
+
* a failed refetch's cached data and stand-in data stay hidden until a retry succeeds; `isRetrying` while a retry pressed on
|
|
24
|
+
* the current key's error runs, during which `isError` stays `true`; and `retry`, which only refetches when the request is
|
|
25
|
+
* not in error. A refetch on returning to a key that failed earlier is a load, not a retry, and a retry left running behind
|
|
26
|
+
* another key is still one when its key is shown again.
|
|
27
|
+
*/
|
|
28
|
+
const useLoadState = ({ key, isPending, isError, isPreviousData = false, refetch }) => {
|
|
29
|
+
const [retryCounts, setRetryCounts] = useState(() => new Map());
|
|
30
|
+
const isRetrying = retryCounts.has(key);
|
|
31
|
+
const state = loadStateOf({ isPending, isError, isPreviousData, isRetrying });
|
|
32
|
+
// A layout effect, so a press straight after the render that showed the error already reads it.
|
|
33
|
+
const latest = useRef({ key, refetch, isError: state.isError });
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
latest.current = { key, refetch, isError: state.isError };
|
|
36
|
+
});
|
|
37
|
+
const retry = useCallback(() => {
|
|
38
|
+
const { key: retriedKey, refetch: run, isError: isInError } = latest.current;
|
|
39
|
+
// A refetch of a request that has not failed, such as a Refresh, must not show an error or hide the data.
|
|
40
|
+
if (!isInError) {
|
|
41
|
+
const refresh = run();
|
|
42
|
+
// The data library reports a failed refresh through `isError`; left unhandled, the rejection would reach the browser too.
|
|
43
|
+
if (isPromiseLike(refresh))
|
|
44
|
+
refresh.then(undefined, ignoreRejection);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const settle = () => setRetryCounts((counts) => withRetryCount(counts, retriedKey, -1));
|
|
48
|
+
setRetryCounts((counts) => withRetryCount(counts, retriedKey, 1));
|
|
49
|
+
let attempt;
|
|
50
|
+
try {
|
|
51
|
+
attempt = run();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// A refetch that throws started nothing, so the error must not hold behind a spinner that never ends.
|
|
55
|
+
settle();
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
if (isPromiseLike(attempt))
|
|
59
|
+
attempt.then(settle, settle);
|
|
60
|
+
else
|
|
61
|
+
settle();
|
|
62
|
+
}, []);
|
|
63
|
+
return { ...state, isRetrying, retry };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { useLoadState };
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/useLoadState/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAuCA;AACA,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAE,GAA+B,EAAE,MAAc,KAAiB;AAC3G,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC5B,IAAA,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM;IAC7C,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AACrB,IAAA,OAAO,IAAI;AACb,CAAC;AAED,MAAM,eAAe,GAAG,MAAK,EAAE,CAAC;AAEhC,MAAM,aAAa,GAAG,CAAC,KAAc,KAAoC,OAAQ,KAAqC,EAAE,IAAI,KAAK,UAAU;AAE3I;;;;;;;;;;;AAWG;AACI,MAAM,YAAY,GAAG,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,GAAG,KAAK,EAAE,OAAO,EAAuB,KAAe;AAC3H,IAAA,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAc,MAAM,IAAI,GAAG,EAAE,CAAC;IAC5E,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;AACvC,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC;;AAG7E,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/D,eAAe,CAAC,MAAK;AACnB,QAAA,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;AAC3D,IAAA,CAAC,CAAC;AAEF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,MAAK;AAC7B,QAAA,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,OAAO;;QAE5E,IAAI,CAAC,SAAS,EAAE;AACd,YAAA,MAAM,OAAO,GAAG,GAAG,EAAE;;YAErB,IAAI,aAAa,CAAC,OAAO,CAAC;AAAE,gBAAA,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC;YACpE;QACF;QACA,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AACvF,QAAA,cAAc,CAAC,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;AACjE,QAAA,IAAI,OAAgB;AACpB,QAAA,IAAI;YACF,OAAO,GAAG,GAAG,EAAE;QACjB;QAAE,OAAO,KAAK,EAAE;;AAEd,YAAA,MAAM,EAAE;AACR,YAAA,MAAM,KAAK;QACb;QACA,IAAI,aAAa,CAAC,OAAO,CAAC;AAAE,YAAA,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;;AACnD,YAAA,MAAM,EAAE;IACf,CAAC,EAAE,EAAE,CAAC;IAEN,OAAO,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE;AACxC;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var useLoadState = require('@flipdish/ui-library/hooks/useLoadState');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var listState_utils = require('../../utilities/__internal__/listStateUtils/listState.utils.cjs');
|
|
6
|
+
var stableKey_utils = require('../../utilities/__internal__/stableKeyUtils/stableKey.utils.cjs');
|
|
7
|
+
|
|
8
|
+
// One empty array for every render with nothing to draw, so `rows` keeps its identity while it stays empty.
|
|
9
|
+
const NO_ROWS = [];
|
|
10
|
+
/**
|
|
11
|
+
* Reports what a paged list shows, from the state of the request its page makes, which keeps its own `useQuery`. Use it for
|
|
12
|
+
* any list with a pager: it keeps the row total across page changes, holds a failed load's error through its retry, and
|
|
13
|
+
* names the query on screen for the status region that announces it.
|
|
14
|
+
*
|
|
15
|
+
* @param options The page's query, its rows and total, the request's state as the data library reports it, and its `refetch`;
|
|
16
|
+
* see `UsePagedListOptions`.
|
|
17
|
+
* @returns The `rows` to draw, `[]` while there is nothing to show or the error shows, as it does for a failed refetch whose
|
|
18
|
+
* rows are cached; `total` and `totalPages`, which stay through a page or rows-per-page change and an error, and are unknown
|
|
19
|
+
* again once anything else changes; the load state of `useLoadState`; `resultKey`, which changes as another query's result
|
|
20
|
+
* lands and with each failed attempt, but not for a refresh of the same query; `isPastEnd` for a link to a page past the
|
|
21
|
+
* last; and `loadingRowCount`, so a short last page does not load taller than it lands.
|
|
22
|
+
*/
|
|
23
|
+
const usePagedList = ({ query, rows, total, isPending, isError, isPreviousData = false, errorCount = 0, refetch, }) => {
|
|
24
|
+
const key = stableKey_utils.stableKeyOf(query);
|
|
25
|
+
const { showData, ...state } = useLoadState.useLoadState({ key, isPending, isError, isPreviousData, refetch });
|
|
26
|
+
// Rows standing in from the previous request belong to its result set, so neither their total nor their key is kept.
|
|
27
|
+
const hasLanded = rows !== undefined && !isPreviousData;
|
|
28
|
+
// Kept per result set, so the pager stays through a page change but never offers pages a new search or filter may not have.
|
|
29
|
+
const resultSet = listState_utils.resultSetKeyOf(query);
|
|
30
|
+
// A `NaN` total, as from `Number()` of a missing header, never equals the kept one and would set state on every render.
|
|
31
|
+
const landedTotal = hasLanded && Number.isFinite(total) ? total : undefined;
|
|
32
|
+
const [kept, setKept] = React.useState();
|
|
33
|
+
if (landedTotal !== undefined && (kept?.resultSet !== resultSet || kept.total !== landedTotal))
|
|
34
|
+
setKept({ resultSet, total: landedTotal });
|
|
35
|
+
const knownTotal = landedTotal ?? (kept?.resultSet === resultSet ? kept.total : undefined);
|
|
36
|
+
const totalPages = listState_utils.pageCountOf(knownTotal, query.pageSize);
|
|
37
|
+
// Keyed by query, not by response: a background refetch landing new rows for the same query must not be announced again.
|
|
38
|
+
const shownResult = hasLanded ? key : undefined;
|
|
39
|
+
const [landedResult, setLandedResult] = React.useState();
|
|
40
|
+
if (shownResult !== undefined && shownResult !== landedResult)
|
|
41
|
+
setLandedResult(shownResult);
|
|
42
|
+
// A failed attempt gets a key of its own, so a retry that fails again is announced although the words are the same.
|
|
43
|
+
const resultKey = state.isError ? `${key} failed ${errorCount}` : (shownResult ?? landedResult);
|
|
44
|
+
const shownRows = showData ? (rows ?? NO_ROWS) : NO_ROWS;
|
|
45
|
+
const isSettled = !state.isLoading && !state.isSearching && !state.isError;
|
|
46
|
+
const isPastEnd = isSettled && hasLanded && shownRows.length === 0 && knownTotal !== undefined && knownTotal > 0 && query.page > totalPages;
|
|
47
|
+
const rowsBeforePage = (query.page - 1) * query.pageSize;
|
|
48
|
+
const rowsOnPage = knownTotal === undefined ? 0 : Math.min(knownTotal - rowsBeforePage, query.pageSize);
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
rows: shownRows,
|
|
52
|
+
total: knownTotal,
|
|
53
|
+
totalPages,
|
|
54
|
+
resultKey,
|
|
55
|
+
isPastEnd,
|
|
56
|
+
loadingRowCount: rowsOnPage > 0 ? rowsOnPage : query.pageSize,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.usePagedList = usePagedList;
|
|
61
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/usePagedList/index.ts"],"sourcesContent":[null],"names":["stableKeyOf","useLoadState","resultSetKeyOf","useState","pageCountOf"],"mappings":";;;;;;;AAkDA;AACA,MAAM,OAAO,GAAqB,EAAE;AAEpC;;;;;;;;;;;;AAYG;AACI,MAAM,YAAY,GAAG,CAAqD,EAC/E,KAAK,EACL,IAAI,EACJ,KAAK,EACL,SAAS,EACT,OAAO,EACP,cAAc,GAAG,KAAK,EACtB,UAAU,GAAG,CAAC,EACd,OAAO,GACyB,KAAyB;AACzD,IAAA,MAAM,GAAG,GAAGA,2BAAW,CAAC,KAAK,CAAC;IAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAGC,yBAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;;IAGjG,MAAM,SAAS,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,cAAc;;AAGvD,IAAA,MAAM,SAAS,GAAGC,8BAAc,CAAC,KAAK,CAAC;;AAEvC,IAAA,MAAM,WAAW,GAAG,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,SAAS;IAC3E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAGC,cAAQ,EAAwC;AACxE,IAAA,IAAI,WAAW,KAAK,SAAS,KAAK,IAAI,EAAE,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,CAAC;QAAE,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAC1I,MAAM,UAAU,GAAG,WAAW,KAAK,IAAI,EAAE,SAAS,KAAK,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAC1F,MAAM,UAAU,GAAGC,2BAAW,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;;IAG1D,MAAM,WAAW,GAAG,SAAS,GAAG,GAAG,GAAG,SAAS;IAC/C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGD,cAAQ,EAAU;AAC1D,IAAA,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,YAAY;QAAE,eAAe,CAAC,WAAW,CAAC;;IAE3F,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,GAAG,CAAA,EAAG,GAAG,WAAW,UAAU,CAAA,CAAE,IAAI,WAAW,IAAI,YAAY,CAAC;AAE/F,IAAA,MAAM,SAAS,GAAG,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,OAAO;AACxD,IAAA,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,OAAO;IAC1E,MAAM,SAAS,GAAG,SAAS,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,UAAU;AAE3I,IAAA,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ;IACxD,MAAM,UAAU,GAAG,UAAU,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC;IAEvG,OAAO;AACL,QAAA,GAAG,KAAK;AACR,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,UAAU;QACjB,UAAU;QACV,SAAS;QACT,SAAS;AACT,QAAA,eAAe,EAAE,UAAU,GAAG,CAAC,GAAG,UAAU,GAAG,KAAK,CAAC,QAAQ;KAC9D;AACH;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type LoadState } from '@flipdish/ui-library/hooks/useLoadState';
|
|
2
|
+
/** The fields `usePagedList` reads from a list query; the rest of the query, such as its search and filters, passes through. */
|
|
3
|
+
export interface PagedListQuery {
|
|
4
|
+
/** The page requested, from 1. */
|
|
5
|
+
page: number;
|
|
6
|
+
/** Rows per page. */
|
|
7
|
+
pageSize: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UsePagedListOptions<Row, Query extends PagedListQuery = PagedListQuery> {
|
|
10
|
+
/** Names the request: the page's query, or its `listQueryKeyOf` key. */
|
|
11
|
+
query: Query;
|
|
12
|
+
/** The page's rows, `undefined` until they arrive. */
|
|
13
|
+
rows: readonly Row[] | undefined;
|
|
14
|
+
/** The row total of the whole result set, from the API, `undefined` until a page arrives; `NaN` or `Infinity` counts as unknown. */
|
|
15
|
+
total: number | undefined;
|
|
16
|
+
/** The request has no data yet, as TanStack Query's `isPending`. */
|
|
17
|
+
isPending: boolean;
|
|
18
|
+
/** The request failed. */
|
|
19
|
+
isError: boolean;
|
|
20
|
+
/** The previous request's rows are standing in while this one lands, as TanStack Query's `isPlaceholderData`. */
|
|
21
|
+
isPreviousData?: boolean;
|
|
22
|
+
/** How many times the request has failed, as TanStack Query's `errorUpdateCount`, so a retry that fails again has a new `resultKey`. */
|
|
23
|
+
errorCount?: number;
|
|
24
|
+
/** Starts the request again. A returned promise ends the retry when it settles; anything else ends it at once. */
|
|
25
|
+
refetch: () => unknown;
|
|
26
|
+
}
|
|
27
|
+
/** What `usePagedList` reports a paged list shows. */
|
|
28
|
+
export interface PagedListState<Row> extends Omit<LoadState, 'showData'> {
|
|
29
|
+
/** The rows to draw: none while nothing has arrived or while the error shows, cached rows of a failed refetch included. */
|
|
30
|
+
rows: readonly Row[];
|
|
31
|
+
/** The current result set's row total, kept across page and page-size changes and through an error; `undefined` until a page lands. */
|
|
32
|
+
total: number | undefined;
|
|
33
|
+
/** The page count for the pager; `0` while `total` is unknown. */
|
|
34
|
+
totalPages: number;
|
|
35
|
+
/** Names the query whose rows are on screen, for keying a status announcement; each failed attempt has a key of its own. */
|
|
36
|
+
resultKey: string | undefined;
|
|
37
|
+
/** A page past the last one has landed with no rows, as from a stale link. */
|
|
38
|
+
isPastEnd: boolean;
|
|
39
|
+
/** How many placeholder rows a loading page draws: the size the page will land at when the total is known. */
|
|
40
|
+
loadingRowCount: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Reports what a paged list shows, from the state of the request its page makes, which keeps its own `useQuery`. Use it for
|
|
44
|
+
* any list with a pager: it keeps the row total across page changes, holds a failed load's error through its retry, and
|
|
45
|
+
* names the query on screen for the status region that announces it.
|
|
46
|
+
*
|
|
47
|
+
* @param options The page's query, its rows and total, the request's state as the data library reports it, and its `refetch`;
|
|
48
|
+
* see `UsePagedListOptions`.
|
|
49
|
+
* @returns The `rows` to draw, `[]` while there is nothing to show or the error shows, as it does for a failed refetch whose
|
|
50
|
+
* rows are cached; `total` and `totalPages`, which stay through a page or rows-per-page change and an error, and are unknown
|
|
51
|
+
* again once anything else changes; the load state of `useLoadState`; `resultKey`, which changes as another query's result
|
|
52
|
+
* lands and with each failed attempt, but not for a refresh of the same query; `isPastEnd` for a link to a page past the
|
|
53
|
+
* last; and `loadingRowCount`, so a short last page does not load taller than it lands.
|
|
54
|
+
*/
|
|
55
|
+
export declare const usePagedList: <Row, Query extends PagedListQuery = PagedListQuery>({ query, rows, total, isPending, isError, isPreviousData, errorCount, refetch, }: UsePagedListOptions<Row, Query>) => PagedListState<Row>;
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePagedList/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAgB,MAAM,yCAAyC,CAAC;AAKvF,gIAAgI;AAChI,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB,CAAC,GAAG,EAAE,KAAK,SAAS,cAAc,GAAG,cAAc;IACrF,wEAAwE;IACxE,KAAK,EAAE,KAAK,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,SAAS,CAAC;IACjC,oIAAoI;IACpI,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAC;IACnB,0BAA0B;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,iHAAiH;IACjH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,wIAAwI;IACxI,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kHAAkH;IAClH,OAAO,EAAE,MAAM,OAAO,CAAC;CACxB;AAED,sDAAsD;AACtD,MAAM,WAAW,cAAc,CAAC,GAAG,CAAE,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IACtE,2HAA2H;IAC3H,IAAI,EAAE,SAAS,GAAG,EAAE,CAAC;IACrB,uIAAuI;IACvI,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,4HAA4H;IAC5H,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,8EAA8E;IAC9E,SAAS,EAAE,OAAO,CAAC;IACnB,8GAA8G;IAC9G,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,EAAE,KAAK,SAAS,cAAc,GAAG,cAAc,EAAE,kFAS9E,mBAAmB,CAAC,GAAG,EAAE,KAAK,CAAC,KAAG,cAAc,CAAC,GAAG,CAuCtD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useLoadState } from '@flipdish/ui-library/hooks/useLoadState';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { resultSetKeyOf, pageCountOf } from '../../utilities/__internal__/listStateUtils/listState.utils.js';
|
|
4
|
+
import { stableKeyOf } from '../../utilities/__internal__/stableKeyUtils/stableKey.utils.js';
|
|
5
|
+
|
|
6
|
+
// One empty array for every render with nothing to draw, so `rows` keeps its identity while it stays empty.
|
|
7
|
+
const NO_ROWS = [];
|
|
8
|
+
/**
|
|
9
|
+
* Reports what a paged list shows, from the state of the request its page makes, which keeps its own `useQuery`. Use it for
|
|
10
|
+
* any list with a pager: it keeps the row total across page changes, holds a failed load's error through its retry, and
|
|
11
|
+
* names the query on screen for the status region that announces it.
|
|
12
|
+
*
|
|
13
|
+
* @param options The page's query, its rows and total, the request's state as the data library reports it, and its `refetch`;
|
|
14
|
+
* see `UsePagedListOptions`.
|
|
15
|
+
* @returns The `rows` to draw, `[]` while there is nothing to show or the error shows, as it does for a failed refetch whose
|
|
16
|
+
* rows are cached; `total` and `totalPages`, which stay through a page or rows-per-page change and an error, and are unknown
|
|
17
|
+
* again once anything else changes; the load state of `useLoadState`; `resultKey`, which changes as another query's result
|
|
18
|
+
* lands and with each failed attempt, but not for a refresh of the same query; `isPastEnd` for a link to a page past the
|
|
19
|
+
* last; and `loadingRowCount`, so a short last page does not load taller than it lands.
|
|
20
|
+
*/
|
|
21
|
+
const usePagedList = ({ query, rows, total, isPending, isError, isPreviousData = false, errorCount = 0, refetch, }) => {
|
|
22
|
+
const key = stableKeyOf(query);
|
|
23
|
+
const { showData, ...state } = useLoadState({ key, isPending, isError, isPreviousData, refetch });
|
|
24
|
+
// Rows standing in from the previous request belong to its result set, so neither their total nor their key is kept.
|
|
25
|
+
const hasLanded = rows !== undefined && !isPreviousData;
|
|
26
|
+
// Kept per result set, so the pager stays through a page change but never offers pages a new search or filter may not have.
|
|
27
|
+
const resultSet = resultSetKeyOf(query);
|
|
28
|
+
// A `NaN` total, as from `Number()` of a missing header, never equals the kept one and would set state on every render.
|
|
29
|
+
const landedTotal = hasLanded && Number.isFinite(total) ? total : undefined;
|
|
30
|
+
const [kept, setKept] = useState();
|
|
31
|
+
if (landedTotal !== undefined && (kept?.resultSet !== resultSet || kept.total !== landedTotal))
|
|
32
|
+
setKept({ resultSet, total: landedTotal });
|
|
33
|
+
const knownTotal = landedTotal ?? (kept?.resultSet === resultSet ? kept.total : undefined);
|
|
34
|
+
const totalPages = pageCountOf(knownTotal, query.pageSize);
|
|
35
|
+
// Keyed by query, not by response: a background refetch landing new rows for the same query must not be announced again.
|
|
36
|
+
const shownResult = hasLanded ? key : undefined;
|
|
37
|
+
const [landedResult, setLandedResult] = useState();
|
|
38
|
+
if (shownResult !== undefined && shownResult !== landedResult)
|
|
39
|
+
setLandedResult(shownResult);
|
|
40
|
+
// A failed attempt gets a key of its own, so a retry that fails again is announced although the words are the same.
|
|
41
|
+
const resultKey = state.isError ? `${key} failed ${errorCount}` : (shownResult ?? landedResult);
|
|
42
|
+
const shownRows = showData ? (rows ?? NO_ROWS) : NO_ROWS;
|
|
43
|
+
const isSettled = !state.isLoading && !state.isSearching && !state.isError;
|
|
44
|
+
const isPastEnd = isSettled && hasLanded && shownRows.length === 0 && knownTotal !== undefined && knownTotal > 0 && query.page > totalPages;
|
|
45
|
+
const rowsBeforePage = (query.page - 1) * query.pageSize;
|
|
46
|
+
const rowsOnPage = knownTotal === undefined ? 0 : Math.min(knownTotal - rowsBeforePage, query.pageSize);
|
|
47
|
+
return {
|
|
48
|
+
...state,
|
|
49
|
+
rows: shownRows,
|
|
50
|
+
total: knownTotal,
|
|
51
|
+
totalPages,
|
|
52
|
+
resultKey,
|
|
53
|
+
isPastEnd,
|
|
54
|
+
loadingRowCount: rowsOnPage > 0 ? rowsOnPage : query.pageSize,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { usePagedList };
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/usePagedList/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAkDA;AACA,MAAM,OAAO,GAAqB,EAAE;AAEpC;;;;;;;;;;;;AAYG;AACI,MAAM,YAAY,GAAG,CAAqD,EAC/E,KAAK,EACL,IAAI,EACJ,KAAK,EACL,SAAS,EACT,OAAO,EACP,cAAc,GAAG,KAAK,EACtB,UAAU,GAAG,CAAC,EACd,OAAO,GACyB,KAAyB;AACzD,IAAA,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC;IAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;;IAGjG,MAAM,SAAS,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,cAAc;;AAGvD,IAAA,MAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC;;AAEvC,IAAA,MAAM,WAAW,GAAG,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,SAAS;IAC3E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,EAAwC;AACxE,IAAA,IAAI,WAAW,KAAK,SAAS,KAAK,IAAI,EAAE,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,CAAC;QAAE,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAC1I,MAAM,UAAU,GAAG,WAAW,KAAK,IAAI,EAAE,SAAS,KAAK,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAC1F,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;;IAG1D,MAAM,WAAW,GAAG,SAAS,GAAG,GAAG,GAAG,SAAS;IAC/C,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAU;AAC1D,IAAA,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,YAAY;QAAE,eAAe,CAAC,WAAW,CAAC;;IAE3F,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,GAAG,CAAA,EAAG,GAAG,WAAW,UAAU,CAAA,CAAE,IAAI,WAAW,IAAI,YAAY,CAAC;AAE/F,IAAA,MAAM,SAAS,GAAG,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,OAAO;AACxD,IAAA,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,OAAO;IAC1E,MAAM,SAAS,GAAG,SAAS,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,UAAU;AAE3I,IAAA,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ;IACxD,MAAM,UAAU,GAAG,UAAU,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC;IAEvG,OAAO;AACL,QAAA,GAAG,KAAK;AACR,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,UAAU;QACjB,UAAU;QACV,SAAS;QACT,SAAS;AACT,QAAA,eAAe,EAAE,UAAU,GAAG,CAAC,GAAG,UAAU,GAAG,KAAK,CAAC,QAAQ;KAC9D;AACH;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `
|
|
2
|
+
* `Tables` has no React Native implementation.
|
|
3
3
|
*
|
|
4
4
|
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
-
* that importing `@flipdish/ui-library/
|
|
5
|
+
* that importing `@flipdish/ui-library/components/organisms/Tables` from React Native fails at
|
|
6
6
|
* compile time rather than resolving to the web build's types. There is no
|
|
7
7
|
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
8
|
*
|
|
9
|
-
* To make `
|
|
9
|
+
* To make `Tables` available on React Native, add an `index.native.tsx` beside
|
|
10
10
|
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
11
|
*/
|
|
12
12
|
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListQueryParams` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/hooks/useListQueryParams` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `useListQueryParams` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useLoadState` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/hooks/useLoadState` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `useLoadState` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `usePagedList` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/hooks/usePagedList` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `usePagedList` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `listQueryUtils` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/utilities/listQueryUtils` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `listQueryUtils` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
package/dist/styles.css
CHANGED
|
@@ -142,9 +142,9 @@
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/*
|
|
145
|
-
* The keyboard focus ring of an element `useFocusHandOff`
|
|
146
|
-
* it with this attribute, so the element keeps its own classes. In `base`, so a utility on the element
|
|
147
|
-
* `focus-visible:outline-hidden` still wins.
|
|
145
|
+
* The keyboard focus ring of an element `hooks/__internal__/useFocusHandOff` made focusable, behind `useFocusAfterRetry` and
|
|
146
|
+
* `Table`, which marks it with this attribute, so the element keeps its own classes. In `base`, so a utility on the element
|
|
147
|
+
* such as `focus-visible:outline-hidden` still wins.
|
|
148
148
|
*/
|
|
149
149
|
@layer base {
|
|
150
150
|
[data-focus-hand-off-target]:focus-visible {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stableKey_utils = require('../stableKeyUtils/stableKey.utils.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The state helpers under `useLoadState` and `usePagedList`: what a load shows, which result set a page belongs to, and its
|
|
7
|
+
* page count. INTERNAL: import as `#internal/utilities/listStateUtils/listState.utils`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Names the result set a page of rows belongs to, so a row total can outlive page and page-size changes.
|
|
11
|
+
*
|
|
12
|
+
* @param query Any query object with a `page` and `pageSize`, plus whatever else the list filters on.
|
|
13
|
+
* @returns A string that is the same for every page and page size of one result set, and different once anything else changes.
|
|
14
|
+
*/
|
|
15
|
+
const resultSetKeyOf = ({ page: _page, pageSize: _pageSize, ...rest }) => stableKey_utils.stableKeyOf(rest);
|
|
16
|
+
/**
|
|
17
|
+
* Decides what a load shows. An error always shows as one: TanStack Query keeps a failed refetch's cached data, and drops the
|
|
18
|
+
* error as soon as a retry fetches again, so the error and the button that started a retry hold until it succeeds.
|
|
19
|
+
*
|
|
20
|
+
* @param state The query's result and whether a retry is running; see `LoadStateInput`.
|
|
21
|
+
* @returns At most one of `isLoading` (loading rows), `isSearching` (stand-in rows) and `isError`, which wins over the others
|
|
22
|
+
* while the query is in error or a retry runs; and `showData`, which is `false` exactly while `isError` is `true`, so cached or
|
|
23
|
+
* stand-in rows stay hidden behind the error.
|
|
24
|
+
*/
|
|
25
|
+
const loadStateOf = ({ isPending, isError, isPreviousData, isRetrying }) => {
|
|
26
|
+
if (isError || isRetrying)
|
|
27
|
+
return { isLoading: false, isSearching: false, isError: true, showData: false };
|
|
28
|
+
// Rows standing in are data to show, so they are not also a load.
|
|
29
|
+
return { isLoading: isPending && !isPreviousData, isSearching: isPreviousData, isError: false, showData: true };
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Counts the pages a result set spans.
|
|
33
|
+
*
|
|
34
|
+
* @param total The row total from the API, `undefined` while it is not known.
|
|
35
|
+
* @param pageSize Rows per page.
|
|
36
|
+
* @returns `Math.ceil(total / pageSize)`; `0` when `total` is unknown or zero, or `pageSize` is not a positive number.
|
|
37
|
+
*/
|
|
38
|
+
const pageCountOf = (total, pageSize) => {
|
|
39
|
+
if (!total || !(pageSize > 0))
|
|
40
|
+
return 0;
|
|
41
|
+
return Math.ceil(total / pageSize);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.loadStateOf = loadStateOf;
|
|
45
|
+
exports.pageCountOf = pageCountOf;
|
|
46
|
+
exports.resultSetKeyOf = resultSetKeyOf;
|
|
47
|
+
//# sourceMappingURL=listState.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listState.utils.cjs","sources":["../../../../src/utilities/__internal__/listStateUtils/listState.utils.ts"],"sourcesContent":[null],"names":["stableKeyOf"],"mappings":";;;;AAAA;;;AAGG;AAGH;;;;;AAKG;AACI,MAAM,cAAc,GAAG,CAAmD,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAS,KACnIA,2BAAW,CAAC,IAAI;AA0BlB;;;;;;;;AAQG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAkB,KAAqB;IACjH,IAAI,OAAO,IAAI,UAAU;AAAE,QAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;;IAE1G,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI,CAAC,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE;AACjH;AAEA;;;;;;AAMG;MACU,WAAW,GAAG,CAAC,KAAyB,EAAE,QAAgB,KAAY;IACjF,IAAI,CAAC,KAAK,IAAI,EAAE,QAAQ,GAAG,CAAC,CAAC;AAAE,QAAA,OAAO,CAAC;IACvC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;AACpC;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names the result set a page of rows belongs to, so a row total can outlive page and page-size changes.
|
|
3
|
+
*
|
|
4
|
+
* @param query Any query object with a `page` and `pageSize`, plus whatever else the list filters on.
|
|
5
|
+
* @returns A string that is the same for every page and page size of one result set, and different once anything else changes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const resultSetKeyOf: <Query extends {
|
|
8
|
+
page: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
}>({ page: _page, pageSize: _pageSize, ...rest }: Query) => string;
|
|
11
|
+
/** A query's result as TanStack's `useQuery` reports it, and whether the page's `retry` is still running for it. */
|
|
12
|
+
export interface LoadStateInput {
|
|
13
|
+
/** The query has no data yet. */
|
|
14
|
+
isPending: boolean;
|
|
15
|
+
/** The query failed, a refetch with data cached included. */
|
|
16
|
+
isError: boolean;
|
|
17
|
+
/** TanStack Query's `isPlaceholderData`, when `placeholderData` keeps the previous rows standing in, as for a search. */
|
|
18
|
+
isPreviousData: boolean;
|
|
19
|
+
/** `retry` was called for this query and its fetch has not settled. */
|
|
20
|
+
isRetrying: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** What `loadStateOf` decides a load shows. */
|
|
23
|
+
export interface LoadStateResult {
|
|
24
|
+
/** Draw loading rows. */
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
/** The previous rows stand in while a search lands. */
|
|
27
|
+
isSearching: boolean;
|
|
28
|
+
/** Show the error and its retry button. */
|
|
29
|
+
isError: boolean;
|
|
30
|
+
/** The data may be drawn; `false` while the error shows. */
|
|
31
|
+
showData: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Decides what a load shows. An error always shows as one: TanStack Query keeps a failed refetch's cached data, and drops the
|
|
35
|
+
* error as soon as a retry fetches again, so the error and the button that started a retry hold until it succeeds.
|
|
36
|
+
*
|
|
37
|
+
* @param state The query's result and whether a retry is running; see `LoadStateInput`.
|
|
38
|
+
* @returns At most one of `isLoading` (loading rows), `isSearching` (stand-in rows) and `isError`, which wins over the others
|
|
39
|
+
* while the query is in error or a retry runs; and `showData`, which is `false` exactly while `isError` is `true`, so cached or
|
|
40
|
+
* stand-in rows stay hidden behind the error.
|
|
41
|
+
*/
|
|
42
|
+
export declare const loadStateOf: ({ isPending, isError, isPreviousData, isRetrying }: LoadStateInput) => LoadStateResult;
|
|
43
|
+
/**
|
|
44
|
+
* Counts the pages a result set spans.
|
|
45
|
+
*
|
|
46
|
+
* @param total The row total from the API, `undefined` while it is not known.
|
|
47
|
+
* @param pageSize Rows per page.
|
|
48
|
+
* @returns `Math.ceil(total / pageSize)`; `0` when `total` is unknown or zero, or `pageSize` is not a positive number.
|
|
49
|
+
*/
|
|
50
|
+
export declare const pageCountOf: (total: number | undefined, pageSize: number) => number;
|
|
51
|
+
//# sourceMappingURL=listState.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listState.utils.d.ts","sourceRoot":"","sources":["../../../../src/utilities/__internal__/listStateUtils/listState.utils.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,+CAA+C,KAAK,KAAG,MACrH,CAAC;AAEpB,oHAAoH;AACpH,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,OAAO,EAAE,OAAO,CAAC;IACjB,yHAAyH;IACzH,cAAc,EAAE,OAAO,CAAC;IACxB,uEAAuE;IACvE,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,+CAA+C;AAC/C,MAAM,WAAW,eAAe;IAC9B,yBAAyB;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,WAAW,EAAE,OAAO,CAAC;IACrB,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAI,oDAAoD,cAAc,KAAG,eAIhG,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,GAAG,SAAS,EAAE,UAAU,MAAM,KAAG,MAGzE,CAAC"}
|