@devtron-labs/devtron-fe-common-lib 0.0.58-beta-6 → 0.0.58-beta-7
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/Constants.d.ts +1 -14
- package/dist/Common/Hooks/index.d.ts +0 -1
- package/dist/Common/Types.d.ts +3 -2
- package/dist/Common/index.d.ts +0 -1
- package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.d.ts +7 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/Descriptor.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/Footer.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/constants.d.ts +47 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +7 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +13 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +282 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +12 -0
- package/dist/Pages/GlobalConfigurations/index.d.ts +1 -0
- package/dist/Pages/index.d.ts +1 -0
- package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +4 -0
- package/dist/Shared/Components/APIResponseHandler/index.d.ts +2 -0
- package/dist/Shared/Components/APIResponseHandler/types.d.ts +37 -0
- package/dist/Shared/Components/ReactSelect/index.d.ts +1 -0
- package/dist/Shared/Components/ReactSelect/utils.d.ts +12 -0
- package/dist/Shared/Components/index.d.ts +2 -0
- package/dist/Shared/index.d.ts +2 -0
- package/dist/Shared/validations.d.ts +7 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1123 -339
- package/package.json +1 -1
- package/src/Assets/Icon/ic-cpu.svg +4 -0
- package/src/Assets/Icon/ic-memory.svg +3 -0
- package/src/Assets/Icon/ic-timer.svg +3 -0
- package/src/Common/BreadCrumb/Types.ts +0 -1
- package/src/Common/Checkbox.tsx +1 -0
- package/src/Common/Constants.ts +3 -18
- package/src/Common/CustomInput/CustomInput.tsx +2 -1
- package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
- package/src/Common/Hooks/index.ts +0 -1
- package/src/Common/RJSF/utils.ts +3 -0
- package/src/Common/SearchBar/SearchBar.component.tsx +26 -13
- package/src/Common/SearchBar/searchBar.scss +1 -1
- package/src/Common/Types.ts +2 -1
- package/src/Common/index.ts +0 -1
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +121 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +44 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +104 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.tsx +55 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.tsx +32 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx +38 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +45 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +4 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +136 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +184 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +335 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +494 -0
- package/src/Pages/GlobalConfigurations/index.ts +1 -0
- package/src/Pages/index.ts +1 -0
- package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +39 -0
- package/src/Shared/Components/APIResponseHandler/index.ts +2 -0
- package/src/Shared/Components/APIResponseHandler/types.tsx +39 -0
- package/src/Shared/Components/ReactSelect/index.ts +1 -0
- package/src/Shared/Components/ReactSelect/utils.tsx +97 -0
- package/src/Shared/Components/index.ts +2 -0
- package/src/Shared/index.ts +2 -0
- package/src/Shared/validations.tsx +72 -0
- package/src/index.ts +3 -1
- package/dist/Common/Hooks/useUrlFilters/constants.d.ts +0 -8
- package/dist/Common/Hooks/useUrlFilters/index.d.ts +0 -2
- package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -6
- package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +0 -32
- package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +0 -18
- package/dist/Common/SortableTableHeaderCell/index.d.ts +0 -2
- package/dist/Common/SortableTableHeaderCell/types.d.ts +0 -8
- package/src/Assets/Icon/ic-arrow-up-down.svg +0 -3
- package/src/Assets/Icon/ic-sort-arrow-down.svg +0 -3
- package/src/Common/Hooks/useUrlFilters/constants.ts +0 -9
- package/src/Common/Hooks/useUrlFilters/index.ts +0 -2
- package/src/Common/Hooks/useUrlFilters/types.ts +0 -6
- package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +0 -120
- package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +0 -44
- package/src/Common/SortableTableHeaderCell/index.ts +0 -2
- package/src/Common/SortableTableHeaderCell/types.ts +0 -9
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface ValidationResponseType {
|
|
2
|
+
isValid: boolean
|
|
3
|
+
message?: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const validateName = (name: string): ValidationResponseType => {
|
|
7
|
+
if (!/^.{3,50}$/.test(name)) {
|
|
8
|
+
return {
|
|
9
|
+
isValid: false,
|
|
10
|
+
message: 'Minimum 3 and maximum 50 characters allowed',
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!/^[a-z0-9-._]+$/.test(name)) {
|
|
15
|
+
return {
|
|
16
|
+
isValid: false,
|
|
17
|
+
message: 'Only lowercase alphanumeric characters, -, _ or . allowed',
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!/^(?![-._]).*[^-._]$/.test(name)) {
|
|
22
|
+
return {
|
|
23
|
+
isValid: false,
|
|
24
|
+
message: 'Cannot start/end with -, _ or .',
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
isValid: true,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const validateDescription = (description: string): ValidationResponseType => {
|
|
34
|
+
if (description?.length > 300) {
|
|
35
|
+
return {
|
|
36
|
+
isValid: false,
|
|
37
|
+
message: 'Maximum 300 characters are allowed',
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
isValid: true,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const validateRequiredPositiveNumber = (value: string | Number): ValidationResponseType => {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return {
|
|
49
|
+
isValid: false,
|
|
50
|
+
message: 'This field is required',
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TODO: Look if regex is available for this, since 0002 is not a valid number
|
|
55
|
+
if (!/^\d+(\.\d+)?$/.test(value.toString())) {
|
|
56
|
+
return {
|
|
57
|
+
isValid: false,
|
|
58
|
+
message: 'This field should be a valid positive number',
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (Number(value) <= 0) {
|
|
63
|
+
return {
|
|
64
|
+
isValid: false,
|
|
65
|
+
message: 'Only positive numbers are allowed',
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
isValid: true,
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_PAGE_NUMBER = 1;
|
|
2
|
-
export declare const URL_FILTER_KEYS: {
|
|
3
|
-
readonly PAGE_SIZE: "pageSize";
|
|
4
|
-
readonly PAGE_NUMBER: "pageNumber";
|
|
5
|
-
readonly SEARCH_KEY: "searchKey";
|
|
6
|
-
readonly SORT_BY: "sortBy";
|
|
7
|
-
readonly SORT_ORDER: "sortOrder";
|
|
8
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SortingOrder } from '../../Constants';
|
|
2
|
-
import { UseUrlFiltersProps } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Generic hook for implementing URL based filters.
|
|
5
|
-
* eg: pagination, search, sort.
|
|
6
|
-
*
|
|
7
|
-
* The exposed handlers can be consumed directly without the need for explicit state management
|
|
8
|
-
*
|
|
9
|
-
* @example Default Usage:
|
|
10
|
-
* ```tsx
|
|
11
|
-
* const { pageSize, changePage, ...rest } = useUrlFilters()
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @example Usage with custom type for sort keys and initial sort key:
|
|
15
|
-
* ```tsx
|
|
16
|
-
* const { sortBy, sortOrder } = useUrlFilters<'email' | 'name'>({ initialSortKey: 'email' })
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
declare const useUrlFilters: <T = string>({ initialSortKey }?: UseUrlFiltersProps<T>) => {
|
|
21
|
-
pageSize: number;
|
|
22
|
-
changePage: (page: number) => void;
|
|
23
|
-
changePageSize: (_pageSize: number) => void;
|
|
24
|
-
searchKey: string;
|
|
25
|
-
handleSearch: (searchTerm: string) => void;
|
|
26
|
-
offset: number;
|
|
27
|
-
sortBy: T;
|
|
28
|
-
sortOrder: SortingOrder;
|
|
29
|
-
handleSorting: (_sortBy: T) => void;
|
|
30
|
-
clearFilters: () => void;
|
|
31
|
-
};
|
|
32
|
-
export default useUrlFilters;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { SortableTableHeaderCellProps } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Reusable component for the table header cell with support for sorting icons
|
|
5
|
-
*
|
|
6
|
-
* @example Usage
|
|
7
|
-
* ```tsx
|
|
8
|
-
* <SortableTableHeaderCell
|
|
9
|
-
* isSorted={currentSortedCell === 'cell'}
|
|
10
|
-
* triggerSorting={() => {}}
|
|
11
|
-
* sortOrder={SortingOrder.ASC}
|
|
12
|
-
* title="Header Cell"
|
|
13
|
-
* disabled={isDisabled}
|
|
14
|
-
* />
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
declare const SortableTableHeaderCell: ({ isSorted, triggerSorting, sortOrder, title, disabled, }: SortableTableHeaderCellProps) => JSX.Element;
|
|
18
|
-
export default SortableTableHeaderCell;
|
|
@@ -1,3 +0,0 @@
|
|
|
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>
|
|
@@ -1,120 +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 } 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> = {}) => {
|
|
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
|
-
}
|
|
83
|
-
|
|
84
|
-
const handleSorting = (_sortBy: T) => {
|
|
85
|
-
let order: SortingOrder
|
|
86
|
-
if (_sortBy === sortBy && sortOrder === SortingOrder.ASC) {
|
|
87
|
-
order = SortingOrder.DESC
|
|
88
|
-
} else {
|
|
89
|
-
order = SortingOrder.ASC
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
_updateSearchParam(SORT_BY, _sortBy)
|
|
93
|
-
_updateSearchParam(SORT_ORDER, order)
|
|
94
|
-
|
|
95
|
-
// Reset page number on sorting change
|
|
96
|
-
_resetPageNumber()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const clearFilters = () => {
|
|
100
|
-
Object.values(URL_FILTER_KEYS).forEach((key) => {
|
|
101
|
-
searchParams.delete(key)
|
|
102
|
-
})
|
|
103
|
-
history.replace({ search: searchParams.toString() })
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
pageSize,
|
|
108
|
-
changePage,
|
|
109
|
-
changePageSize,
|
|
110
|
-
searchKey,
|
|
111
|
-
handleSearch,
|
|
112
|
-
offset,
|
|
113
|
-
sortBy,
|
|
114
|
-
sortOrder,
|
|
115
|
-
handleSorting,
|
|
116
|
-
clearFilters,
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
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
|