@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.
Files changed (83) hide show
  1. package/dist/Common/Constants.d.ts +1 -14
  2. package/dist/Common/Hooks/index.d.ts +0 -1
  3. package/dist/Common/Types.d.ts +3 -2
  4. package/dist/Common/index.d.ts +0 -1
  5. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.d.ts +4 -0
  6. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.d.ts +4 -0
  7. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.d.ts +7 -0
  8. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.d.ts +4 -0
  9. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.d.ts +4 -0
  10. package/dist/Pages/GlobalConfigurations/BuildInfra/Descriptor.d.ts +4 -0
  11. package/dist/Pages/GlobalConfigurations/BuildInfra/Footer.d.ts +4 -0
  12. package/dist/Pages/GlobalConfigurations/BuildInfra/constants.d.ts +47 -0
  13. package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +7 -0
  14. package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +13 -0
  15. package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +282 -0
  16. package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +12 -0
  17. package/dist/Pages/GlobalConfigurations/index.d.ts +1 -0
  18. package/dist/Pages/index.d.ts +1 -0
  19. package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +4 -0
  20. package/dist/Shared/Components/APIResponseHandler/index.d.ts +2 -0
  21. package/dist/Shared/Components/APIResponseHandler/types.d.ts +37 -0
  22. package/dist/Shared/Components/ReactSelect/index.d.ts +1 -0
  23. package/dist/Shared/Components/ReactSelect/utils.d.ts +12 -0
  24. package/dist/Shared/Components/index.d.ts +2 -0
  25. package/dist/Shared/index.d.ts +2 -0
  26. package/dist/Shared/validations.d.ts +7 -0
  27. package/dist/index.d.ts +3 -1
  28. package/dist/index.js +1123 -339
  29. package/package.json +1 -1
  30. package/src/Assets/Icon/ic-cpu.svg +4 -0
  31. package/src/Assets/Icon/ic-memory.svg +3 -0
  32. package/src/Assets/Icon/ic-timer.svg +3 -0
  33. package/src/Common/BreadCrumb/Types.ts +0 -1
  34. package/src/Common/Checkbox.tsx +1 -0
  35. package/src/Common/Constants.ts +3 -18
  36. package/src/Common/CustomInput/CustomInput.tsx +2 -1
  37. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
  38. package/src/Common/Hooks/index.ts +0 -1
  39. package/src/Common/RJSF/utils.ts +3 -0
  40. package/src/Common/SearchBar/SearchBar.component.tsx +26 -13
  41. package/src/Common/SearchBar/searchBar.scss +1 -1
  42. package/src/Common/Types.ts +2 -1
  43. package/src/Common/index.ts +0 -1
  44. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +121 -0
  45. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +44 -0
  46. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +104 -0
  47. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.tsx +55 -0
  48. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.tsx +32 -0
  49. package/src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx +38 -0
  50. package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +45 -0
  51. package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +4 -0
  52. package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +136 -0
  53. package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
  54. package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +184 -0
  55. package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +335 -0
  56. package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +494 -0
  57. package/src/Pages/GlobalConfigurations/index.ts +1 -0
  58. package/src/Pages/index.ts +1 -0
  59. package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +39 -0
  60. package/src/Shared/Components/APIResponseHandler/index.ts +2 -0
  61. package/src/Shared/Components/APIResponseHandler/types.tsx +39 -0
  62. package/src/Shared/Components/ReactSelect/index.ts +1 -0
  63. package/src/Shared/Components/ReactSelect/utils.tsx +97 -0
  64. package/src/Shared/Components/index.ts +2 -0
  65. package/src/Shared/index.ts +2 -0
  66. package/src/Shared/validations.tsx +72 -0
  67. package/src/index.ts +3 -1
  68. package/dist/Common/Hooks/useUrlFilters/constants.d.ts +0 -8
  69. package/dist/Common/Hooks/useUrlFilters/index.d.ts +0 -2
  70. package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -6
  71. package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +0 -32
  72. package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +0 -18
  73. package/dist/Common/SortableTableHeaderCell/index.d.ts +0 -2
  74. package/dist/Common/SortableTableHeaderCell/types.d.ts +0 -8
  75. package/src/Assets/Icon/ic-arrow-up-down.svg +0 -3
  76. package/src/Assets/Icon/ic-sort-arrow-down.svg +0 -3
  77. package/src/Common/Hooks/useUrlFilters/constants.ts +0 -9
  78. package/src/Common/Hooks/useUrlFilters/index.ts +0 -2
  79. package/src/Common/Hooks/useUrlFilters/types.ts +0 -6
  80. package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +0 -120
  81. package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +0 -44
  82. package/src/Common/SortableTableHeaderCell/index.ts +0 -2
  83. package/src/Common/SortableTableHeaderCell/types.ts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtron-labs/devtron-fe-common-lib",
