@devtron-labs/devtron-fe-common-lib 0.0.60 → 0.0.61-beta-1
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/Api.d.ts +9 -0
- package/dist/Common/Constants.d.ts +14 -0
- package/dist/Common/DraggableWrapper/types.d.ts +4 -1
- package/dist/Common/Helper.d.ts +1 -4
- package/dist/Common/Hooks/index.d.ts +1 -0
- package/dist/Common/Hooks/useUrlFilters/constants.d.ts +8 -0
- package/dist/Common/Hooks/useUrlFilters/index.d.ts +2 -0
- package/dist/Common/Hooks/useUrlFilters/types.d.ts +19 -0
- package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +20 -0
- package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +18 -0
- package/dist/Common/SortableTableHeaderCell/index.d.ts +2 -0
- package/dist/Common/SortableTableHeaderCell/types.d.ts +25 -0
- package/dist/Common/Types.d.ts +16 -3
- package/dist/Common/index.d.ts +1 -0
- package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +15 -0
- package/dist/Pages/GlobalConfigurations/Authorization/index.d.ts +1 -0
- package/dist/Pages/GlobalConfigurations/index.d.ts +1 -0
- package/dist/Pages/index.d.ts +1 -0
- package/dist/Shared/Components/BulkSelection/BulkSelection.d.ts +4 -0
- package/dist/Shared/Components/BulkSelection/BulkSelectionDropdownItems.d.ts +4 -0
- package/dist/Shared/Components/BulkSelection/BulkSelectionProvider.d.ts +4 -0
- package/dist/Shared/Components/BulkSelection/constants.d.ts +9 -0
- package/dist/Shared/Components/BulkSelection/index.d.ts +4 -0
- package/dist/Shared/Components/BulkSelection/types.d.ts +54 -0
- package/dist/Shared/Components/index.d.ts +1 -0
- package/dist/Shared/index.d.ts +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +669 -182
- package/package.json +1 -1
- package/src/Assets/Icon/ic-arrow-up-down.svg +3 -0
- package/src/Assets/Icon/ic-check-all.svg +5 -0
- package/src/Assets/Icon/ic-check-square.svg +4 -0
- package/src/Assets/Icon/ic-close.svg +9 -0
- package/src/Assets/Icon/ic-sort-arrow-down.svg +3 -0
- package/src/Common/Api.ts +21 -0
- package/src/Common/Constants.ts +17 -1
- package/src/Common/DraggableWrapper/types.ts +4 -1
- package/src/Common/Helper.tsx +16 -30
- package/src/Common/Hooks/index.ts +1 -0
- package/src/Common/Hooks/useUrlFilters/constants.ts +9 -0
- package/src/Common/Hooks/useUrlFilters/index.ts +2 -0
- package/src/Common/Hooks/useUrlFilters/types.ts +21 -0
- package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +121 -0
- package/src/Common/SearchBar/SearchBar.component.tsx +23 -11
- package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +44 -0
- package/src/Common/SortableTableHeaderCell/index.ts +2 -0
- package/src/Common/SortableTableHeaderCell/types.ts +26 -0
- package/src/Common/Types.ts +16 -2
- package/src/Common/index.ts +1 -0
- package/src/Pages/GlobalConfigurations/Authorization/constants.ts +16 -0
- package/src/Pages/GlobalConfigurations/Authorization/index.ts +1 -0
- package/src/Pages/GlobalConfigurations/index.ts +1 -0
- package/src/Pages/index.ts +1 -0
- package/src/Shared/Components/BulkSelection/BulkSelection.tsx +77 -0
- package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +31 -0
- package/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +163 -0
- package/src/Shared/Components/BulkSelection/constants.tsx +13 -0
- package/src/Shared/Components/BulkSelection/index.ts +4 -0
- package/src/Shared/Components/BulkSelection/types.tsx +65 -0
- package/src/Shared/Components/index.ts +1 -0
- package/src/Shared/index.ts +1 -0
- package/src/index.ts +3 -1
package/package.json
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
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>
|
|
@@ -0,0 +1,4 @@
|
|
|
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>
|
|
@@ -0,0 +1,9 @@
|
|
|
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>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M3.5 7.50009L6.00004 10.0001M6.00004 10.0001L8.5 7.50054M6.00004 10.0001V2" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
3
|
+
</svg>
|
package/src/Common/Api.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ServerErrors } from './ServerError'
|
|
2
2
|
import { FALLBACK_REQUEST_TIMEOUT, Host, URLS } from './Constants'
|
|
3
3
|
import { ResponseType, APIOptions } from './Types'
|
|
4
|
+
import { MutableRefObject } from 'react'
|
|
4
5
|
|
|
5
6
|
const responseMessages = {
|
|
6
7
|
100: 'Continue',
|
|
@@ -228,3 +229,23 @@ export const get = (url: string, options?: APIOptions): Promise<ResponseType> =>
|
|
|
228
229
|
export const trash = (url: string, data?: object, options?: APIOptions): Promise<ResponseType> => {
|
|
229
230
|
return fetchInTime(url, 'DELETE', data, options)
|
|
230
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Aborts the previous request before triggering next request
|
|
235
|
+
*/
|
|
236
|
+
export const abortPreviousRequests = <T,>(
|
|
237
|
+
callback: () => Promise<T>,
|
|
238
|
+
abortControllerRef: MutableRefObject<AbortController>,
|
|
239
|
+
): Promise<T> => {
|
|
240
|
+
abortControllerRef.current.abort()
|
|
241
|
+
// eslint-disable-next-line no-param-reassign
|
|
242
|
+
abortControllerRef.current = new AbortController()
|
|
243
|
+
return callback()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Returns true if the error is due to a aborted request
|
|
248
|
+
*/
|
|
249
|
+
export const getIsRequestAborted = (error) =>
|
|
250
|
+
// The 0 code is common for aborted and blocked requests
|
|
251
|
+
error && error.code === 0 && error.message === 'The user aborted a request.'
|
package/src/Common/Constants.ts
CHANGED
|
@@ -251,4 +251,20 @@ export const MAX_Z_INDEX = 2147483647
|
|
|
251
251
|
export const SELECTED_APPROVAL_TAB_STATE = {
|
|
252
252
|
APPROVAL: 'approval',
|
|
253
253
|
PENDING: 'pending',
|
|
254
|
-
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export enum SortingOrder {
|
|
257
|
+
/**
|
|
258
|
+
* Ascending order
|
|
259
|
+
*/
|
|
260
|
+
ASC = 'ASC',
|
|
261
|
+
/**
|
|
262
|
+
* Descending order
|
|
263
|
+
*/
|
|
264
|
+
DESC = 'DESC',
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Base page size for pagination
|
|
269
|
+
*/
|
|
270
|
+
export const DEFAULT_BASE_PAGE_SIZE = 20
|
|
@@ -8,7 +8,10 @@ export enum DraggablePositionVariant {
|
|
|
8
8
|
|
|
9
9
|
export interface DraggableWrapperProps {
|
|
10
10
|
children: ReactNode
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Support for passing the direct value or calc functions as well
|
|
13
|
+
*/
|
|
14
|
+
zIndex?: number | string
|
|
12
15
|
positionVariant?: DraggablePositionVariant
|
|
13
16
|
/**
|
|
14
17
|
* 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
|
@@ -499,27 +499,18 @@ export const getFilteredChartVersions = (charts, selectedChartType) => {
|
|
|
499
499
|
chartRefId: item.chartRefId,
|
|
500
500
|
}))
|
|
501
501
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
// It recursively removes empty object keys and empty array keys
|
|
502
|
+
function removeEmptyObjectKeysAndNullValues(obj) {
|
|
503
|
+
// It recursively removes empty object keys and array values that are null
|
|
505
504
|
for (let key in obj) {
|
|
506
505
|
if (Array.isArray(obj[key])) {
|
|
506
|
+
if (obj[key].length === 0) continue
|
|
507
|
+
obj[key] = obj[key].filter((item) => item !== null)
|
|
507
508
|
// Check if the array is empty
|
|
508
|
-
if (obj[key].length
|
|
509
|
-
obj[key]
|
|
510
|
-
if (element === null || (typeof element === 'object' && Object.keys(element).length === 0))
|
|
511
|
-
obj[key].splice(index, 1)
|
|
512
|
-
else removeEmptyObjectKeysAndNullValues(element, originaljsonCopy[key][index])
|
|
513
|
-
})
|
|
514
|
-
}
|
|
515
|
-
if (obj[key].length === 0 && originaljsonCopy[key].length !== 0) {
|
|
516
|
-
delete obj[key]
|
|
509
|
+
if (obj[key].length === 0) {
|
|
510
|
+
delete obj[key] // Delete the key if the array is empty
|
|
517
511
|
}
|
|
518
512
|
} else if (obj[key] && typeof obj[key] === 'object') {
|
|
519
|
-
if (
|
|
520
|
-
removeEmptyObjectKeysAndNullValues(obj[key], originaljsonCopy[key]) &&
|
|
521
|
-
Object.keys(originaljsonCopy[key]).length !== 0
|
|
522
|
-
) {
|
|
513
|
+
if (removeEmptyObjectKeysAndNullValues(obj[key])) {
|
|
523
514
|
delete obj[key]
|
|
524
515
|
}
|
|
525
516
|
} else if (obj[key] === undefined) {
|
|
@@ -529,25 +520,20 @@ function removeEmptyObjectKeysAndNullValues(obj, originaljsonCopy) {
|
|
|
529
520
|
return Object.keys(obj).length === 0
|
|
530
521
|
}
|
|
531
522
|
|
|
532
|
-
export function getUnlockedJSON(json, jsonPathArray
|
|
533
|
-
if (!jsonPathArray.length) return { newDocument: json, removedPatches: [] }
|
|
534
|
-
|
|
523
|
+
export function getUnlockedJSON(json, jsonPathArray) {
|
|
535
524
|
const jsonCopy = JSON.parse(JSON.stringify(json))
|
|
536
|
-
const originaljsonCopy = JSON.parse(JSON.stringify(json))
|
|
537
|
-
let removedPatches = []
|
|
538
525
|
let patches = jsonPathArray.flatMap((jsonPath) => {
|
|
539
526
|
const pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' })
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
return { op: 'remove', path: result.pointer }
|
|
546
|
-
})
|
|
527
|
+
return pathsToRemove.map((result) =>
|
|
528
|
+
Array.isArray(result.parent)
|
|
529
|
+
? { op: 'replace', path: result.pointer, value: null }
|
|
530
|
+
: { op: 'remove', path: result.pointer },
|
|
531
|
+
)
|
|
547
532
|
})
|
|
548
533
|
let newDocument = jsonpatch.applyPatch(jsonCopy, patches).newDocument
|
|
549
|
-
|
|
550
|
-
|
|
534
|
+
|
|
535
|
+
removeEmptyObjectKeysAndNullValues(newDocument)
|
|
536
|
+
return newDocument
|
|
551
537
|
}
|
|
552
538
|
|
|
553
539
|
export function getLockedJSON(json, jsonPathArray: string[]) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SortingOrder } from '../../Constants'
|
|
2
|
+
|
|
3
|
+
export interface UseUrlFiltersProps<T> {
|
|
4
|
+
/**
|
|
5
|
+
* The key on which the sorting should be applied
|
|
6
|
+
*/
|
|
7
|
+
initialSortKey?: T
|
|
8
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEvent, useCallback, useRef, useState, KeyboardEvent } from 'react'
|
|
1
|
+
import { ChangeEvent, useCallback, useRef, useState, KeyboardEvent, useEffect } from 'react'
|
|
2
2
|
import { ReactComponent as Search } from '../../Assets/Icon/ic-search.svg'
|
|
3
3
|
import { ReactComponent as Clear } from '../../Assets/Icon/ic-error-cross.svg'
|
|
4
4
|
import { SearchBarProps } from './types'
|
|
@@ -55,9 +55,28 @@ const SearchBar = ({
|
|
|
55
55
|
debounceTimeout,
|
|
56
56
|
])
|
|
57
57
|
|
|
58
|
+
// assuming initialSearchText will change if we are changing history otherwise will be constant and will not change
|
|
59
|
+
// since on changing history we expect to make api call using useAsync so not applying handleEnter
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
inputRef.current.value = initialSearchText
|
|
62
|
+
setShowClearButton(!!initialSearchText)
|
|
63
|
+
}, [initialSearchText])
|
|
64
|
+
|
|
65
|
+
const _applySearch = (value: string) => {
|
|
66
|
+
handleSearchChange(value)
|
|
67
|
+
handleEnter(value)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const clearSearch = () => {
|
|
71
|
+
inputRef.current.value = ''
|
|
72
|
+
_applySearch('')
|
|
73
|
+
setShowClearButton(false)
|
|
74
|
+
}
|
|
75
|
+
|
|
58
76
|
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
59
77
|
const { value } = e.target
|
|
60
78
|
setShowClearButton(!!value)
|
|
79
|
+
|
|
61
80
|
if (shouldDebounce) {
|
|
62
81
|
debouncedSearchChange(value)
|
|
63
82
|
} else {
|
|
@@ -65,25 +84,17 @@ const SearchBar = ({
|
|
|
65
84
|
}
|
|
66
85
|
}
|
|
67
86
|
|
|
68
|
-
const _applySearch = (value: string) => {
|
|
69
|
-
handleSearchChange(value)
|
|
70
|
-
handleEnter(value)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
87
|
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
74
88
|
const { key } = e
|
|
75
89
|
|
|
76
90
|
if (key === 'Enter') {
|
|
91
|
+
e.preventDefault()
|
|
77
92
|
const inputTarget = e.target as HTMLInputElement
|
|
78
93
|
const value = inputTarget.value.trim()
|
|
79
94
|
_applySearch(value)
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
const clearSearch = () => {
|
|
84
|
-
inputRef.current.value = ''
|
|
85
|
-
_applySearch('')
|
|
86
|
-
}
|
|
87
98
|
return (
|
|
88
99
|
<div className={containerClassName}>
|
|
89
100
|
<div className="search-bar bc-n50 focus-within-border-b5 dc__hover-border-n300 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32">
|
|
@@ -94,13 +105,14 @@ const SearchBar = ({
|
|
|
94
105
|
type="text"
|
|
95
106
|
{...inputProps}
|
|
96
107
|
defaultValue={initialSearchText}
|
|
97
|
-
className={`search-bar__input dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ${
|
|
108
|
+
className={`search-bar__input bc-n50 dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ${
|
|
98
109
|
showClearButton ? 'pr-30' : 'pr-10'
|
|
99
110
|
}`}
|
|
100
111
|
onChange={handleChange}
|
|
101
112
|
onKeyDown={handleKeyDown}
|
|
102
113
|
ref={inputRef}
|
|
103
114
|
/>
|
|
115
|
+
{/* TODO: Sync with product since it should have ic-enter in case of not applied */}
|
|
104
116
|
{showClearButton && (
|
|
105
117
|
<button
|
|
106
118
|
className="flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5"
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
package/src/Common/Types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode, CSSProperties } from 'react'
|
|
2
2
|
import { Placement } from 'tippy.js'
|
|
3
3
|
import { ImageComment, ReleaseTag } from './ImageTags.Types'
|
|
4
|
-
import { DockerConfigOverrideType, TaskErrorObj } from '.'
|
|
4
|
+
import { DockerConfigOverrideType, SortingOrder, TaskErrorObj } from '.'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Generic response type object with support for overriding the result type
|
|
@@ -51,11 +51,13 @@ export interface Teams {
|
|
|
51
51
|
export enum CHECKBOX_VALUE {
|
|
52
52
|
CHECKED = 'CHECKED',
|
|
53
53
|
INTERMEDIATE = 'INTERMEDIATE',
|
|
54
|
+
BULK_CHECKED = 'BULK_CHECKED',
|
|
54
55
|
}
|
|
55
56
|
export interface CheckboxProps {
|
|
56
57
|
onChange: (event) => void
|
|
57
58
|
isChecked: boolean
|
|
58
|
-
|
|
59
|
+
// FIXME: Need to replace this CHECKBOX_VALUE enum, and replace string instances in dashboard
|
|
60
|
+
value: 'CHECKED' | 'INTERMEDIATE' | 'BULK_CHECKED'
|
|
59
61
|
disabled?: boolean
|
|
60
62
|
tabIndex?: number
|
|
61
63
|
rootClassName?: string
|
|
@@ -762,3 +764,15 @@ export interface EdgeNodeType {
|
|
|
762
764
|
export interface EdgeEndNodeType extends EdgeNodeType {
|
|
763
765
|
userApprovalConfig?: UserApprovalConfigType
|
|
764
766
|
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Search params for sorting configuration
|
|
770
|
+
*
|
|
771
|
+
* Note: Either both sortOrder and sortBy are required or none
|
|
772
|
+
*/
|
|
773
|
+
export type SortingParams<T = string> =
|
|
774
|
+
| {
|
|
775
|
+
sortOrder: SortingOrder
|
|
776
|
+
sortBy: T
|
|
777
|
+
}
|
|
778
|
+
| { sortOrder?: never; sortBy?: never }
|
package/src/Common/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from './Checkbox'
|
|
|
27
27
|
export { default as EmptyState } from './EmptyState/EmptyState'
|
|
28
28
|
export { default as GenericEmptyState } from './EmptyState/GenericEmptyState'
|
|
29
29
|
export * from './SearchBar'
|
|
30
|
+
export * from './SortableTableHeaderCell'
|
|
30
31
|
export { default as Toggle } from './Toggle/Toggle'
|
|
31
32
|
export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
|
|
32
33
|
export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constants'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Authorization'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GlobalConfigurations'
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|