@devtron-labs/devtron-fe-common-lib 0.0.58-beta-3 → 0.0.58-beta-4
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 +9 -0
- package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
- package/dist/Common/CustomInput/Types.d.ts +1 -0
- package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
- package/dist/Common/Helper.d.ts +1 -4
- package/dist/Common/Types.d.ts +4 -2
- 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 +48 -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 +281 -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 +1160 -193
- 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 +11 -1
- package/src/Common/CustomInput/CustomInput.tsx +6 -5
- package/src/Common/CustomInput/Types.ts +1 -0
- package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
- package/src/Common/EmptyState/GenericEmptyState.tsx +45 -13
- package/src/Common/Helper.tsx +16 -30
- 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 +3 -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 +99 -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 +137 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +183 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +334 -0
- package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +489 -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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { FormEvent, FunctionComponent } from 'react'
|
|
2
|
+
import ReactSelect from 'react-select'
|
|
3
|
+
import { BuildInfraFormActionProps } from './types'
|
|
4
|
+
import { OptionType } from '../../../Common'
|
|
5
|
+
import { unitSelectorStyles } from './utils'
|
|
6
|
+
import { BUILD_INFRA_INPUT_CONSTRAINTS } from './constants'
|
|
7
|
+
import { ReactComponent as ErrorIcon } from '../../../Assets/Icon/ic-warning.svg'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* In case need arise for variants break this CustomInput and Select as a separate component
|
|
11
|
+
*/
|
|
12
|
+
const BuildInfraFormAction: FunctionComponent<BuildInfraFormActionProps> = ({
|
|
13
|
+
actionType,
|
|
14
|
+
label,
|
|
15
|
+
placeholder,
|
|
16
|
+
error,
|
|
17
|
+
isRequired,
|
|
18
|
+
profileUnitsMap,
|
|
19
|
+
handleProfileInputChange,
|
|
20
|
+
currentUnitName,
|
|
21
|
+
currentValue,
|
|
22
|
+
}) => {
|
|
23
|
+
const handleUnitChange = (selectedUnit: OptionType) => {
|
|
24
|
+
const data = {
|
|
25
|
+
unit: selectedUnit.label,
|
|
26
|
+
value: currentValue,
|
|
27
|
+
}
|
|
28
|
+
handleProfileInputChange({ action: actionType, data })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const handleInputChange = (e: FormEvent<HTMLInputElement>) => {
|
|
32
|
+
const data = {
|
|
33
|
+
unit: currentUnitName,
|
|
34
|
+
value: e.currentTarget.value,
|
|
35
|
+
}
|
|
36
|
+
handleProfileInputChange({ action: actionType, data })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const unitOptions: OptionType[] =
|
|
40
|
+
Object.values(profileUnitsMap)?.map((unit) => ({
|
|
41
|
+
label: unit.name,
|
|
42
|
+
value: unit.name,
|
|
43
|
+
})) ?? []
|
|
44
|
+
const currentUnit = unitOptions.find((unit) => unit.value === currentUnitName)
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className="flexbox-col dc__gap-4 dc__mxw-420 w-100 dc__align-start">
|
|
48
|
+
<label
|
|
49
|
+
htmlFor={`${actionType}-input`}
|
|
50
|
+
className={`fs-13 fw-4 lh-20 cn-7 ${isRequired ? 'dc__required-field' : ''}`}
|
|
51
|
+
>
|
|
52
|
+
{label}
|
|
53
|
+
</label>
|
|
54
|
+
<div className="w-100 flexbox dc__align-items-center">
|
|
55
|
+
<div className="flex-grow-1">
|
|
56
|
+
<input
|
|
57
|
+
data-testid={actionType}
|
|
58
|
+
name={actionType}
|
|
59
|
+
type="number"
|
|
60
|
+
step={BUILD_INFRA_INPUT_CONSTRAINTS.STEP}
|
|
61
|
+
min={BUILD_INFRA_INPUT_CONSTRAINTS.MIN}
|
|
62
|
+
className="form__input dc__no-right-border dc__no-right-radius"
|
|
63
|
+
placeholder={placeholder}
|
|
64
|
+
value={currentValue}
|
|
65
|
+
onChange={handleInputChange}
|
|
66
|
+
required={isRequired}
|
|
67
|
+
autoComplete="off"
|
|
68
|
+
id={`${actionType}-input`}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
{profileUnitsMap && (
|
|
73
|
+
<ReactSelect
|
|
74
|
+
name={`${actionType}-unit`}
|
|
75
|
+
className="bcn-0 dc__mxw-120"
|
|
76
|
+
options={unitOptions}
|
|
77
|
+
value={currentUnit}
|
|
78
|
+
onChange={handleUnitChange}
|
|
79
|
+
isSearchable={false}
|
|
80
|
+
components={{
|
|
81
|
+
IndicatorSeparator: null,
|
|
82
|
+
ClearIndicator: null,
|
|
83
|
+
}}
|
|
84
|
+
styles={unitSelectorStyles()}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{error && (
|
|
90
|
+
<div className="form__error">
|
|
91
|
+
<ErrorIcon className="form__icon form__icon--error" />
|
|
92
|
+
{error}
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
</div>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default BuildInfraFormAction
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FormEvent, FunctionComponent } from 'react'
|
|
2
|
+
import { BuildInfraFormItemProps, BuildInfraInheritActions } from './types'
|
|
3
|
+
import { CHECKBOX_VALUE, Checkbox } from '../../../Common'
|
|
4
|
+
|
|
5
|
+
const BuildInfraFormItem: FunctionComponent<BuildInfraFormItemProps> = ({
|
|
6
|
+
heading,
|
|
7
|
+
marker: Marker,
|
|
8
|
+
children,
|
|
9
|
+
isInheriting,
|
|
10
|
+
showDivider,
|
|
11
|
+
handleProfileInputChange,
|
|
12
|
+
locator,
|
|
13
|
+
isDefaultProfile,
|
|
14
|
+
}) => {
|
|
15
|
+
const handleActivationChange = (e: FormEvent<HTMLInputElement>) => {
|
|
16
|
+
const { checked } = e.currentTarget
|
|
17
|
+
const action = (checked ? `activate_${locator}` : `de_activate_${locator}`) as BuildInfraInheritActions
|
|
18
|
+
handleProfileInputChange({ action })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const renderMarker = () => {
|
|
22
|
+
if (isDefaultProfile) {
|
|
23
|
+
return <Marker className="icon-dim-20 dc__no-shrink" />
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Checkbox
|
|
28
|
+
onChange={handleActivationChange}
|
|
29
|
+
isChecked={!isInheriting}
|
|
30
|
+
value={CHECKBOX_VALUE.CHECKED}
|
|
31
|
+
dataTestId={`${locator}_marker`}
|
|
32
|
+
/>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// If in configuration active is false, means it is inheriting values from other profile
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<div className="flexbox-col dc__gap-8 w-100">
|
|
40
|
+
<div className="flexbox dc__gap-12 dc__align-start w-100">
|
|
41
|
+
{renderMarker()}
|
|
42
|
+
|
|
43
|
+
<div className="flexbox-col dc__gap-8 w-100">
|
|
44
|
+
{heading}
|
|
45
|
+
{!isInheriting && children}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
{showDivider && <div className="w-100 dc__border-bottom-n1" />}
|
|
51
|
+
</>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default BuildInfraFormItem
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FormEvent, FunctionComponent } from 'react'
|
|
2
|
+
import { BuildInfraMetaConfigTypes, BuildInfraInputFieldComponentProps } from './types'
|
|
3
|
+
import { CustomInput } from '../../../Common'
|
|
4
|
+
import { BUILD_INFRA_TEXT } from './constants'
|
|
5
|
+
|
|
6
|
+
const BuildInfraProfileNameField: FunctionComponent<BuildInfraInputFieldComponentProps> = ({
|
|
7
|
+
handleProfileInputChange,
|
|
8
|
+
currentValue,
|
|
9
|
+
error,
|
|
10
|
+
}) => {
|
|
11
|
+
const handleChange = (e: FormEvent<HTMLInputElement>) => {
|
|
12
|
+
handleProfileInputChange({ action: BuildInfraMetaConfigTypes.NAME, data: { value: e.currentTarget.value } })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div className="flexbox-col dc__gap-4 w-100 dc__align-start">
|
|
17
|
+
<CustomInput
|
|
18
|
+
name="profile-name"
|
|
19
|
+
label={BUILD_INFRA_TEXT.PROFILE_LABEL}
|
|
20
|
+
labelClassName="m-0 dc__required-field fs-13 fw-4 lh-20 cn-7"
|
|
21
|
+
placeholder={BUILD_INFRA_TEXT.PROFILE_PLACEHOLDER}
|
|
22
|
+
value={currentValue}
|
|
23
|
+
onChange={handleChange}
|
|
24
|
+
error={error}
|
|
25
|
+
required
|
|
26
|
+
inputWrapClassName="w-100"
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default BuildInfraProfileNameField
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DescriptorProps } from './types'
|
|
2
|
+
import { BreadCrumb, TippyCustomized, TippyTheme } from '../../../Common'
|
|
3
|
+
import { ReactComponent as QuestionFilled } from '../../../Assets/Icon/ic-help.svg'
|
|
4
|
+
import { ReactComponent as ICHelpOutline } from '../../../Assets/Icon/ic-help-outline.svg'
|
|
5
|
+
import { BUILD_INFRA_TEXT } from './constants'
|
|
6
|
+
|
|
7
|
+
const Descriptor = ({ additionalContainerClasses, breadCrumbs, children }: DescriptorProps) => (
|
|
8
|
+
<div className={`flexbox dc__content-space dc__align-items-center w-100 ${additionalContainerClasses ?? ''}`}>
|
|
9
|
+
<div className="flexbox dc__align-items-center dc__gap-4">
|
|
10
|
+
<BreadCrumb breadcrumbs={breadCrumbs} />
|
|
11
|
+
|
|
12
|
+
<TippyCustomized
|
|
13
|
+
theme={TippyTheme.white}
|
|
14
|
+
className="w-300 h-100 dc__align-left"
|
|
15
|
+
placement="right"
|
|
16
|
+
Icon={QuestionFilled}
|
|
17
|
+
iconClass="fcv-5"
|
|
18
|
+
infoText={BUILD_INFRA_TEXT.EDIT_DEFAULT_TOOLTIP}
|
|
19
|
+
heading={BUILD_INFRA_TEXT.HEADING}
|
|
20
|
+
showCloseButton
|
|
21
|
+
trigger="click"
|
|
22
|
+
interactive
|
|
23
|
+
>
|
|
24
|
+
<button
|
|
25
|
+
className="p-0 h-20 dc__no-background dc__no-border dc__tab-focus"
|
|
26
|
+
type="button"
|
|
27
|
+
aria-label="build-infra-info"
|
|
28
|
+
>
|
|
29
|
+
<ICHelpOutline className="icon-dim-20" />
|
|
30
|
+
</button>
|
|
31
|
+
</TippyCustomized>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
{children}
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
export default Descriptor
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FunctionComponent, ReactElement } from 'react'
|
|
2
|
+
import Tippy from '@tippyjs/react'
|
|
3
|
+
import { BUILD_INFRA_TEXT } from './constants'
|
|
4
|
+
import { FooterProps } from './types'
|
|
5
|
+
import { ConditionalWrap, Progressing } from '../../../Common'
|
|
6
|
+
|
|
7
|
+
const Footer: FunctionComponent<FooterProps> = ({ disabled, hideCancelButton, editProfile, loading }) => {
|
|
8
|
+
const disableMessage = disabled
|
|
9
|
+
? BUILD_INFRA_TEXT.SUBMIT_BUTTON_TIPPY.INVALID_INPUT
|
|
10
|
+
: BUILD_INFRA_TEXT.SUBMIT_BUTTON_TIPPY.REQUEST_IN_PROGRESS
|
|
11
|
+
|
|
12
|
+
const getButtonText = () => {
|
|
13
|
+
if (editProfile) {
|
|
14
|
+
return BUILD_INFRA_TEXT.EDIT_SUBMIT
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return BUILD_INFRA_TEXT.SAVE_SUBMIT
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const renderTippy = (children: ReactElement) => (
|
|
21
|
+
<Tippy content={disableMessage} placement="top" className="default-tt" arrow={false}>
|
|
22
|
+
{children}
|
|
23
|
+
</Tippy>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className="flex pl pr pb pt h-64 dc__gap-12 dc__border-top dc__content-start">
|
|
28
|
+
<ConditionalWrap condition={disabled || loading} wrap={renderTippy}>
|
|
29
|
+
<div className="flexbox dc__align-items-center">
|
|
30
|
+
<button type="submit" className="cta submit h-32 flex" disabled={disabled || loading}>
|
|
31
|
+
{loading ? <Progressing size={16} /> : getButtonText()}
|
|
32
|
+
</button>
|
|
33
|
+
</div>
|
|
34
|
+
</ConditionalWrap>
|
|
35
|
+
|
|
36
|
+
{!hideCancelButton && (
|
|
37
|
+
<button type="button" className="cta cancel h-32 flex">
|
|
38
|
+
{BUILD_INFRA_TEXT.EDIT_CANCEL}
|
|
39
|
+
</button>
|
|
40
|
+
)}
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default Footer
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
In case someone wants to add a new build infrastructure field, the following steps should be followed:
|
|
2
|
+
- Update the BUILD_INFRA_FORM_FIELDS, in constants.tsx
|
|
3
|
+
- Add BuildInfraConfigTypes, BuildInfraLocators, BuildInfraInheritActions(If any) in types.tsx
|
|
4
|
+
- In utils.tsx, update the handleProfileInputChange and validation functions accordingly
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { ReactComponent as ICCpu } from '../../../Assets/Icon/ic-cpu.svg'
|
|
2
|
+
import { ReactComponent as ICMemory } from '../../../Assets/Icon/ic-memory.svg'
|
|
3
|
+
import { ReactComponent as ICTimer } from '../../../Assets/Icon/ic-timer.svg'
|
|
4
|
+
import { UseBreadcrumbProps } from '../../../Common/BreadCrumb/Types'
|
|
5
|
+
import {
|
|
6
|
+
BuildInfraConfigTypes,
|
|
7
|
+
BuildInfraFormFieldType,
|
|
8
|
+
BuildInfraLocators,
|
|
9
|
+
BuildInfraMetaConfigTypes,
|
|
10
|
+
ProfileInputErrorType,
|
|
11
|
+
BuildInfraProfileBase,
|
|
12
|
+
BuildInfraProfileVariants,
|
|
13
|
+
HandleProfileInputChangeType,
|
|
14
|
+
} from './types'
|
|
15
|
+
|
|
16
|
+
export const BUILD_INFRA_TEXT = {
|
|
17
|
+
HEADING: 'Build Infra Configuration',
|
|
18
|
+
EDIT_SUBMIT: 'Save changes',
|
|
19
|
+
SAVE_SUBMIT: 'Save',
|
|
20
|
+
EDIT_CANCEL: 'Cancel',
|
|
21
|
+
EDIT_DEFAULT_TOOLTIP:
|
|
22
|
+
'Efficiently control infrastructure settings such as CPU, Memory, and Build timeout for your build pipelines. Streamline resource management to optimise build time and cost effortlessly.',
|
|
23
|
+
DESCRIPTION_LABEL: 'Description',
|
|
24
|
+
DESCRIPTION_PLACEHOLDER: 'Enter a description here',
|
|
25
|
+
PROFILE_LABEL: 'Profile name',
|
|
26
|
+
PROFILE_PLACEHOLDER: 'Eg. Java or Node',
|
|
27
|
+
INHERITING_HEADING_DESCRIPTION: 'Inheriting from default',
|
|
28
|
+
SUBMIT_BUTTON_TIPPY: {
|
|
29
|
+
INVALID_INPUT: 'Valid input is required for all mandatory fields.',
|
|
30
|
+
REQUEST_IN_PROGRESS: 'Request in progress.',
|
|
31
|
+
},
|
|
32
|
+
VALIDATE_REQUEST_LIMIT: {
|
|
33
|
+
NEGATIVE_REQUEST: 'Request should be a positive number.',
|
|
34
|
+
NEGATIVE_LIMIT: 'Limit should be a positive number.',
|
|
35
|
+
REQUEST_LESS_THAN_LIMIT: 'Request should be less than or equal to limit.',
|
|
36
|
+
REQUEST_TOO_BIG: 'Request is too big to compute.',
|
|
37
|
+
LIMIT_TOO_BIG: 'Limit is too big to compute.',
|
|
38
|
+
REQUEST_DECIMAL_PLACES: 'Request should be upto 2 decimal places.',
|
|
39
|
+
LIMIT_DECIMAL_PLACES: 'Limit should be upto 2 decimal places.',
|
|
40
|
+
},
|
|
41
|
+
getInvalidActionMessage: (action: HandleProfileInputChangeType['action']) => `Invalid action type: ${action}`,
|
|
42
|
+
getSubmitSuccessMessage: (profileName: string, isEdited: boolean) =>
|
|
43
|
+
`${profileName} is ${isEdited ? 'updated' : 'created'}`,
|
|
44
|
+
PROFILE_NOT_FOUND: {
|
|
45
|
+
title: 'Profile not found',
|
|
46
|
+
subTitle: 'The profile you are looking for does not exist.',
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const BUILD_INFRA_BREADCRUMB: UseBreadcrumbProps = {
|
|
51
|
+
alias: {
|
|
52
|
+
'global-config': null,
|
|
53
|
+
'build-infra': {
|
|
54
|
+
component: <h2 className="m-0 cn-9 fs-16 fw-6 lh-32">{BUILD_INFRA_TEXT.HEADING}</h2>,
|
|
55
|
+
linked: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const BUILD_INFRA_FORM_FIELDS: BuildInfraFormFieldType[] = [
|
|
61
|
+
{
|
|
62
|
+
heading: <h3 className="m-0 cn-9 fs-13 fw-6 lh-20">CPU (Request - Limit)</h3>,
|
|
63
|
+
marker: ICCpu,
|
|
64
|
+
actions: [
|
|
65
|
+
{
|
|
66
|
+
actionType: BuildInfraConfigTypes.CPU_REQUEST,
|
|
67
|
+
label: 'Request',
|
|
68
|
+
placeholder: 'Type CPU request',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
actionType: BuildInfraConfigTypes.CPU_LIMIT,
|
|
72
|
+
label: 'Limit',
|
|
73
|
+
placeholder: 'Type CPU limit',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
locator: BuildInfraLocators.CPU,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
heading: <h3 className="m-0 cn-9 fs-13 fw-6 lh-20">Memory (Request - Limit)</h3>,
|
|
80
|
+
marker: ICMemory,
|
|
81
|
+
actions: [
|
|
82
|
+
{
|
|
83
|
+
actionType: BuildInfraConfigTypes.MEMORY_REQUEST,
|
|
84
|
+
label: 'Request',
|
|
85
|
+
placeholder: 'Type memory request',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
actionType: BuildInfraConfigTypes.MEMORY_LIMIT,
|
|
89
|
+
label: 'Limit',
|
|
90
|
+
placeholder: 'Type memory limit',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
locator: BuildInfraLocators.MEMORY,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
heading: <h3 className="m-0 cn-9 fs-13 fw-6 lh-20">Build timeout</h3>,
|
|
97
|
+
marker: ICTimer,
|
|
98
|
+
actions: [
|
|
99
|
+
{
|
|
100
|
+
actionType: BuildInfraConfigTypes.BUILD_TIMEOUT,
|
|
101
|
+
label: 'Timeout',
|
|
102
|
+
placeholder: 'Type build timeout',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
locator: BuildInfraLocators.BUILD_TIMEOUT,
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
// TODO: Handle the case of create profile to disable save button initially and enable it when all the fields are filled
|
|
110
|
+
export const PROFILE_INPUT_ERROR_FIELDS = {
|
|
111
|
+
...Object.fromEntries(
|
|
112
|
+
Object.keys({ ...BuildInfraConfigTypes, ...BuildInfraMetaConfigTypes }).map((key) => [key, null]),
|
|
113
|
+
),
|
|
114
|
+
} as ProfileInputErrorType
|
|
115
|
+
|
|
116
|
+
// All fields in BuildInfraConfigTypes are required and name in BuildInfraMetaConfigTypes is required
|
|
117
|
+
export const REQUIRED_INPUT_FIELDS = [...Object.keys(BuildInfraConfigTypes), BuildInfraMetaConfigTypes.NAME]
|
|
118
|
+
|
|
119
|
+
export const DEFAULT_PROFILE_NAME = 'default'
|
|
120
|
+
|
|
121
|
+
export const CREATE_PROFILE_BASE_VALUE: BuildInfraProfileBase = {
|
|
122
|
+
name: '',
|
|
123
|
+
description: '',
|
|
124
|
+
type: BuildInfraProfileVariants.NORMAL,
|
|
125
|
+
appCount: 0,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const CREATE_VIEW_CHECKED_CONFIGS = {
|
|
129
|
+
[BuildInfraConfigTypes.CPU_REQUEST]: true,
|
|
130
|
+
[BuildInfraConfigTypes.CPU_LIMIT]: true,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const BUILD_INFRA_INPUT_CONSTRAINTS = {
|
|
134
|
+
STEP: 0.01,
|
|
135
|
+
MIN: 0,
|
|
136
|
+
DECIMAL_PLACES: 2,
|
|
137
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as BuildInfraDescriptor } from './Descriptor'
|
|
2
|
+
export { default as BuildInfraFooter } from './Footer'
|
|
3
|
+
export { default as BuildInfraConfigForm } from './BuildInfraConfigForm'
|
|
4
|
+
export * from './services'
|
|
5
|
+
export * from './utils'
|
|
6
|
+
export * from './types'
|
|
7
|
+
export * from './constants'
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// TODO: Remove these comment on API integration
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
+
import { ROUTES, ResponseType, get, put, showError } from '../../../Common'
|
|
5
|
+
import { CREATE_PROFILE_BASE_VALUE, CREATE_VIEW_CHECKED_CONFIGS } from './constants'
|
|
6
|
+
import {
|
|
7
|
+
BuildInfraConfigTypes,
|
|
8
|
+
BuildInfraConfigurationMapType,
|
|
9
|
+
BuildInfraConfigurationType,
|
|
10
|
+
BuildInfraProfileAPIResponseType,
|
|
11
|
+
BuildInfraProfileBase,
|
|
12
|
+
BuildInfraProfileResponseDataType,
|
|
13
|
+
BuildInfraProfileResponseType,
|
|
14
|
+
BuildInfraProfileTransformerType,
|
|
15
|
+
BuildInfraProfileVariants,
|
|
16
|
+
BuildInfraUnitsMapType,
|
|
17
|
+
ConfigurationUnitMapType,
|
|
18
|
+
CreateBuildInfraProfileType,
|
|
19
|
+
CreateBuildInfraServicePayloadType,
|
|
20
|
+
CreateBuildInfraServiceConfigurationType,
|
|
21
|
+
GetBuildInfraProfileType,
|
|
22
|
+
UpdateBuildInfraProfileType,
|
|
23
|
+
} from './types'
|
|
24
|
+
|
|
25
|
+
const getBaseProfileObject = (
|
|
26
|
+
fromCreateView: boolean,
|
|
27
|
+
profile: BuildInfraProfileResponseDataType,
|
|
28
|
+
): BuildInfraProfileBase => {
|
|
29
|
+
if (fromCreateView) {
|
|
30
|
+
return CREATE_PROFILE_BASE_VALUE
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
id: profile.id,
|
|
35
|
+
name: profile.name,
|
|
36
|
+
description: profile.description,
|
|
37
|
+
type: profile.type,
|
|
38
|
+
appCount: profile.appCount,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Would receive a single profile and return transformed response
|
|
43
|
+
export const getTransformedBuildInfraProfileResponse = ({
|
|
44
|
+
configurationUnits,
|
|
45
|
+
defaultConfigurations,
|
|
46
|
+
profile,
|
|
47
|
+
fromCreateView,
|
|
48
|
+
}: BuildInfraProfileTransformerType): BuildInfraProfileResponseType => {
|
|
49
|
+
// Assuming would contain all the keys
|
|
50
|
+
const defaultConfigurationsMap =
|
|
51
|
+
defaultConfigurations?.reduce((acc, configuration) => {
|
|
52
|
+
acc[configuration.key] = configuration
|
|
53
|
+
return acc
|
|
54
|
+
}, {}) ?? {}
|
|
55
|
+
|
|
56
|
+
const profileConfigurations =
|
|
57
|
+
profile?.configurations?.reduce((acc, configuration) => {
|
|
58
|
+
acc[configuration.key] = configuration
|
|
59
|
+
return acc
|
|
60
|
+
}, {}) ?? {}
|
|
61
|
+
|
|
62
|
+
// traversing defaultConfigurationsMap and if key is present in profileConfigurations then use that else use defaultConfigurationsMap
|
|
63
|
+
const configurations = Object.keys(defaultConfigurationsMap).reduce((acc, key) => {
|
|
64
|
+
const defaultConfiguration: BuildInfraConfigurationType = defaultConfigurationsMap[key]
|
|
65
|
+
const profileConfiguration = profileConfigurations[key]
|
|
66
|
+
if (fromCreateView) {
|
|
67
|
+
acc[key] = {
|
|
68
|
+
key,
|
|
69
|
+
value: defaultConfiguration.value,
|
|
70
|
+
unit: defaultConfiguration.unit,
|
|
71
|
+
active: CREATE_VIEW_CHECKED_CONFIGS[key] ?? false,
|
|
72
|
+
}
|
|
73
|
+
} else if (profileConfiguration) {
|
|
74
|
+
acc[key] = profileConfiguration
|
|
75
|
+
} else {
|
|
76
|
+
// Removing id from it since we do not have a configuration
|
|
77
|
+
// While generating payload, we will check on the basis of id and active flag.
|
|
78
|
+
acc[key] = {
|
|
79
|
+
key,
|
|
80
|
+
value: defaultConfiguration.value,
|
|
81
|
+
// saving profile name as undefined and this would be a check, if we are deriving from default or not
|
|
82
|
+
unit: defaultConfiguration.unit,
|
|
83
|
+
active: false,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
acc[key].defaultValue = {
|
|
87
|
+
value: defaultConfiguration.value,
|
|
88
|
+
unit: defaultConfiguration.unit,
|
|
89
|
+
}
|
|
90
|
+
return acc
|
|
91
|
+
}, {} as BuildInfraConfigurationMapType)
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
configurationUnits,
|
|
95
|
+
profile: {
|
|
96
|
+
...(profile && getBaseProfileObject(fromCreateView, profile)),
|
|
97
|
+
configurations,
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const getBuildInfraProfileByName = async ({
|
|
103
|
+
name,
|
|
104
|
+
fromCreateView,
|
|
105
|
+
}: GetBuildInfraProfileType): Promise<BuildInfraProfileResponseType> => {
|
|
106
|
+
try {
|
|
107
|
+
const response = await get(`${ROUTES.INFRA_CONFIG_PROFILE}/${name}`)
|
|
108
|
+
const {
|
|
109
|
+
result: { configurationUnits, defaultConfigurations, profile },
|
|
110
|
+
} = response as ResponseType<BuildInfraProfileAPIResponseType>
|
|
111
|
+
|
|
112
|
+
return getTransformedBuildInfraProfileResponse({
|
|
113
|
+
configurationUnits,
|
|
114
|
+
defaultConfigurations,
|
|
115
|
+
profile,
|
|
116
|
+
fromCreateView,
|
|
117
|
+
})
|
|
118
|
+
} catch (error) {
|
|
119
|
+
showError(error)
|
|
120
|
+
throw error
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const getBuildInfraProfilePayload = (
|
|
125
|
+
profileInput: CreateBuildInfraProfileType['profileInput'],
|
|
126
|
+
): CreateBuildInfraServicePayloadType => {
|
|
127
|
+
const currentConfigurations = profileInput.configurations
|
|
128
|
+
const configurationKeys = Object.keys(currentConfigurations) as BuildInfraConfigTypes[]
|
|
129
|
+
// would only keep the configurations with id or active flag as true
|
|
130
|
+
const configurations: CreateBuildInfraServiceConfigurationType[] = configurationKeys.reduce((acc, key) => {
|
|
131
|
+
const configuration = currentConfigurations[key]
|
|
132
|
+
if (configuration.id || configuration.active) {
|
|
133
|
+
acc.push({
|
|
134
|
+
id: configuration.id,
|
|
135
|
+
key,
|
|
136
|
+
value: configuration.value,
|
|
137
|
+
unit: configuration.unit,
|
|
138
|
+
active: configuration.active,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
return acc
|
|
142
|
+
}, [] as CreateBuildInfraServiceConfigurationType[])
|
|
143
|
+
|
|
144
|
+
const payload: CreateBuildInfraServicePayloadType = {
|
|
145
|
+
name: profileInput.name,
|
|
146
|
+
description: profileInput.description,
|
|
147
|
+
type: profileInput.type,
|
|
148
|
+
configurations,
|
|
149
|
+
}
|
|
150
|
+
return payload
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const updateBuildInfraProfile = ({ name, profileInput }: UpdateBuildInfraProfileType) => {
|
|
154
|
+
const payload = getBuildInfraProfilePayload(profileInput)
|
|
155
|
+
// TODO: Would remove this
|
|
156
|
+
console.log(payload, 'edit payload')
|
|
157
|
+
return put(`${ROUTES.INFRA_CONFIG_PROFILE}/${name}`, payload)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const createBuildInfraProfile = async ({ profileInput }: CreateBuildInfraProfileType) => {
|
|
161
|
+
// Adding a timeout to show the loader
|
|
162
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
164
|
+
const payload = getBuildInfraProfilePayload(profileInput)
|
|
165
|
+
// TODO: Remove this
|
|
166
|
+
console.log(payload, 'create payload')
|
|
167
|
+
return Promise.resolve({
|
|
168
|
+
code: 200,
|
|
169
|
+
result: profileInput,
|
|
170
|
+
})
|
|
171
|
+
// return post(`${ROUTES}/${name}`, payload)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export const deleteBuildInfraProfileByName = async (name: string) => {
|
|
175
|
+
// Adding a timeout to show the loader
|
|
176
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
177
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
178
|
+
return Promise.resolve({
|
|
179
|
+
code: 200,
|
|
180
|
+
result: null,
|
|
181
|
+
})
|
|
182
|
+
// return trash(`${ROUTES}/${name}`)
|
|
183
|
+
}
|