3
- "version": "0.0.58-beta-6",
3
+ "version": "0.0.58-beta-7",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
2
+ <path d="M12.5 5.625H7.5M12.5 8.125H7.5M15.625 3.125V16.875C15.625 17.2202 15.3452 17.5 15 17.5H5C4.65482 17.5 4.375 17.2202 4.375 16.875V3.125C4.375 2.77982 4.65482 2.5 5 2.5H15C15.3452 2.5 15.625 2.77982 15.625 3.125Z" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
3
+ <path d="M10 15C10.5178 15 10.9375 14.5803 10.9375 14.0625C10.9375 13.5447 10.5178 13.125 10 13.125C9.48223 13.125 9.0625 13.5447 9.0625 14.0625C9.0625 14.5803 9.48223 15 10 15Z" fill="#596168"/>
4
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
2
+ <path d="M16.25 8.125H18.125M16.25 11.875H18.125M1.875 8.125H3.75M1.875 11.875H3.75M11.875 16.25V18.125M8.125 16.25V18.125M11.875 1.875V3.75M8.125 1.875V3.75M7.8125 7.8125H12.1875V12.1875H7.8125V7.8125ZM4.375 3.75H15.625C15.9702 3.75 16.25 4.02982 16.25 4.375V15.625C16.25 15.9702 15.9702 16.25 15.625 16.25H4.375C4.02982 16.25 3.75 15.9702 3.75 15.625V4.375C3.75 4.02982 4.02982 3.75 4.375 3.75Z" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
2
+ <path d="M10 11.0415L13.0936 7.94791M8.125 1.6665H11.875M16.875 11.0415C16.875 14.8385 13.797 17.9165 10 17.9165C6.20304 17.9165 3.125 14.8385 3.125 11.0415C3.125 7.24455 6.20304 4.1665 10 4.1665C13.797 4.1665 16.875 7.24455 16.875 11.0415Z" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
3
+ </svg>
@@ -1,4 +1,3 @@
1
-
2
1
  export interface Breadcrumb {
3
2
  to: string
4
3
  name: string
@@ -10,6 +10,7 @@ Valid States of Checkbox:
10
10
  5. disabled: false, checked: true, value: INTERMIDIATE
11
11
  6. disabled: false, checked: true, value: CHECKED
12
12
  */
13
+ // TODO: Associate label with input element
13
14
  export class Checkbox extends Component<CheckboxProps> {
14
15
  render() {
15
16
  let rootClassName = `${this.props.rootClassName ? this.props.rootClassName : ''}`
@@ -25,7 +25,8 @@ export const ROUTES = {
25
25
  USER_CHECK_ROLE: 'user/check/roles',
26
26
  IMAGE_TAGGING:'app/image-tagging',
27
27
  CD_MATERIAL_GET: 'app/cd-pipeline',
28
- DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
28
+ DEPLOYMENT_TEMPLATE_LIST: 'app/template/list',
29
+ INFRA_CONFIG_PROFILE: 'infra-config/profile',
29
30
  }
30
31
 
31
32
  export enum KEY_VALUE {
@@ -251,20 +252,4 @@ export const MAX_Z_INDEX = 2147483647
251
252
  export const SELECTED_APPROVAL_TAB_STATE = {
252
253
  APPROVAL: 'approval',
253
254
  PENDING: 'pending',
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
255
+ }
@@ -2,6 +2,7 @@ import { CustomInputProps } from './Types'
2
2
  import { ReactComponent as Info } from '../../Assets/Icon/ic-info-filled.svg'
3
3
  import { ReactComponent as ErrorIcon } from '../../Assets/Icon/ic-warning.svg'
4
4
 
5
+ // TODO: label association with input
5
6
  export function CustomInput({
6
7
  name,
7
8
  value,
@@ -13,7 +14,7 @@ export function CustomInput({
13
14
  disabled = false,
14
15
  labelClassName = '',
15
16
  placeholder = '',
16
- tabIndex = 1,
17
+ tabIndex = 0,
17
18
  dataTestid = '',
18
19
  isRequiredField = false,
19
20
  autoFocus = false,
@@ -94,8 +94,9 @@ export default function DraggableWrapper({
94
94
  }
95
95
 
96
96
  return (
97
+ // Since we are using position fixed so we need to disable click on the div so that it does not interfere with the click of other elements
97
98
  <div
98
- className="dc__position-fixed"
99
+ className="dc__position-fixed dc__disable-click"
99
100
  style={{
100
101
  zIndex,
101
102
  }}
@@ -106,6 +107,7 @@ export default function DraggableWrapper({
106
107
  {...childDivProps}
107
108
  style={{
108
109
  zIndex,
110
+ pointerEvents: 'auto',
109
111
  }}
110
112
  >
111
113
  {children}
@@ -1,4 +1,3 @@
1
1
  export { useSuperAdmin } from './UseSuperAdmin/UseSuperAdmin'
2
2
  export { useClickOutside } from './UseClickOutside/UseClickOutside'
3
3
  export { useWindowSize } from './UseWindowSize/UseWindowSize'
4
- export * from './useUrlFilters'
@@ -13,12 +13,14 @@ export const translateString = (stringToTranslate: TranslatableString, params?:
13
13
  }
14
14
  }
15
15
 
16
+ // NOTE: If you are changing this please make sure BuildInfra selects are also working fine
16
17
  export const getCommonSelectStyle = (styleOverrides = {}) => {
17
18
  return {
18
19
  menuList: (base) => ({
19
20
  ...base,
20
21
  paddingTop: 0,
21
22
  paddingBottom: 0,
23
+ cursor: 'pointer',
22
24
  }),
23
25
  control: (base, state) => ({
24
26
  ...base,
@@ -33,6 +35,7 @@ export const getCommonSelectStyle = (styleOverrides = {}) => {
33
35
  color: 'var(--N900)',
34
36
  backgroundColor: state.isFocused ? 'var(--N100)' : 'white',
35
37
  padding: '10px 12px',
38
+ cursor: 'pointer',
36
39
  }),
37
40
  dropdownIndicator: (base, state) => ({
38
41
  ...base,
@@ -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,31 @@ const SearchBar = ({
55
55
  debounceTimeout,
56
56
  ])
57
57
 
58
+ // In most case would reset the state by doing history.push('/')
59
+ useEffect(() => {
60
+ inputRef.current.value = initialSearchText
61
+ }, [initialSearchText])
62
+
63
+ const _applySearch = (value: string) => {
64
+ handleSearchChange(value)
65
+ handleEnter(value)
66
+ }
67
+
68
+ const clearSearch = () => {
69
+ inputRef.current.value = ''
70
+ _applySearch('')
71
+ setShowClearButton(false)
72
+ }
73
+
58
74
  const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
59
75
  const { value } = e.target
60
76
  setShowClearButton(!!value)
77
+
78
+ if (!value) {
79
+ clearSearch()
80
+ return
81
+ }
82
+
61
83
  if (shouldDebounce) {
62
84
  debouncedSearchChange(value)
63
85
  } else {
@@ -65,11 +87,6 @@ const SearchBar = ({
65
87
  }
66
88
  }
67
89
 
68
- const _applySearch = (value: string) => {
69
- handleSearchChange(value)
70
- handleEnter(value)
71
- }
72
-
73
90
  const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
74
91
  const { key } = e
75
92
 
@@ -80,14 +97,9 @@ const SearchBar = ({
80
97
  }
81
98
  }
82
99
 
83
- const clearSearch = () => {
84
- inputRef.current.value = ''
85
- _applySearch('')
86
- }
87
-
88
100
  return (
89
101
  <div className={containerClassName}>
90
- <div className="search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32">
102
+ <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">
91
103
  <Search className="search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" />
92
104
  <input
93
105
  placeholder="Search"
@@ -95,13 +107,14 @@ const SearchBar = ({
95
107
  type="text"
96
108
  {...inputProps}
97
109
  defaultValue={initialSearchText}
98
- className={`search-bar__input bcn-0 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 ${
110
+ 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 ${
99
111
  showClearButton ? 'pr-30' : 'pr-10'
100
112
  }`}
101
113
  onChange={handleChange}
102
114
  onKeyDown={handleKeyDown}
103
115
  ref={inputRef}
104
116
  />
117
+ {/* TODO: Sync with product since it should have ic-enter in case of not applied */}
105
118
  {showClearButton && (
106
119
  <button
107
120
  className="flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5"
@@ -3,7 +3,7 @@
3
3
  &:focus,
4
4
  &:focus-within {
5
5
  outline: none;
6
- border: solid 1px var(--B500);
6
+ border: solid 1px var(--B500) !important;
7
7
  }
8
8
 
9
9
  &__input {
@@ -51,11 +51,12 @@ 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
- value: 'CHECKED' | 'INTERMEDIATE'
59
+ value: 'CHECKED' | 'INTERMEDIATE' | 'BULK_CHECKED'
59
60
  disabled?: boolean
60
61
  tabIndex?: number
61
62
  rootClassName?: string
@@ -27,7 +27,6 @@ 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'
31
30
  export { default as Toggle } from './Toggle/Toggle'
32
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
33
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'
@@ -0,0 +1,121 @@
1
+ import { FunctionComponent } from 'react'
2
+ import { Progressing } from '../../../Common'
3
+ import BuildInfraFormAction from './BuildInfraFormAction'
4
+ import BuildInfraFormItem from './BuildInfraFormItem'
5
+ import BuildInfraProfileDescriptionField from './BuildInfraDescriptionField'
6
+ import BuildInfraProfileNameField from './BuildInfraProfileNameField'
7
+ import { BUILD_INFRA_FORM_FIELDS, BUILD_INFRA_TEXT } from './constants'
8
+ import { BuildInfraActionType, BuildInfraConfigFormProps, InheritingHeaderProps } from './types'
9
+
10
+ const InheritingHeader = ({
11
+ defaultHeading,
12
+ inheritingData,
13
+ isInheriting,
14
+ isDefaultProfile,
15
+ }: InheritingHeaderProps) => {
16
+ const inheritingDataString = inheritingData.map((data) => `${data.value} ${data.unit ?? ''}`).join(' - ')
17
+
18
+ if (isDefaultProfile || !isInheriting) {
19
+ // For typing issues
20
+ // eslint-disable-next-line react/jsx-no-useless-fragment
21
+ return <>{defaultHeading}</>
22
+ }
23
+
24
+ return (
25
+ <div className="flexbox dc__align-items-center dc__content-space w-100">
26
+ {defaultHeading}
27
+
28
+ <p className="m-0 flexbox pt-0 pb-0 pl-4 pr-4 fs-13 lh-20 fw-4 cn-9">{inheritingDataString}</p>
29
+
30
+ <p className="m-0 cn-7 fs-13 fw-4 lh-20">{BUILD_INFRA_TEXT.INHERITING_HEADING_DESCRIPTION}</p>
31
+ </div>
32
+ )
33
+ }
34
+
35
+ const BuildInfraConfigForm: FunctionComponent<BuildInfraConfigFormProps> = ({
36
+ profileInput,
37
+ profileInputErrors,
38
+ handleProfileInputChange,
39
+ isDefaultProfile,
40
+ unitsMap,
41
+ configurationContainerLabel,
42
+ }) => {
43
+ const currentConfigurations = profileInput?.configurations
44
+
45
+ // will get the desired configuration from the currentConfigurations and then check if it is active or not
46
+ const isInheritingProfileValues = (actions: BuildInfraActionType[]) =>
47
+ actions.some((action) => !currentConfigurations[action.actionType].active)
48
+
49
+ // Had to show loader for an instance due to batching of state updates not working as expected :/
50
+ if (!currentConfigurations) {
51
+ return <Progressing pageLoader />
52
+ }
53
+
54
+ return (
55
+ <div className="flexbox-col dc__mxw-920 dc__gap-16">
56
+ {!isDefaultProfile && (
57
+ <div className="flexbox-col dc__gap-12">
58
+ <BuildInfraProfileNameField
59
+ handleProfileInputChange={handleProfileInputChange}
60
+ currentValue={profileInput.name}
61
+ error={profileInputErrors.name}
62
+ />
63
+
64
+ <BuildInfraProfileDescriptionField
65
+ handleProfileInputChange={handleProfileInputChange}
66
+ currentValue={profileInput.description}
67
+ error={profileInputErrors.description}
68
+ />
69
+ </div>
70
+ )}
71
+
72
+ <div className="flexbox-col dc__gap-12">
73
+ {configurationContainerLabel}
74
+
75
+ <div className="w-100 flexbox-col dc__gap-16 br-4 dc__border-n1 p-16">
76
+ {BUILD_INFRA_FORM_FIELDS.map((field, index) => (
77
+ <BuildInfraFormItem
78
+ key={field.locator}
79
+ marker={field.marker}
80
+ heading={
81
+ <InheritingHeader
82
+ defaultHeading={field.heading}
83
+ inheritingData={field.actions.map(
84
+ (action) => currentConfigurations[action.actionType],
85
+ )}
86
+ isInheriting={isInheritingProfileValues(field.actions)}
87
+ isDefaultProfile={isDefaultProfile}
88
+ />
89
+ }
90
+ showDivider={index !== BUILD_INFRA_FORM_FIELDS.length - 1}
91
+ isInheriting={isInheritingProfileValues(field.actions)}
92
+ handleProfileInputChange={handleProfileInputChange}
93
+ locator={field.locator}
94
+ isDefaultProfile={isDefaultProfile}
95
+ >
96
+ <div className="w-50 flexbox dc__gap-12 w-100 dc__align-start">
97
+ {field.actions.map((action) => (
98
+ <BuildInfraFormAction
99
+ key={action.actionType}
100
+ actionType={action.actionType}
101
+ label={action.label}
102
+ placeholder={action.placeholder}
103
+ error={profileInputErrors[action.actionType]}
104
+ // Assumption is for default profiles all input fields are required
105
+ isRequired={isDefaultProfile}
106
+ profileUnitsMap={unitsMap[action.actionType]}
107
+ handleProfileInputChange={handleProfileInputChange}
108
+ currentUnitName={currentConfigurations[action.actionType].unit}
109
+ currentValue={currentConfigurations[action.actionType].value}
110
+ />
111
+ ))}
112
+ </div>
113
+ </BuildInfraFormItem>
114
+ ))}
115
+ </div>
116
+ </div>
117
+ </div>
118
+ )
119
+ }
120
+
121
+ export default BuildInfraConfigForm
@@ -0,0 +1,44 @@
1
+ import { FormEvent, FunctionComponent } from 'react'
2
+ import { ReactComponent as ErrorIcon } from '../../../Assets/Icon/ic-warning.svg'
3
+ import { BuildInfraInputFieldComponentProps, BuildInfraMetaConfigTypes } from './types'
4
+ import { BUILD_INFRA_TEXT } from './constants'
5
+
6
+ const BuildInfraProfileDescriptionField: FunctionComponent<BuildInfraInputFieldComponentProps> = ({
7
+ handleProfileInputChange,
8
+ currentValue,
9
+ error,
10
+ }) => {
11
+ const handleChange = (e: FormEvent<HTMLTextAreaElement>) => {
12
+ handleProfileInputChange({
13
+ action: BuildInfraMetaConfigTypes.DESCRIPTION,
14
+ data: { value: e.currentTarget.value },
15
+ })
16
+ }
17
+
18
+ return (
19
+ <div className="flexbox-col dc__gap-4 w-100 dc__align-start">
20
+ <label htmlFor="build-infra-profile-description" className="m-0 fs-13 fw-4 lh-20 cn-7">
21
+ {BUILD_INFRA_TEXT.DESCRIPTION_LABEL}
22
+ </label>
23
+
24
+ <textarea
25
+ data-testid="build-infra-profile-description"
26
+ name="profile-description"
27
+ className="form__textarea mxh-140 dc__hover-border-n300"
28
+ id="build-infra-profile-description"
29
+ placeholder={BUILD_INFRA_TEXT.DESCRIPTION_PLACEHOLDER}
30
+ value={currentValue}
31
+ onChange={handleChange}
32
+ />
33
+
34
+ {error && (
35
+ <div className="form__error">
36
+ <ErrorIcon className="form__icon form__icon--error" />
37
+ {error}
38
+ </div>
39
+ )}
40
+ </div>
41
+ )
42
+ }
43
+
44
+ export default BuildInfraProfileDescriptionField
@@ -0,0 +1,104 @@
1
+ import { FormEvent, FunctionComponent, useMemo } 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
+ // would also sort the units in order of conversionFactor
40
+ const { unitOptions, currentUnit } = useMemo(() => {
41
+ const units =
42
+ Object.values(profileUnitsMap)?.map((unit) => ({
43
+ label: unit.name,
44
+ value: String(unit.conversionFactor),
45
+ })) ?? []
46
+
47
+ const _currentUnit = units.find((unit) => unit.label === currentUnitName)
48
+ return { unitOptions: units.sort((a, b) => Number(a.value) - Number(b.value)), currentUnit: _currentUnit }
49
+ }, [profileUnitsMap])
50
+
51
+ return (
52
+ <div className="flexbox-col dc__gap-4 dc__mxw-420 w-100 dc__align-start">
53
+ <label
54
+ htmlFor={`${actionType}-input`}
55
+ className={`fs-13 fw-4 lh-20 cn-7 ${isRequired ? 'dc__required-field' : ''}`}
56
+ >
57
+ {label}
58
+ </label>
59
+ <div className="w-100 flexbox dc__align-items-center">
60
+ <div className="flex-grow-1">
61
+ <input
62
+ data-testid={actionType}
63
+ name={actionType}
64
+ type="number"
65
+ step={BUILD_INFRA_INPUT_CONSTRAINTS.STEP}
66
+ min={BUILD_INFRA_INPUT_CONSTRAINTS.MIN}
67
+ className="form__input dc__no-right-border dc__no-right-radius"
68
+ placeholder={placeholder}
69
+ value={currentValue}
70
+ onChange={handleInputChange}
71
+ required={isRequired}
72
+ autoComplete="off"
73
+ id={`${actionType}-input`}
74
+ />
75
+ </div>
76
+
77
+ {profileUnitsMap && (
78
+ <ReactSelect
79
+ name={`${actionType}-unit`}
80
+ className="bcn-0 dc__mxw-120"
81
+ options={unitOptions}
82
+ value={currentUnit}
83
+ onChange={handleUnitChange}
84
+ isSearchable={false}
85
+ components={{
86
+ IndicatorSeparator: null,
87
+ ClearIndicator: null,
88
+ }}
89
+ styles={unitSelectorStyles()}
90
+ />
91
+ )}
92
+ </div>
93
+
94
+ {error && (
95
+ <div className="form__error">
96
+ <ErrorIcon className="form__icon form__icon--error" />
97
+ {error}
98
+ </div>
99
+ )}
100
+ </div>
101
+ )
102
+ }
103
+
104
+ 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