@devtron-labs/devtron-fe-common-lib 0.0.58-beta-4 → 0.0.58-beta-6

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.
Files changed (83) hide show
  1. package/dist/Common/Constants.d.ts +14 -1
  2. package/dist/Common/Hooks/index.d.ts +1 -0
  3. package/dist/Common/Hooks/useUrlFilters/constants.d.ts +8 -0
  4. package/dist/Common/Hooks/useUrlFilters/index.d.ts +2 -0
  5. package/dist/Common/Hooks/useUrlFilters/types.d.ts +6 -0
  6. package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +32 -0
  7. package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +18 -0
  8. package/dist/Common/SortableTableHeaderCell/index.d.ts +2 -0
  9. package/dist/Common/SortableTableHeaderCell/types.d.ts +8 -0
  10. package/dist/Common/Types.d.ts +2 -3
  11. package/dist/Common/index.d.ts +1 -0
  12. package/dist/index.d.ts +1 -3
  13. package/dist/index.js +339 -1123
  14. package/package.json +1 -1
  15. package/src/Assets/Icon/ic-arrow-up-down.svg +3 -0
  16. package/src/Assets/Icon/ic-sort-arrow-down.svg +3 -0
  17. package/src/Common/BreadCrumb/Types.ts +1 -0
  18. package/src/Common/Checkbox.tsx +0 -1
  19. package/src/Common/Constants.ts +18 -3
  20. package/src/Common/CustomInput/CustomInput.tsx +1 -2
  21. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +1 -3
  22. package/src/Common/Hooks/index.ts +1 -0
  23. package/src/Common/Hooks/useUrlFilters/constants.ts +9 -0
  24. package/src/Common/Hooks/useUrlFilters/index.ts +2 -0
  25. package/src/Common/Hooks/useUrlFilters/types.ts +6 -0
  26. package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +120 -0
  27. package/src/Common/RJSF/utils.ts +0 -3
  28. package/src/Common/SearchBar/SearchBar.component.tsx +13 -26
  29. package/src/Common/SearchBar/searchBar.scss +1 -1
  30. package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +44 -0
  31. package/src/Common/SortableTableHeaderCell/index.ts +2 -0
  32. package/src/Common/SortableTableHeaderCell/types.ts +9 -0
  33. package/src/Common/Types.ts +1 -2
  34. package/src/Common/index.ts +1 -0
  35. package/src/index.ts +1 -3
  36. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.d.ts +0 -4
  37. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.d.ts +0 -4
  38. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.d.ts +0 -7
  39. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.d.ts +0 -4
  40. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.d.ts +0 -4
  41. package/dist/Pages/GlobalConfigurations/BuildInfra/Descriptor.d.ts +0 -4
  42. package/dist/Pages/GlobalConfigurations/BuildInfra/Footer.d.ts +0 -4
  43. package/dist/Pages/GlobalConfigurations/BuildInfra/constants.d.ts +0 -48
  44. package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +0 -7
  45. package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +0 -13
  46. package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +0 -281
  47. package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +0 -12
  48. package/dist/Pages/GlobalConfigurations/index.d.ts +0 -1
  49. package/dist/Pages/index.d.ts +0 -1
  50. package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +0 -4
  51. package/dist/Shared/Components/APIResponseHandler/index.d.ts +0 -2
  52. package/dist/Shared/Components/APIResponseHandler/types.d.ts +0 -37
  53. package/dist/Shared/Components/ReactSelect/index.d.ts +0 -1
  54. package/dist/Shared/Components/ReactSelect/utils.d.ts +0 -12
  55. package/dist/Shared/Components/index.d.ts +0 -2
  56. package/dist/Shared/index.d.ts +0 -2
  57. package/dist/Shared/validations.d.ts +0 -7
  58. package/src/Assets/Icon/ic-cpu.svg +0 -4
  59. package/src/Assets/Icon/ic-memory.svg +0 -3
  60. package/src/Assets/Icon/ic-timer.svg +0 -3
  61. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +0 -121
  62. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +0 -44
  63. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +0 -99
  64. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.tsx +0 -55
  65. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.tsx +0 -32
  66. package/src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx +0 -38
  67. package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +0 -45
  68. package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +0 -4
  69. package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +0 -137
  70. package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +0 -7
  71. package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +0 -183
  72. package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +0 -334
  73. package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +0 -489
  74. package/src/Pages/GlobalConfigurations/index.ts +0 -1
  75. package/src/Pages/index.ts +0 -1
  76. package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +0 -39
  77. package/src/Shared/Components/APIResponseHandler/index.ts +0 -2
  78. package/src/Shared/Components/APIResponseHandler/types.tsx +0 -39
  79. package/src/Shared/Components/ReactSelect/index.ts +0 -1
  80. package/src/Shared/Components/ReactSelect/utils.tsx +0 -97
  81. package/src/Shared/Components/index.ts +0 -2
  82. package/src/Shared/index.ts +0 -2
  83. package/src/Shared/validations.tsx +0 -72
@@ -1,55 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,38 +0,0 @@
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
@@ -1,45 +0,0 @@
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
@@ -1,4 +0,0 @@
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
@@ -1,137 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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'
@@ -1,183 +0,0 @@
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
- }