@devtron-labs/devtron-fe-common-lib 0.0.60-beta-2 → 0.0.60-beta-3

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.
Files changed (60) hide show
  1. package/dist/Common/Api.d.ts +0 -9
  2. package/dist/Common/Constants.d.ts +0 -14
  3. package/dist/Common/Helper.d.ts +4 -1
  4. package/dist/Common/Hooks/index.d.ts +0 -1
  5. package/dist/Common/Types.d.ts +4 -16
  6. package/dist/Common/index.d.ts +0 -1
  7. package/dist/index.d.ts +1 -3
  8. package/dist/index.js +182 -666
  9. package/package.json +1 -1
  10. package/src/Common/Api.ts +0 -21
  11. package/src/Common/Constants.ts +1 -17
  12. package/src/Common/Helper.tsx +30 -16
  13. package/src/Common/Hooks/index.ts +0 -1
  14. package/src/Common/SearchBar/SearchBar.component.tsx +11 -23
  15. package/src/Common/Types.ts +3 -16
  16. package/src/Common/index.ts +0 -1
  17. package/src/index.ts +1 -3
  18. package/dist/Common/Hooks/useUrlFilters/constants.d.ts +0 -8
  19. package/dist/Common/Hooks/useUrlFilters/index.d.ts +0 -2
  20. package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -19
  21. package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +0 -20
  22. package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +0 -18
  23. package/dist/Common/SortableTableHeaderCell/index.d.ts +0 -2
  24. package/dist/Common/SortableTableHeaderCell/types.d.ts +0 -25
  25. package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +0 -15
  26. package/dist/Pages/GlobalConfigurations/Authorization/index.d.ts +0 -1
  27. package/dist/Pages/GlobalConfigurations/index.d.ts +0 -1
  28. package/dist/Pages/index.d.ts +0 -1
  29. package/dist/Shared/Components/BulkSelection/BulkSelection.d.ts +0 -4
  30. package/dist/Shared/Components/BulkSelection/BulkSelectionDropdownItems.d.ts +0 -4
  31. package/dist/Shared/Components/BulkSelection/BulkSelectionProvider.d.ts +0 -4
  32. package/dist/Shared/Components/BulkSelection/constants.d.ts +0 -9
  33. package/dist/Shared/Components/BulkSelection/index.d.ts +0 -4
  34. package/dist/Shared/Components/BulkSelection/types.d.ts +0 -54
  35. package/dist/Shared/Components/index.d.ts +0 -1
  36. package/dist/Shared/index.d.ts +0 -1
  37. package/src/Assets/Icon/ic-arrow-up-down.svg +0 -3
  38. package/src/Assets/Icon/ic-check-all.svg +0 -5
  39. package/src/Assets/Icon/ic-check-square.svg +0 -4
  40. package/src/Assets/Icon/ic-close.svg +0 -9
  41. package/src/Assets/Icon/ic-sort-arrow-down.svg +0 -3
  42. package/src/Common/Hooks/useUrlFilters/constants.ts +0 -9
  43. package/src/Common/Hooks/useUrlFilters/index.ts +0 -2
  44. package/src/Common/Hooks/useUrlFilters/types.ts +0 -21
  45. package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +0 -121
  46. package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +0 -44
  47. package/src/Common/SortableTableHeaderCell/index.ts +0 -2
  48. package/src/Common/SortableTableHeaderCell/types.ts +0 -26
  49. package/src/Pages/GlobalConfigurations/Authorization/constants.ts +0 -16
  50. package/src/Pages/GlobalConfigurations/Authorization/index.ts +0 -1
  51. package/src/Pages/GlobalConfigurations/index.ts +0 -1
  52. package/src/Pages/index.ts +0 -1
  53. package/src/Shared/Components/BulkSelection/BulkSelection.tsx +0 -77
  54. package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +0 -31
  55. package/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +0 -160
  56. package/src/Shared/Components/BulkSelection/constants.tsx +0 -13
  57. package/src/Shared/Components/BulkSelection/index.ts +0 -4
  58. package/src/Shared/Components/BulkSelection/types.tsx +0 -65
  59. package/src/Shared/Components/index.ts +0 -1
  60. package/src/Shared/index.ts +0 -1
