@devtron-labs/devtron-fe-common-lib 0.0.62-beta-3 → 0.0.62-beta-5
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 -0
- package/dist/Common/Hooks/useUrlFilters/types.d.ts +35 -0
- package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +4 -0
- package/dist/Pages/GlobalConfigurations/Authorization/index.d.ts +1 -0
- package/dist/Pages/GlobalConfigurations/Authorization/types.d.ts +23 -0
- 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 +50 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +7 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +6 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +286 -0
- package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +12 -0
- package/dist/Pages/GlobalConfigurations/index.d.ts +1 -0
- package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +4 -0
- package/dist/Shared/Components/APIResponseHandler/constants.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/BulkSelection/constants.d.ts +1 -0
- package/dist/Shared/Components/FilterChips/FilterChips.component.d.ts +7 -0
- package/dist/Shared/Components/FilterChips/index.d.ts +2 -0
- package/dist/Shared/Components/FilterChips/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 +3 -0
- package/dist/Shared/Helpers.d.ts +16 -0
- package/dist/Shared/index.d.ts +2 -0
- package/dist/Shared/validations.d.ts +8 -0
- package/dist/index.js +1221 -170
- 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 +2 -1
- package/src/Common/CustomInput/CustomInput.tsx +2 -1
- package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
- package/src/Common/Hooks/useUrlFilters/types.ts +35 -0
- package/src/Common/RJSF/utils.ts +2 -0
- package/src/Common/SearchBar/searchBar.scss +1 -1
- package/src/Pages/GlobalConfigurations/Authorization/constants.ts +5 -0
- package/src/Pages/GlobalConfigurations/Authorization/index.ts +1 -0
- package/src/Pages/GlobalConfigurations/Authorization/types.ts +25 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +128 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +44 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +106 -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 +45 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +56 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +4 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +139 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +167 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +339 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +507 -0
- package/src/Pages/GlobalConfigurations/index.ts +1 -0
- package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +41 -0
- package/src/Shared/Components/APIResponseHandler/constants.tsx +5 -0
- package/src/Shared/Components/APIResponseHandler/index.ts +2 -0
- package/src/Shared/Components/APIResponseHandler/types.tsx +39 -0
- package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +3 -1
- package/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +12 -1
- package/src/Shared/Components/BulkSelection/constants.tsx +1 -0
- package/src/Shared/Components/FilterChips/FilterChips.component.tsx +100 -0
- package/src/Shared/Components/FilterChips/index.ts +2 -0
- package/src/Shared/Components/FilterChips/types.ts +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 +3 -0
- package/src/Shared/Helpers.tsx +29 -0
- package/src/Shared/index.ts +2 -0
- package/src/Shared/validations.tsx +130 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ReactComponent as CloseIcon } from '../../../Assets/Icon/ic-close.svg'
|
|
2
|
+
import { noop } from '../../../Common'
|
|
3
|
+
import { FilterChipProps, FilterChipsProps } from './types'
|
|
4
|
+
|
|
5
|
+
const FilterChip = ({
|
|
6
|
+
label,
|
|
7
|
+
value,
|
|
8
|
+
handleRemoveFilter,
|
|
9
|
+
getFormattedLabel = noop,
|
|
10
|
+
getFormattedValue = noop,
|
|
11
|
+
}: FilterChipProps) => {
|
|
12
|
+
const removeFilter = () => {
|
|
13
|
+
handleRemoveFilter(label, value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const labelToDisplay = getFormattedLabel(label) ?? label
|
|
17
|
+
|
|
18
|
+
const valueToDisplay = getFormattedValue(label, value) ?? value
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="flexbox flex-align-center br-4 dc__border dc__bg-n50 pl-6 pr-6 pt-2 pb-2 dc__user-select-none h-24 dc__gap-6 fs-12 lh-20 cn-9 fw-4">
|
|
22
|
+
<span className="fw-6 dc__capitalize">{labelToDisplay}</span>
|
|
23
|
+
<span className="dc__divider h-24" />
|
|
24
|
+
<span className="dc__ellipsis-right">{valueToDisplay}</span>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
className="flex p-0 dc__transparent"
|
|
28
|
+
onClick={removeFilter}
|
|
29
|
+
aria-label="Remove filter"
|
|
30
|
+
>
|
|
31
|
+
<CloseIcon className="icon-dim-12 icon-use-fill-n6" />
|
|
32
|
+
</button>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Component for rendering the applied filter chips
|
|
39
|
+
*/
|
|
40
|
+
const FilterChips = ({
|
|
41
|
+
filterConfig,
|
|
42
|
+
clearFilters,
|
|
43
|
+
onRemoveFilter,
|
|
44
|
+
getFormattedLabel,
|
|
45
|
+
getFormattedValue,
|
|
46
|
+
}: FilterChipsProps) => {
|
|
47
|
+
const handleRemoveFilter = (filterKey, valueToRemove) => {
|
|
48
|
+
const updatedFilterConfig = JSON.parse(JSON.stringify(filterConfig))
|
|
49
|
+
if (Array.isArray(filterConfig[filterKey])) {
|
|
50
|
+
onRemoveFilter({
|
|
51
|
+
...updatedFilterConfig,
|
|
52
|
+
[filterKey]: updatedFilterConfig[filterKey].filter((val) => val !== valueToRemove),
|
|
53
|
+
})
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
if (filterKey in updatedFilterConfig) {
|
|
57
|
+
delete updatedFilterConfig[filterKey]
|
|
58
|
+
onRemoveFilter(updatedFilterConfig)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const chips = Object.entries(filterConfig).filter(([, value]) => (Array.isArray(value) ? value.length : !!value))
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
chips.length > 0 && (
|
|
66
|
+
<div className="flexbox pt-6 pb-6 flex-wrap dc__gap-8">
|
|
67
|
+
{chips.map(([filterKey, filterValue]) =>
|
|
68
|
+
Array.isArray(filterValue) ? (
|
|
69
|
+
filterValue.map((filter) => (
|
|
70
|
+
<FilterChip
|
|
71
|
+
key={`${filterKey}-${filter}`}
|
|
72
|
+
label={filterKey}
|
|
73
|
+
value={filter}
|
|
74
|
+
handleRemoveFilter={handleRemoveFilter}
|
|
75
|
+
getFormattedLabel={getFormattedLabel}
|
|
76
|
+
getFormattedValue={getFormattedValue}
|
|
77
|
+
/>
|
|
78
|
+
))
|
|
79
|
+
) : (
|
|
80
|
+
<FilterChip
|
|
81
|
+
key={filterKey}
|
|
82
|
+
label={filterKey}
|
|
83
|
+
value={filterValue}
|
|
84
|
+
handleRemoveFilter={handleRemoveFilter}
|
|
85
|
+
getFormattedLabel={getFormattedLabel}
|
|
86
|
+
getFormattedValue={getFormattedValue}
|
|
87
|
+
/>
|
|
88
|
+
),
|
|
89
|
+
)}
|
|
90
|
+
<div className="flex">
|
|
91
|
+
<button type="button" className="cta text fs-13 lh-20-imp h-20 p-0-imp" onClick={clearFilters}>
|
|
92
|
+
Clear All Filters
|
|
93
|
+
</button>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default FilterChips
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface FilterChipProps {
|
|
4
|
+
/**
|
|
5
|
+
* Filter label
|
|
6
|
+
*/
|
|
7
|
+
label: string
|
|
8
|
+
/**
|
|
9
|
+
* Corresponding value of the filter
|
|
10
|
+
*/
|
|
11
|
+
value: unknown
|
|
12
|
+
/**
|
|
13
|
+
* Callback handler for removing the filter
|
|
14
|
+
*/
|
|
15
|
+
handleRemoveFilter: (label: string, valueToRemove: unknown) => void
|
|
16
|
+
/**
|
|
17
|
+
* If passed, the label will be formatted accordingly
|
|
18
|
+
*/
|
|
19
|
+
getFormattedLabel?: (filterKey: string) => ReactNode
|
|
20
|
+
/**
|
|
21
|
+
* If passed, the label will be formatted accordingly
|
|
22
|
+
*/
|
|
23
|
+
getFormattedValue?: (filterKey: string, filterValue: unknown) => ReactNode
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface FilterChipsProps extends Pick<FilterChipProps, 'getFormattedLabel' | 'getFormattedValue'> {
|
|
27
|
+
/**
|
|
28
|
+
* Current filter configuration
|
|
29
|
+
*/
|
|
30
|
+
filterConfig: Record<string, unknown>
|
|
31
|
+
/**
|
|
32
|
+
* Callback handler for removing the filters
|
|
33
|
+
*/
|
|
34
|
+
clearFilters: () => void
|
|
35
|
+
/**
|
|
36
|
+
* Handler for removing a applied filter
|
|
37
|
+
*/
|
|
38
|
+
onRemoveFilter: (filterConfig: Record<string, unknown>) => void
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils'
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import Tippy from '@tippyjs/react'
|
|
2
|
+
import { components } from 'react-select'
|
|
3
|
+
import { stopPropagation } from '../../../Common'
|
|
4
|
+
|
|
5
|
+
export const getCommonSelectStyle = (styleOverrides = {}) => ({
|
|
6
|
+
menuList: (base) => ({
|
|
7
|
+
...base,
|
|
8
|
+
paddingTop: 0,
|
|
9
|
+
paddingBottom: 0,
|
|
10
|
+
}),
|
|
11
|
+
control: (base, state) => ({
|
|
12
|
+
...base,
|
|
13
|
+
minHeight: '32px',
|
|
14
|
+
boxShadow: 'none',
|
|
15
|
+
backgroundColor: 'var(--N50)',
|
|
16
|
+
border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)',
|
|
17
|
+
cursor: 'pointer',
|
|
18
|
+
}),
|
|
19
|
+
option: (base, state) => ({
|
|
20
|
+
...base,
|
|
21
|
+
color: 'var(--N900)',
|
|
22
|
+
backgroundColor: state.isFocused ? 'var(--N100)' : 'white',
|
|
23
|
+
padding: '10px 12px',
|
|
24
|
+
}),
|
|
25
|
+
dropdownIndicator: (base, state) => ({
|
|
26
|
+
...base,
|
|
27
|
+
color: 'var(--N400)',
|
|
28
|
+
padding: '0 8px',
|
|
29
|
+
transition: 'all .2s ease',
|
|
30
|
+
transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
31
|
+
}),
|
|
32
|
+
valueContainer: (base) => ({
|
|
33
|
+
...base,
|
|
34
|
+
padding: '0 8px',
|
|
35
|
+
fontWeight: '400',
|
|
36
|
+
}),
|
|
37
|
+
loadingMessage: (base) => ({
|
|
38
|
+
...base,
|
|
39
|
+
color: 'var(--N600)',
|
|
40
|
+
}),
|
|
41
|
+
noOptionsMessage: (base) => ({
|
|
42
|
+
...base,
|
|
43
|
+
color: 'var(--N600)',
|
|
44
|
+
}),
|
|
45
|
+
...styleOverrides,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const getCustomOptionBackgroundColor = (isSelected: boolean, isFocused: boolean) => {
|
|
49
|
+
if (isSelected) {
|
|
50
|
+
return 'var(--B100)'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isFocused) {
|
|
54
|
+
return 'var(--N50)'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return 'var(--white)'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const getCustomOptionSelectionStyle =
|
|
61
|
+
(styleOverrides = {}) =>
|
|
62
|
+
(base, state) => ({
|
|
63
|
+
...base,
|
|
64
|
+
backgroundColor: getCustomOptionBackgroundColor(state.isSelected, state.isFocused),
|
|
65
|
+
color: state.isSelected ? 'var(--B500)' : 'var(--N900)',
|
|
66
|
+
textOverflow: 'ellipsis',
|
|
67
|
+
fontWeight: '500',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
textAlign: 'left',
|
|
70
|
+
whiteSpace: 'nowrap',
|
|
71
|
+
cursor: 'pointer',
|
|
72
|
+
fontSize: '13px',
|
|
73
|
+
...styleOverrides,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
export const SelectOption = (props: any) => {
|
|
77
|
+
const { selectProps, data, showTippy, style, placement, tippyContent, tippyClass } = props
|
|
78
|
+
selectProps.styles.option = getCustomOptionSelectionStyle(style)
|
|
79
|
+
const getOption = () => (
|
|
80
|
+
<div onClick={stopPropagation}>
|
|
81
|
+
<components.Option {...props} />
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return showTippy ? (
|
|
86
|
+
<Tippy
|
|
87
|
+
className={tippyClass || 'default-white'}
|
|
88
|
+
arrow={false}
|
|
89
|
+
placement={placement || 'right'}
|
|
90
|
+
content={tippyContent || data.label}
|
|
91
|
+
>
|
|
92
|
+
{getOption()}
|
|
93
|
+
</Tippy>
|
|
94
|
+
) : (
|
|
95
|
+
getOption()
|
|
96
|
+
)
|
|
97
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface HighlightSearchTextProps {
|
|
2
|
+
/**
|
|
3
|
+
* The text to be highlighted
|
|
4
|
+
*/
|
|
5
|
+
searchText: string
|
|
6
|
+
/**
|
|
7
|
+
* The whole text string
|
|
8
|
+
*/
|
|
9
|
+
text: string
|
|
10
|
+
/**
|
|
11
|
+
* The classes to be applied to the highlighted text
|
|
12
|
+
*/
|
|
13
|
+
highlightClasses?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Disabling default export since this is a helper function and we would have to export a lot of functions in future.
|
|
17
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
18
|
+
export const highlightSearchText = ({ searchText, text, highlightClasses }: HighlightSearchTextProps): string => {
|
|
19
|
+
if (!searchText) {
|
|
20
|
+
return text
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const regex = new RegExp(searchText, 'gi')
|
|
25
|
+
return text.replace(regex, (match) => `<span class="${highlightClasses}">${match}</span>`)
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return text
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/Shared/index.ts
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export interface ValidationResponseType {
|
|
2
|
+
isValid: boolean
|
|
3
|
+
message?: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const MESSAGES = {
|
|
7
|
+
PROVIDE_A_NUMBER: 'Please provide a number',
|
|
8
|
+
LOWERCASE_ALPHANUMERIC: 'Only lowercase alphanumeric characters, -, _ or . allowed',
|
|
9
|
+
CAN_NOT_START_END_WITH_SEPARATORS: 'Cannot start/end with -, _ or .',
|
|
10
|
+
getMinMaxCharMessage: (min: number, max: number) => `Minimum ${min} and maximum ${max} characters allowed`,
|
|
11
|
+
getMaxCharMessage: (max: number) => `Maximum ${max} characters are allowed`,
|
|
12
|
+
VALID_POSITIVE_NUMBER: 'This field should be a valid positive number',
|
|
13
|
+
VALID_POSITIVE_INTEGER: 'This field should be a valid positive integer',
|
|
14
|
+
MAX_SAFE_INTEGER: `Maximum allowed value is ${Number.MAX_SAFE_INTEGER}`,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const MAX_DESCRIPTION_LENGTH = 300
|
|
18
|
+
|
|
19
|
+
export const validateName = (name: string): ValidationResponseType => {
|
|
20
|
+
if (!/^.{3,50}$/.test(name)) {
|
|
21
|
+
return {
|
|
22
|
+
isValid: false,
|
|
23
|
+
message: MESSAGES.getMinMaxCharMessage(3, 50),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!/^[a-z0-9-._]+$/.test(name)) {
|
|
28
|
+
return {
|
|
29
|
+
isValid: false,
|
|
30
|
+
message: MESSAGES.LOWERCASE_ALPHANUMERIC,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!/^(?![-._]).*[^-._]$/.test(name)) {
|
|
35
|
+
return {
|
|
36
|
+
isValid: false,
|
|
37
|
+
message: MESSAGES.CAN_NOT_START_END_WITH_SEPARATORS,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
isValid: true,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const validateDescription = (description: string): ValidationResponseType => {
|
|
47
|
+
if (description?.length > MAX_DESCRIPTION_LENGTH) {
|
|
48
|
+
return {
|
|
49
|
+
isValid: false,
|
|
50
|
+
message: MESSAGES.getMaxCharMessage(MAX_DESCRIPTION_LENGTH),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
isValid: true,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const validateRequiredPositiveNumber = (value: string | number): ValidationResponseType => {
|
|
60
|
+
if (!value) {
|
|
61
|
+
return {
|
|
62
|
+
isValid: false,
|
|
63
|
+
message: MESSAGES.PROVIDE_A_NUMBER,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// TODO: Look if regex is available for this, since 0002 is not a valid number
|
|
68
|
+
if (!/^\d+(\.\d+)?$/.test(value.toString())) {
|
|
69
|
+
return {
|
|
70
|
+
isValid: false,
|
|
71
|
+
message: MESSAGES.VALID_POSITIVE_NUMBER,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const numericValue = Number(value)
|
|
76
|
+
|
|
77
|
+
if (numericValue > Number.MAX_SAFE_INTEGER) {
|
|
78
|
+
return {
|
|
79
|
+
isValid: false,
|
|
80
|
+
message: MESSAGES.MAX_SAFE_INTEGER,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (numericValue <= 0) {
|
|
85
|
+
return {
|
|
86
|
+
isValid: false,
|
|
87
|
+
message: MESSAGES.VALID_POSITIVE_NUMBER,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
isValid: true,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const validateRequiredPositiveInteger = (value: string | number): ValidationResponseType => {
|
|
97
|
+
if (!value) {
|
|
98
|
+
return {
|
|
99
|
+
isValid: false,
|
|
100
|
+
message: MESSAGES.PROVIDE_A_NUMBER,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!/^\d+$/.test(value.toString())) {
|
|
105
|
+
return {
|
|
106
|
+
isValid: false,
|
|
107
|
+
message: MESSAGES.VALID_POSITIVE_INTEGER,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const numericValue = Number(value)
|
|
112
|
+
|
|
113
|
+
if (numericValue > Number.MAX_SAFE_INTEGER) {
|
|
114
|
+
return {
|
|
115
|
+
isValid: false,
|
|
116
|
+
message: MESSAGES.MAX_SAFE_INTEGER,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (numericValue <= 0) {
|
|
121
|
+
return {
|
|
122
|
+
isValid: false,
|
|
123
|
+
message: MESSAGES.VALID_POSITIVE_INTEGER,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
isValid: true,
|
|
129
|
+
}
|
|
130
|
+
}
|