@devtron-labs/devtron-fe-common-lib 0.0.62-beta-1 → 0.0.62-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Common/DraggableWrapper/types.d.ts +1 -4
- package/dist/Common/Hooks/useUrlFilters/index.d.ts +1 -1
- package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -13
- package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +14 -2
- package/dist/Common/Types.d.ts +3 -3
- package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +150 -441
- package/package.json +1 -1
- package/src/Common/DraggableWrapper/types.ts +1 -4
- package/src/Common/Helper.tsx +1 -8
- package/src/Common/Hooks/useUrlFilters/index.ts +1 -1
- package/src/Common/Hooks/useUrlFilters/types.ts +0 -15
- package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +2 -2
- package/src/Common/Types.ts +2 -3
- package/src/Pages/GlobalConfigurations/Authorization/constants.ts +1 -1
- package/src/index.ts +0 -1
- package/dist/Shared/Components/BulkSelection/BulkSelection.d.ts +0 -4
- package/dist/Shared/Components/BulkSelection/BulkSelectionDropdownItems.d.ts +0 -4
- package/dist/Shared/Components/BulkSelection/BulkSelectionProvider.d.ts +0 -4
- package/dist/Shared/Components/BulkSelection/constants.d.ts +0 -9
- package/dist/Shared/Components/BulkSelection/index.d.ts +0 -4
- package/dist/Shared/Components/BulkSelection/types.d.ts +0 -56
- package/dist/Shared/Components/index.d.ts +0 -1
- package/dist/Shared/index.d.ts +0 -1
- package/src/Assets/Icon/ic-check-all.svg +0 -5
- package/src/Assets/Icon/ic-check-square.svg +0 -4
- package/src/Assets/Icon/ic-close.svg +0 -9
- package/src/Shared/Components/BulkSelection/BulkSelection.tsx +0 -77
- package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +0 -31
- package/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +0 -171
- package/src/Shared/Components/BulkSelection/constants.tsx +0 -13
- package/src/Shared/Components/BulkSelection/index.ts +0 -4
- package/src/Shared/Components/BulkSelection/types.tsx +0 -67
- package/src/Shared/Components/index.ts +0 -1
- package/src/Shared/index.ts +0 -1
package/package.json
CHANGED
|
@@ -8,10 +8,7 @@ export enum DraggablePositionVariant {
|
|
|
8
8
|
|
|
9
9
|
export interface DraggableWrapperProps {
|
|
10
10
|
children: ReactNode
|
|
11
|
-
|
|
12
|
-
* Support for passing the direct value or calc functions as well
|
|
13
|
-
*/
|
|
14
|
-
zIndex?: number | string
|
|
11
|
+
zIndex?: number
|
|
15
12
|
positionVariant?: DraggablePositionVariant
|
|
16
13
|
/**
|
|
17
14
|
* dragSelector (class - (append with .), id, etc) will be used to identify the grabbable button that will grab the div to drag
|
package/src/Common/Helper.tsx
CHANGED
|
@@ -447,16 +447,9 @@ export const processDeployedTime = (lastDeployed, isArgoInstalled) => {
|
|
|
447
447
|
*/
|
|
448
448
|
export const getUrlWithSearchParams = (url: string, params: Record<string | number, any>) => {
|
|
449
449
|
const searchParams = new URLSearchParams()
|
|
450
|
-
// TODO: Common out
|
|
451
450
|
Object.keys(params).forEach((key) => {
|
|
452
451
|
if (params[key]) {
|
|
453
|
-
|
|
454
|
-
params[key].forEach((val) => {
|
|
455
|
-
searchParams.append(key, val)
|
|
456
|
-
})
|
|
457
|
-
} else {
|
|
458
|
-
searchParams.set(key, params[key])
|
|
459
|
-
}
|
|
452
|
+
searchParams.append(key, params[key])
|
|
460
453
|
}
|
|
461
454
|
})
|
|
462
455
|
const queryString = searchParams.toString()
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as useUrlFilters } from './useUrlFilters'
|
|
2
|
-
export type { UseUrlFiltersProps
|
|
2
|
+
export type { UseUrlFiltersProps } from './types'
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import { SortingOrder } from '../../Constants'
|
|
2
|
-
|
|
3
1
|
export interface UseUrlFiltersProps<T> {
|
|
4
2
|
/**
|
|
5
3
|
* The key on which the sorting should be applied
|
|
6
4
|
*/
|
|
7
5
|
initialSortKey?: T
|
|
8
6
|
}
|
|
9
|
-
|
|
10
|
-
export interface UseUrlFiltersReturnType<T> {
|
|
11
|
-
pageSize: number
|
|
12
|
-
changePage: (pageNumber: number) => void
|
|
13
|
-
changePageSize: (pageSize: number) => void
|
|
14
|
-
searchKey: string
|
|
15
|
-
handleSearch: (searchKey: string) => void
|
|
16
|
-
offset: number
|
|
17
|
-
sortBy: T
|
|
18
|
-
sortOrder: SortingOrder
|
|
19
|
-
handleSorting: (sortBy: T) => void
|
|
20
|
-
clearFilters: () => void
|
|
21
|
-
}
|
|
@@ -2,7 +2,7 @@ import { useMemo } from 'react'
|
|
|
2
2
|
import { useHistory, useLocation } from 'react-router-dom'
|
|
3
3
|
import { DEFAULT_BASE_PAGE_SIZE, SortingOrder } from '../../Constants'
|
|
4
4
|
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
|
|
5
|
-
import { UseUrlFiltersProps
|
|
5
|
+
import { UseUrlFiltersProps } from './types'
|
|
6
6
|
|
|
7
7
|
const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_KEYS
|
|
8
8
|
|
|
@@ -23,7 +23,7 @@ const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_K
|
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
25
|
*/
|
|
26
|
-
const useUrlFilters = <T = string>({ initialSortKey }: UseUrlFiltersProps<T> = {})
|
|
26
|
+
const useUrlFilters = <T = string>({ initialSortKey }: UseUrlFiltersProps<T> = {}) => {
|
|
27
27
|
const location = useLocation()
|
|
28
28
|
const history = useHistory()
|
|
29
29
|
const searchParams = new URLSearchParams(location.search)
|
package/src/Common/Types.ts
CHANGED
|
@@ -51,13 +51,11 @@ export interface Teams {
|
|
|
51
51
|
export enum CHECKBOX_VALUE {
|
|
52
52
|
CHECKED = 'CHECKED',
|
|
53
53
|
INTERMEDIATE = 'INTERMEDIATE',
|
|
54
|
-
BULK_CHECKED = 'BULK_CHECKED',
|
|
55
54
|
}
|
|
56
55
|
export interface CheckboxProps {
|
|
57
56
|
onChange: (event) => void
|
|
58
57
|
isChecked: boolean
|
|
59
|
-
|
|
60
|
-
value: 'CHECKED' | 'INTERMEDIATE' | 'BULK_CHECKED'
|
|
58
|
+
value: 'CHECKED' | 'INTERMEDIATE'
|
|
61
59
|
disabled?: boolean
|
|
62
60
|
tabIndex?: number
|
|
63
61
|
rootClassName?: string
|
|
@@ -375,6 +373,7 @@ export interface CommonNodeAttr {
|
|
|
375
373
|
}
|
|
376
374
|
appReleaseTagNames?: string[]
|
|
377
375
|
tagsEditable?: boolean
|
|
376
|
+
isGitOpsRepoNotConfigured?: boolean
|
|
378
377
|
deploymentAppCreated?: boolean
|
|
379
378
|
isLast?: boolean
|
|
380
379
|
downstreamEnvironments?: DownstreamNodesEnvironmentsType[]
|
package/src/index.ts
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { BulkSelectionDropdownItemsProps } from './types';
|
|
3
|
-
declare const BulkSelectionDropdownItems: <T>({ locator, label, isSelected, handleBulkSelection, icon: Icon, }: BulkSelectionDropdownItemsProps<T>) => JSX.Element;
|
|
4
|
-
export default BulkSelectionDropdownItems;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { UseBulkSelectionProps, UseBulkSelectionReturnType } from './types';
|
|
3
|
-
export declare const useBulkSelection: <T>() => UseBulkSelectionReturnType<T>;
|
|
4
|
-
export declare const BulkSelectionProvider: <T>({ children, identifiers, getSelectAllDialogStatus, }: UseBulkSelectionProps<T>) => JSX.Element;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const BULK_DROPDOWN_TEST_ID: "bulk-selection-pop-up-menu";
|
|
2
|
-
export declare const BulkSelectionOptionsLabels: {
|
|
3
|
-
readonly SELECT_ALL_ON_PAGE: "All on this page";
|
|
4
|
-
readonly SELECT_ALL_ACROSS_PAGES: "All across pages";
|
|
5
|
-
readonly CLEAR_ALL_SELECTIONS: "Clear selection";
|
|
6
|
-
};
|
|
7
|
-
export declare const SELECT_ALL_ACROSS_PAGES_LOCATOR: "*";
|
|
8
|
-
export declare const getInvalidActionMessage: (action: string) => string;
|
|
9
|
-
export declare const BULK_SELECTION_CONTEXT_ERROR = "useBulkSelection must be used within BulkSelectionContext";
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CHECKBOX_VALUE } from '../../../Common';
|
|
3
|
-
export declare 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
|
-
export interface HandleBulkSelectionType<T> {
|
|
13
|
-
action: BulkSelectionEvents;
|
|
14
|
-
data?: {
|
|
15
|
-
identifierIds?: (number | string)[];
|
|
16
|
-
identifierObject?: T;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export interface GetBulkSelectionCheckboxValuesType {
|
|
20
|
-
isChecked: boolean;
|
|
21
|
-
checkboxValue: CHECKBOX_VALUE;
|
|
22
|
-
}
|
|
23
|
-
export interface UseBulkSelectionReturnType<T> extends GetBulkSelectionCheckboxValuesType {
|
|
24
|
-
selectedIdentifiers: T;
|
|
25
|
-
handleBulkSelection: ({ action, data }: HandleBulkSelectionType<T>) => void;
|
|
26
|
-
isBulkSelectionApplied: boolean;
|
|
27
|
-
getSelectedIdentifiersCount: () => number;
|
|
28
|
-
}
|
|
29
|
-
export interface BulkSelectionProps {
|
|
30
|
-
showPagination: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface BulkSelectionDropdownItemsType {
|
|
33
|
-
locator: BulkSelectionEvents;
|
|
34
|
-
label: string;
|
|
35
|
-
isSelected: boolean;
|
|
36
|
-
icon: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
|
|
37
|
-
}
|
|
38
|
-
export interface BulkSelectionDropdownItemsProps<T> extends BulkSelectionDropdownItemsType, Pick<UseBulkSelectionReturnType<T>, 'handleBulkSelection'> {
|
|
39
|
-
}
|
|
40
|
-
export declare enum SelectAllDialogStatus {
|
|
41
|
-
OPEN = "OPEN",
|
|
42
|
-
CLOSED = "CLOSED"
|
|
43
|
-
}
|
|
44
|
-
export type BulkSelectionIdentifiersType<T> = Record<string | number, T>;
|
|
45
|
-
export interface UseBulkSelectionProps<T> {
|
|
46
|
-
/**
|
|
47
|
-
* Response from API, assuming structure to be array of objects with key and values
|
|
48
|
-
* This will the given ids on current page
|
|
49
|
-
*/
|
|
50
|
-
identifiers: T;
|
|
51
|
-
/**
|
|
52
|
-
* Act as buffer between select all across pages and select all on page state
|
|
53
|
-
*/
|
|
54
|
-
getSelectAllDialogStatus: () => SelectAllDialogStatus;
|
|
55
|
-
children?: React.ReactNode;
|
|
56
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BulkSelection';
|
package/dist/Shared/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Components';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<rect x="2" y="2" width="11.2" height="11.2" rx="2" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3
|
-
<path d="M15.4667 5.86621V11.4662C15.4667 13.6754 13.6758 15.4662 11.4667 15.4662H5.8667" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
-
<path d="M10.35 5.84961L6.85004 9.34945L5.10004 7.59961" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</svg>
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<rect x="2" y="2" width="12" height="12" rx="2" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3
|
-
<path d="M11.2083 5.95801L7.12498 10.0412L5.08331 7.99967" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
-
</svg>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
|
|
2
|
-
<defs>
|
|
3
|
-
<path id="a" class="stroke-color" d="M18.295 5.705a.997.997 0 0 0-1.41 0L12 10.59 7.115 5.705a.997.997 0 1 0-1.41 1.41L10.59 12l-4.885 4.885a.997.997 0 1 0 1.41 1.41L12 13.41l4.885 4.885a.997.997 0 0 0 1.41-1.41L13.41 12l4.885-4.885a.997.997 0 0 0 0-1.41z"/>
|
|
4
|
-
</defs>
|
|
5
|
-
<g fill="none" fill-rule="evenodd">
|
|
6
|
-
<path d=""/>
|
|
7
|
-
<use fill="#999" xlink:href="#a"/>
|
|
8
|
-
</g>
|
|
9
|
-
</svg>
|
|
@@ -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, isChecked, checkboxValue, getSelectedIdentifiersCount } = useBulkSelection<T>()
|
|
13
|
-
const areOptionsSelected = getSelectedIdentifiersCount() > 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,171 +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
|
-
isBulkSelectionApplied: false,
|
|
20
|
-
getSelectedIdentifiersCount: noop,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
export const useBulkSelection = <T,>() => {
|
|
24
|
-
const context = useContext<UseBulkSelectionReturnType<T>>(BulkSelectionContext)
|
|
25
|
-
if (!context) {
|
|
26
|
-
throw new Error(BULK_SELECTION_CONTEXT_ERROR)
|
|
27
|
-
}
|
|
28
|
-
return context
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const BulkSelectionProvider = <T,>({
|
|
32
|
-
children,
|
|
33
|
-
identifiers,
|
|
34
|
-
getSelectAllDialogStatus,
|
|
35
|
-
}: UseBulkSelectionProps<T>) => {
|
|
36
|
-
const [selectedIdentifiers, setSelectedIdentifiers] = useState<T>({} as T)
|
|
37
|
-
|
|
38
|
-
const isBulkSelectionApplied = selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
|
|
39
|
-
|
|
40
|
-
const getSelectedIdentifiersCount = () => Object.keys(selectedIdentifiers).length
|
|
41
|
-
|
|
42
|
-
const setIdentifiersAfterClear = (newIdentifiers: T, selectedIds: (number | string)[]) => {
|
|
43
|
-
const _newIdentifiers = JSON.parse(JSON.stringify(newIdentifiers))
|
|
44
|
-
selectedIds.forEach((id) => {
|
|
45
|
-
delete _newIdentifiers[id]
|
|
46
|
-
})
|
|
47
|
-
setSelectedIdentifiers(_newIdentifiers)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const setIdentifiersAfterPageSelection = (baseObject: T) => {
|
|
51
|
-
const _selectedIdentifiers = JSON.parse(JSON.stringify(selectedIdentifiers))
|
|
52
|
-
// removing bulk selection across pages if present
|
|
53
|
-
if (isBulkSelectionApplied) {
|
|
54
|
-
delete _selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
setSelectedIdentifiers({
|
|
58
|
-
..._selectedIdentifiers,
|
|
59
|
-
...baseObject,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const handleBulkSelection = ({ action, data }: HandleBulkSelectionType<T>) => {
|
|
64
|
-
const selectedIds = data?.identifierIds ?? []
|
|
65
|
-
const identifierObject = data?.identifierObject ?? {}
|
|
66
|
-
|
|
67
|
-
switch (action) {
|
|
68
|
-
case BulkSelectionEvents.CLEAR_ALL_SELECTIONS:
|
|
69
|
-
setSelectedIdentifiers({} as T)
|
|
70
|
-
break
|
|
71
|
-
|
|
72
|
-
case BulkSelectionEvents.CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION: {
|
|
73
|
-
setIdentifiersAfterClear(identifiers, selectedIds)
|
|
74
|
-
break
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
case BulkSelectionEvents.CLEAR_IDENTIFIERS: {
|
|
78
|
-
setIdentifiersAfterClear(selectedIdentifiers, selectedIds)
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
case BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES: {
|
|
83
|
-
if (isBulkSelectionApplied) {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
const selectedIdentifiersLength = getSelectedIdentifiersCount()
|
|
87
|
-
// This is for showing a modal dialog if applicable to confirm if bulk selection is to be applied
|
|
88
|
-
// Do note that the 'getSelectAllDialogStatus' should be called after the length check explicitly
|
|
89
|
-
// otherwise the modal will open each time
|
|
90
|
-
if (selectedIdentifiersLength > 0 && getSelectAllDialogStatus() === SelectAllDialogStatus.OPEN) {
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
setSelectedIdentifiers({
|
|
95
|
-
[SELECT_ALL_ACROSS_PAGES_LOCATOR]: true,
|
|
96
|
-
} as unknown as T)
|
|
97
|
-
break
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
case BulkSelectionEvents.CLEAR_SELECTIONS_AND_SELECT_ALL_ACROSS_PAGES:
|
|
101
|
-
setSelectedIdentifiers({
|
|
102
|
-
[SELECT_ALL_ACROSS_PAGES_LOCATOR]: true,
|
|
103
|
-
} as unknown as T)
|
|
104
|
-
break
|
|
105
|
-
|
|
106
|
-
case BulkSelectionEvents.SELECT_ALL_ON_PAGE: {
|
|
107
|
-
setIdentifiersAfterPageSelection(identifiers)
|
|
108
|
-
break
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
case BulkSelectionEvents.SELECT_IDENTIFIER: {
|
|
112
|
-
setIdentifiersAfterPageSelection(identifierObject as T)
|
|
113
|
-
break
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
default:
|
|
117
|
-
throw new Error(getInvalidActionMessage(action))
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const getBulkSelectionCheckboxValues = (): GetBulkSelectionCheckboxValuesType => {
|
|
122
|
-
const selectedIdentifiersArray = Object.keys(selectedIdentifiers)
|
|
123
|
-
if (selectedIdentifiersArray.length === 0) {
|
|
124
|
-
return {
|
|
125
|
-
isChecked: false,
|
|
126
|
-
checkboxValue: CHECKBOX_VALUE.CHECKED,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// if selectedIdentifiers contains select all across pages locator then it means all are selected
|
|
131
|
-
if (isBulkSelectionApplied) {
|
|
132
|
-
return {
|
|
133
|
-
isChecked: true,
|
|
134
|
-
checkboxValue: CHECKBOX_VALUE.BULK_CHECKED,
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// if all the identifiers are selected then CHECKED else intermediate
|
|
139
|
-
const areAllPresentIdentifiersSelected = Object.keys(identifiers).every(
|
|
140
|
-
(identifierId) => selectedIdentifiers[identifierId],
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
if (areAllPresentIdentifiersSelected) {
|
|
144
|
-
return {
|
|
145
|
-
isChecked: true,
|
|
146
|
-
checkboxValue: CHECKBOX_VALUE.CHECKED,
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
isChecked: true,
|
|
152
|
-
checkboxValue: CHECKBOX_VALUE.INTERMEDIATE,
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const { isChecked, checkboxValue } = getBulkSelectionCheckboxValues()
|
|
157
|
-
|
|
158
|
-
const value = useMemo(
|
|
159
|
-
() => ({
|
|
160
|
-
selectedIdentifiers,
|
|
161
|
-
handleBulkSelection,
|
|
162
|
-
isChecked,
|
|
163
|
-
checkboxValue,
|
|
164
|
-
isBulkSelectionApplied,
|
|
165
|
-
getSelectedIdentifiersCount,
|
|
166
|
-
}),
|
|
167
|
-
[selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue, getSelectedIdentifiersCount],
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
return <BulkSelectionContext.Provider value={value}>{children}</BulkSelectionContext.Provider>
|
|
171
|
-
}
|
|
@@ -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,67 +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
|
-
isBulkSelectionApplied: boolean
|
|
30
|
-
getSelectedIdentifiersCount: () => number
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface BulkSelectionProps {
|
|
34
|
-
showPagination: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface BulkSelectionDropdownItemsType {
|
|
38
|
-
locator: BulkSelectionEvents
|
|
39
|
-
label: string
|
|
40
|
-
isSelected: boolean
|
|
41
|
-
icon: React.FunctionComponent<React.SVGProps<SVGSVGElement>>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface BulkSelectionDropdownItemsProps<T>
|
|
45
|
-
extends BulkSelectionDropdownItemsType,
|
|
46
|
-
Pick<UseBulkSelectionReturnType<T>, 'handleBulkSelection'> {}
|
|
47
|
-
|
|
48
|
-
export enum SelectAllDialogStatus {
|
|
49
|
-
OPEN = 'OPEN',
|
|
50
|
-
CLOSED = 'CLOSED',
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// This type is intended to be used with UseBulkSelectionProps, e.g, UseBulkSelectionProps<BulkSelectionIdentifiersType<boolean>>
|
|
54
|
-
export type BulkSelectionIdentifiersType<T> = Record<string | number, T>
|
|
55
|
-
|
|
56
|
-
export interface UseBulkSelectionProps<T> {
|
|
57
|
-
/**
|
|
58
|
-
* Response from API, assuming structure to be array of objects with key and values
|
|
59
|
-
* This will the given ids on current page
|
|
60
|
-
*/
|
|
61
|
-
identifiers: T
|
|
62
|
-
/**
|
|
63
|
-
* Act as buffer between select all across pages and select all on page state
|
|
64
|
-
*/
|
|
65
|
-
getSelectAllDialogStatus: () => SelectAllDialogStatus
|
|
66
|
-
children?: React.ReactNode
|
|
67
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BulkSelection'
|
package/src/Shared/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Components'
|