@@ -1,121 +0,0 @@
1
- import { useMemo } from 'react'
2
- import { useHistory, useLocation } from 'react-router-dom'
3
- import { DEFAULT_BASE_PAGE_SIZE, SortingOrder } from '../../Constants'
4
- import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
5
- import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
6
-
7
- const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_KEYS
8
-
9
- /**
10
- * Generic hook for implementing URL based filters.
11
- * eg: pagination, search, sort.
12
- *
13
- * The exposed handlers can be consumed directly without the need for explicit state management
14
- *
15
- * @example Default Usage:
16
- * ```tsx
17
- * const { pageSize, changePage, ...rest } = useUrlFilters()
18
- * ```
19
- *
20
- * @example Usage with custom type for sort keys and initial sort key:
21
- * ```tsx
22
- * const { sortBy, sortOrder } = useUrlFilters<'email' | 'name'>({ initialSortKey: 'email' })
23
- * ```
24
- *
25
- */
26
- const useUrlFilters = <T = string>({ initialSortKey }: UseUrlFiltersProps<T> = {}): UseUrlFiltersReturnType<T> => {
27
- const location = useLocation()
28
- const history = useHistory()
29
- const searchParams = new URLSearchParams(location.search)
30
-
31
- const { pageSize, pageNumber, searchKey, sortBy, sortOrder } = useMemo(() => {
32
- const _pageSize = searchParams.get(PAGE_SIZE)
33
- const _pageNumber = searchParams.get(PAGE_NUMBER)
34
- const _searchKey = searchParams.get(SEARCH_KEY)
35
- const _sortOrder = searchParams.get(SORT_ORDER) as SortingOrder
36
- const _sortBy = searchParams.get(SORT_BY)
37
-
38
- const sortByKey = (_sortBy || initialSortKey || '') as T
39
- // Fallback to ascending order
40
- const sortByOrder = Object.values(SortingOrder).includes(_sortOrder) ? _sortOrder : SortingOrder.ASC
41
-
42
- return {
43
- pageSize: Number(_pageSize) || DEFAULT_BASE_PAGE_SIZE,
44
- pageNumber: Number(_pageNumber) || DEFAULT_PAGE_NUMBER,
45
- searchKey: _searchKey || '',
46
- sortBy: sortByKey,
47
- // sort order should only be applied if the key is available
48
- sortOrder: (sortByKey ? sortByOrder : '') as SortingOrder,
49
- }
50
- }, [searchParams])
51
-
52
- /**
53
- * Used for getting the required result from the API
54
- */
55
- const offset = pageSize * (pageNumber - 1)
56
-
57
- /**
58
- * Update and replace the search params in the URL.
59
- *
60
- * Note: Currently only primitive data types are supported
61
- */
62
- const _updateSearchParam = (key: string, value) => {
63
- searchParams.set(key, String(value))
64
- history.replace({ search: searchParams.toString() })
65
- }
66
-
67
- const _resetPageNumber = () => {
68
- _updateSearchParam(PAGE_NUMBER, DEFAULT_PAGE_NUMBER)
69
- }
70
-
71
- const changePage = (page: number) => {
72
- _updateSearchParam(PAGE_NUMBER, page)
73
- }
74
-
75
- const changePageSize = (_pageSize: number) => {
76
- _updateSearchParam(PAGE_SIZE, _pageSize)
77
- _resetPageNumber()
78
- }
79
-
80
- const handleSearch = (searchTerm: string) => {
81
- _updateSearchParam(SEARCH_KEY, searchTerm)
82
- _resetPageNumber()
83
- }
84
-
85
- const handleSorting = (_sortBy: T) => {
86
- let order: SortingOrder
87
- if (_sortBy === sortBy && sortOrder === SortingOrder.ASC) {
88
- order = SortingOrder.DESC
89
- } else {
90
- order = SortingOrder.ASC
91
- }
92
-
93
- _updateSearchParam(SORT_BY, _sortBy)
94
- _updateSearchParam(SORT_ORDER, order)
95
-
96
- // Reset page number on sorting change
97
- _resetPageNumber()
98
- }
99
-
100
- const clearFilters = () => {
101
- Object.values(URL_FILTER_KEYS).forEach((key) => {
102
- searchParams.delete(key)
103
- })
104
- history.replace({ search: searchParams.toString() })
105
- }
106
-
107
- return {
108
- pageSize,
109
- changePage,
110
- changePageSize,
111
- searchKey,
112
- handleSearch,
113
- offset,
114
- sortBy,
115
- sortOrder,
116
- handleSorting,
117
- clearFilters,
118
- }
119
- }
120
-
121
- export default useUrlFilters
@@ -1,44 +0,0 @@
1
- import { ReactComponent as SortIcon } from '../../Assets/Icon/ic-arrow-up-down.svg'
2
- import { ReactComponent as SortArrowDown } from '../../Assets/Icon/ic-sort-arrow-down.svg'
3
- import { SortingOrder } from '../Constants'
4
- import { SortableTableHeaderCellProps } from './types'
5
-
6
- /**
7
- * Reusable component for the table header cell with support for sorting icons
8
- *
9
- * @example Usage
10
- * ```tsx
11
- * <SortableTableHeaderCell
12
- * isSorted={currentSortedCell === 'cell'}
13
- * triggerSorting={() => {}}
14
- * sortOrder={SortingOrder.ASC}
15
- * title="Header Cell"
16
- * disabled={isDisabled}
17
- * />
18
- * ```
19
- */
20
- const SortableTableHeaderCell = ({
21
- isSorted,
22
- triggerSorting,
23
- sortOrder,
24
- title,
25
- disabled,
26
- }: SortableTableHeaderCellProps) => (
27
- <button
28
- type="button"
29
- className="dc__transparent p-0 bcn-0 cn-7 flex dc__content-start dc__gap-4 cursor"
30
- onClick={triggerSorting}
31
- disabled={disabled}
32
- >
33
- <span className="dc__uppercase dc__ellipsis-right">{title}</span>
34
- {isSorted ? (
35
- <SortArrowDown
36
- className={`icon-dim-12 mw-12 scn-7 ${sortOrder === SortingOrder.DESC ? 'dc__flip-180' : ''}`}
37
- />
38
- ) : (
39
- <SortIcon className="icon-dim-12 mw-12 scn-7" />
40
- )}
41
- </button>
42
- )
43
-
44
- export default SortableTableHeaderCell
@@ -1,2 +0,0 @@
1
- export { default as SortableTableHeaderCell } from './SortableTableHeaderCell'
2
- export type { SortableTableHeaderCellProps } from './types'
@@ -1,26 +0,0 @@
1
- import { SortingOrder } from '../Constants'
2
-
3
- export interface SortableTableHeaderCellProps {
4
- /**
5
- * If true, the cell is sorted
6
- */
7
- isSorted: boolean
8
- /**
9
- * Callback for handling the sorting of the cell
10
- */
11
- triggerSorting: () => void
12
- /**
13
- * Current sort order
14
- *
15
- * Note: On click, the sort order should be updated as required
16
- */
17
- sortOrder: SortingOrder
18
- /**
19
- * Label for the cell
20
- */
21
- title: string
22
- /**
23
- * If true, the cell is disabled
24
- */
25
- disabled: boolean
26
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * User Status received from the API
3
- */
4
- export enum UserStatusDto {
5
- active = 'active',
6
- inactive = 'inactive',
7
- }
8
-
9
- /**
10
- * User status for the frontend
11
- */
12
- export enum UserStatus {
13
- active = 'active',
14
- inactive = 'inactive',
15
- temporary = 'temporary',
16
- }
@@ -1 +0,0 @@
1
- export * from './constants'
@@ -1 +0,0 @@
1
- export * from './Authorization'
@@ -1 +0,0 @@
1
- export * from './GlobalConfigurations'
@@ -1,77 +0,0 @@
1
- import BulkSelectionDropdownItems from './BulkSelectionDropdownItems'
2
- import { CHECKBOX_VALUE, Checkbox, PopupMenu, noop } from '../../../Common'
3
- import { useBulkSelection } from './BulkSelectionProvider'
4
- import { BulkSelectionDropdownItemsType, BulkSelectionEvents, BulkSelectionProps } from './types'
5
- import { BULK_DROPDOWN_TEST_ID, BulkSelectionOptionsLabels } from './constants'
6
- import { ReactComponent as ICChevronDown } from '../../../Assets/Icon/ic-chevron-down.svg'
7
- import { ReactComponent as ICCheckSquare } from '../../../Assets/Icon/ic-check-square.svg'
8
- import { ReactComponent as ICCheckAll } from '../../../Assets/Icon/ic-check-all.svg'
9
- import { ReactComponent as ICClose } from '../../../Assets/Icon/ic-close.svg'
10
-
11
- const BulkSelection = <T,>({ showPagination }: BulkSelectionProps) => {
12
- const { handleBulkSelection, selectedIdentifiers, isChecked, checkboxValue } = useBulkSelection<T>()
13
- const areOptionsSelected = Object.keys(selectedIdentifiers).length > 0
14
- const BulkSelectionItems: BulkSelectionDropdownItemsType[] = [
15
- {
16
- locator: BulkSelectionEvents.SELECT_ALL_ON_PAGE,
17
- label: BulkSelectionOptionsLabels[BulkSelectionEvents.SELECT_ALL_ON_PAGE],
18
- isSelected: isChecked && checkboxValue === CHECKBOX_VALUE.CHECKED,
19
- icon: ICCheckSquare,
20
- },
21
- ...(showPagination
22
- ? [
23
- {
24
- locator: BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES,
25
- label: BulkSelectionOptionsLabels[BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES],
26
- isSelected: isChecked && checkboxValue === CHECKBOX_VALUE.BULK_CHECKED,
27
- icon: ICCheckAll,
28
- },
29
- ]
30
- : []),
31
- ...(areOptionsSelected
32
- ? [
33
- {
34
- locator: BulkSelectionEvents.CLEAR_ALL_SELECTIONS,
35
- label: BulkSelectionOptionsLabels[BulkSelectionEvents.CLEAR_ALL_SELECTIONS],
36
- isSelected: false,
37
- icon: ICClose,
38
- },
39
- ]
40
- : []),
41
- ]
42
-
43
- return (
44
- <PopupMenu autoClose>
45
- <PopupMenu.Button
46
- isKebab
47
- rootClassName="h-20 flexbox p-0 dc__no-background dc__no-border dc__outline-none-imp"
48
- dataTestId={BULK_DROPDOWN_TEST_ID}
49
- >
50
- <Checkbox
51
- isChecked={isChecked}
52
- onChange={noop}
53
- rootClassName="icon-dim-20 m-0"
54
- value={checkboxValue}
55
- // Ideally should be disabled but was giving issue with cursor
56
- />
57
-
58
- <ICChevronDown className="icon-dim-20 fcn-6 dc__no-shrink" />
59
- </PopupMenu.Button>
60
-
61
- <PopupMenu.Body rootClassName="dc__top-22 w-150 dc__right-0 pt-4 pb-4 pl-0 pr-0 bcn-0 flex column dc__content-start dc__align-start dc__position-abs bcn-0 dc__border dc__border-radius-4-imp">
62
- {BulkSelectionItems.map((item) => (
63
- <BulkSelectionDropdownItems<T>
64
- key={item.locator}
65
- locator={item.locator}
66
- label={item.label}
67
- isSelected={item.isSelected}
68
- icon={item.icon}
69
- handleBulkSelection={handleBulkSelection}
70
- />
71
- ))}
72
- </PopupMenu.Body>
73
- </PopupMenu>
74
- )
75
- }
76
-
77
- export default BulkSelection
@@ -1,31 +0,0 @@
1
- import { BulkSelectionDropdownItemsProps } from './types'
2
-
3
- const BulkSelectionDropdownItems = <T,>({
4
- locator,
5
- label,
6
- isSelected,
7
- handleBulkSelection,
8
- icon: Icon,
9
- }: BulkSelectionDropdownItemsProps<T>) => {
10
- const handleSelect = () => {
11
- handleBulkSelection({
12
- action: locator,
13
- })
14
- }
15
-
16
- return (
17
- <button
18
- data-testid={`bulk-action-${locator}`}
19
- onClick={handleSelect}
20
- className={`dc__no-border dc__outline-none-imp w-100 flexbox h-32 dc__align-items-center pt-6 pr-8 pb-6 pl-8 dc__gap-8 ${
21
- isSelected ? 'cb-5 bcb-2 fs-13 fw-6 lh-20' : 'dc__no-background cn-9 fs-13 fw-4 lh-20 dc__hover-n50'
22
- }`}
23
- type="button"
24
- >
25
- <Icon className="icon-dim-16" />
26
- {label}
27
- </button>
28
- )
29
- }
30
-
31
- export default BulkSelectionDropdownItems
@@ -1,160 +0,0 @@
1
- import { createContext, useContext, useMemo, useState } from 'react'
2
- import { BULK_SELECTION_CONTEXT_ERROR, SELECT_ALL_ACROSS_PAGES_LOCATOR, getInvalidActionMessage } from './constants'
3
- import {
4
- BulkSelectionEvents,
5
- GetBulkSelectionCheckboxValuesType,
6
- HandleBulkSelectionType,
7
- SelectAllDialogStatus,
8
- UseBulkSelectionProps,
9
- UseBulkSelectionReturnType,
10
- } from './types'
11
- import { CHECKBOX_VALUE, noop } from '../../../Common'
12
-
13
- // giving type any here since not exporting this context, rather using it through useBulkSelection hook which is typed
14
- const BulkSelectionContext = createContext<UseBulkSelectionReturnType<any>>({
15
- selectedIdentifiers: {},
16
- handleBulkSelection: noop,
17
- isChecked: false,
18
- checkboxValue: CHECKBOX_VALUE.CHECKED,
19
- })
20
-
21
- export const useBulkSelection = <T,>() => {
22
- const context = useContext<UseBulkSelectionReturnType<T>>(BulkSelectionContext)
23
- if (!context) {
24
- throw new Error(BULK_SELECTION_CONTEXT_ERROR)
25
- }
26
- return context
27
- }
28
-
29
- export const BulkSelectionProvider = <T,>({
30
- children,
31
- identifiers,
32
- getSelectAllDialogStatus,
33
- }: UseBulkSelectionProps<T>) => {
34
- const [selectedIdentifiers, setSelectedIdentifiers] = useState<T>({} as T)
35
-
36
- const setIdentifiersAfterClear = (newIdentifiers: T, selectedIds: (number | string)[]) => {
37
- const _newIdentifiers = JSON.parse(JSON.stringify(newIdentifiers))
38
- selectedIds.forEach((id) => {
39
- delete _newIdentifiers[id]
40
- })
41
- setSelectedIdentifiers(_newIdentifiers)
42
- }
43
-
44
- const setIdentifiersAfterPageSelection = (baseObject: T) => {
45
- const _selectedIdentifiers = JSON.parse(JSON.stringify(selectedIdentifiers))
46
- // removing bulk selection across pages if present
47
- if (_selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
48
- delete _selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
49
- }
50
-
51
- setSelectedIdentifiers({
52
- ..._selectedIdentifiers,
53
- ...baseObject,
54
- })
55
- }
56
-
57
- const handleBulkSelection = ({ action, data }: HandleBulkSelectionType<T>) => {
58
- const selectedIds = data?.identifierIds ?? []
59
- const identifierObject = data?.identifierObject ?? {}
60
-
61
- switch (action) {
62
- case BulkSelectionEvents.CLEAR_ALL_SELECTIONS:
63
- setSelectedIdentifiers({} as T)
64
- break
65
-
66
- case BulkSelectionEvents.CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION: {
67
- setIdentifiersAfterClear(identifiers, selectedIds)
68
- break
69
- }
70
-
71
- case BulkSelectionEvents.CLEAR_IDENTIFIERS: {
72
- setIdentifiersAfterClear(selectedIdentifiers, selectedIds)
73
- break
74
- }
75
-
76
- case BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES: {
77
- if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
78
- return
79
- }
80
- const selectedIdentifiersLength = Object.keys(selectedIdentifiers).length
81
- if (selectedIdentifiersLength > 0 && getSelectAllDialogStatus() === SelectAllDialogStatus.OPEN) {
82
- return
83
- }
84
-
85
- setSelectedIdentifiers({
86
- [SELECT_ALL_ACROSS_PAGES_LOCATOR]: true,
87
- } as unknown as T)
88
- break
89
- }
90
-
91
- case BulkSelectionEvents.CLEAR_SELECTIONS_AND_SELECT_ALL_ACROSS_PAGES:
92
- setSelectedIdentifiers({
93
- [SELECT_ALL_ACROSS_PAGES_LOCATOR]: true,
94
- } as unknown as T)
95
- break
96
-
97
- case BulkSelectionEvents.SELECT_ALL_ON_PAGE: {
98
- setIdentifiersAfterPageSelection(identifiers)
99
- break
100
- }
101
-
102
- case BulkSelectionEvents.SELECT_IDENTIFIER: {
103
- setIdentifiersAfterPageSelection(identifierObject as T)
104
- break
105
- }
106
-
107
- default:
108
- throw new Error(getInvalidActionMessage(action))
109
- }
110
- }
111
-
112
- const getBulkSelectionCheckboxValues = (): GetBulkSelectionCheckboxValuesType => {
113
- const selectedIdentifiersArray = Object.keys(selectedIdentifiers)
114
- if (selectedIdentifiersArray.length === 0) {
115
- return {
116
- isChecked: false,
117
- checkboxValue: CHECKBOX_VALUE.CHECKED,
118
- }
119
- }
120
-
121
- // if selectedIdentifiers contains select all across pages locator then it means all are selected
122
- if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
123
- return {
124
- isChecked: true,
125
- checkboxValue: CHECKBOX_VALUE.BULK_CHECKED,
126
- }
127
- }
128
-
129
- // if all the identifiers are selected then CHECKED else intermediate
130
- const areAllPresentIdentifiersSelected = Object.keys(identifiers).every(
131
- (identifierId) => selectedIdentifiers[identifierId],
132
- )
133
-
134
- if (areAllPresentIdentifiersSelected) {
135
- return {
136
- isChecked: true,
137
- checkboxValue: CHECKBOX_VALUE.CHECKED,
138
- }
139
- }
140
-
141
- return {
142
- isChecked: true,
143
- checkboxValue: CHECKBOX_VALUE.INTERMEDIATE,
144
- }
145
- }
146
-
147
- const { isChecked, checkboxValue } = getBulkSelectionCheckboxValues()
148
-
149
- const value = useMemo(
150
- () => ({
151
- selectedIdentifiers,
152
- handleBulkSelection,
153
- isChecked,
154
- checkboxValue,
155
- }),
156
- [selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue],
157
- )
158
-
159
- return <BulkSelectionContext.Provider value={value}>{children}</BulkSelectionContext.Provider>
160
- }
@@ -1,13 +0,0 @@
1
- import { BulkSelectionEvents } from './types'
2
-
3
- export const BULK_DROPDOWN_TEST_ID = 'bulk-selection-pop-up-menu' as const
4
- export const BulkSelectionOptionsLabels = {
5
- [BulkSelectionEvents.SELECT_ALL_ON_PAGE]: 'All on this page',
6
- [BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES]: 'All across pages',
7
- [BulkSelectionEvents.CLEAR_ALL_SELECTIONS]: 'Clear selection',
8
- } as const
9
-
10
- // Considering application can not be named as *
11
- export const SELECT_ALL_ACROSS_PAGES_LOCATOR = '*' as const
12
- export const getInvalidActionMessage = (action: string) => `Invalid action ${action} passed to useBulkSelection`
13
- export const BULK_SELECTION_CONTEXT_ERROR = 'useBulkSelection must be used within BulkSelectionContext'
@@ -1,4 +0,0 @@
1
- export { default as BulkSelection } from './BulkSelection'
2
- export * from './BulkSelectionProvider'
3
- export * from './types'
4
- export * from './constants'
@@ -1,65 +0,0 @@
1
- import { CHECKBOX_VALUE } from '../../../Common'
2
-
3
- export enum BulkSelectionEvents {
4
- CLEAR_ALL_SELECTIONS = 'CLEAR_ALL_SELECTIONS',
5
- CLEAR_IDENTIFIERS = 'CLEAR_IDENTIFIERS',
6
- SELECT_ALL_ACROSS_PAGES = 'SELECT_ALL_ACROSS_PAGES',
7
- SELECT_ALL_ON_PAGE = 'SELECT_ALL_ON_PAGE',
8
- SELECT_IDENTIFIER = 'SELECT_IDENTIFIER',
9
- CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION = 'CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION',
10
- CLEAR_SELECTIONS_AND_SELECT_ALL_ACROSS_PAGES = 'CLEAR_SELECTIONS_AND_SELECT_ALL_ACROSS_PAGES',
11
- }
12
-
13
- export interface HandleBulkSelectionType<T> {
14
- action: BulkSelectionEvents
15
- data?: {
16
- identifierIds?: (number | string)[]
17
- identifierObject?: T
18
- }
19
- }
20
-
21
- export interface GetBulkSelectionCheckboxValuesType {
22
- isChecked: boolean
23
- checkboxValue: CHECKBOX_VALUE
24
- }
25
-
26
- export interface UseBulkSelectionReturnType<T> extends GetBulkSelectionCheckboxValuesType {
27
- selectedIdentifiers: T
28
- handleBulkSelection: ({ action, data }: HandleBulkSelectionType<T>) => void
29
- }
30
-
31
- export interface BulkSelectionProps {
32
- showPagination: boolean
33
- }
34
-
35
- export interface BulkSelectionDropdownItemsType {
36
- locator: BulkSelectionEvents
37
- label: string
38
- isSelected: boolean
39
- icon: React.FunctionComponent<React.SVGProps<SVGSVGElement>>
40
- }
41
-
42
- export interface BulkSelectionDropdownItemsProps<T>
43
- extends BulkSelectionDropdownItemsType,
44
- Pick<UseBulkSelectionReturnType<T>, 'handleBulkSelection'> {}
45
-
46
- export enum SelectAllDialogStatus {
47
- OPEN = 'OPEN',
48
- CLOSED = 'CLOSED',
49
- }
50
-
51
- // This type is intended to be used with UseBulkSelectionProps, e.g, UseBulkSelectionProps<BulkSelectionIdentifiersType<boolean>>
52
- export type BulkSelectionIdentifiersType<T> = Record<string | number, T>
53
-
54
- export interface UseBulkSelectionProps<T> {
55
- /**
56
- * Response from API, assuming structure to be array of objects with key and values
57
- * This will the given ids on current page
58
- */
59
- identifiers: T
60
- /**
61
- * Act as buffer between select all across pages and select all on page state
62
- */
63
- getSelectAllDialogStatus: () => SelectAllDialogStatus
64
- children?: React.ReactNode
65
- }
@@ -1 +0,0 @@
1
- export * from './BulkSelection'
@@ -1 +0,0 @@
1
- export * from './Components'