@devtron-labs/devtron-fe-common-lib 0.0.59-beta-8 → 0.0.59-beta-10

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 (103) 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 +4 -15
  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 +50 -0
  13. package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +7 -0
  14. package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +6 -0
  15. package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +286 -0
  16. package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +12 -0
  17. package/dist/Pages/GlobalConfigurations/index.d.ts +1 -1
  18. package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +4 -0
  19. package/dist/Shared/Components/APIResponseHandler/constants.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/BulkSelection/BulkSelection.d.ts +4 -0
  23. package/dist/Shared/Components/BulkSelection/BulkSelectionDropdownItems.d.ts +4 -0
  24. package/dist/Shared/Components/BulkSelection/UseBulkSelection.d.ts +3 -0
  25. package/dist/Shared/Components/BulkSelection/constants.d.ts +8 -0
  26. package/dist/Shared/Components/BulkSelection/index.d.ts +4 -0
  27. package/dist/Shared/Components/BulkSelection/types.d.ts +51 -0
  28. package/dist/Shared/Components/ReactSelect/index.d.ts +1 -0
  29. package/dist/Shared/Components/ReactSelect/utils.d.ts +12 -0
  30. package/dist/Shared/Components/index.d.ts +3 -0
  31. package/dist/Shared/Helpers.d.ts +16 -0
  32. package/dist/Shared/index.d.ts +3 -0
  33. package/dist/Shared/validations.d.ts +8 -0
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1366 -346
  36. package/package.json +1 -1
  37. package/src/Assets/Icon/ic-check-all.svg +5 -0
  38. package/src/Assets/Icon/ic-check-square.svg +4 -0
  39. package/src/Assets/Icon/ic-close.svg +3 -0
  40. package/src/Assets/Icon/ic-cpu.svg +4 -0
  41. package/src/Assets/Icon/ic-memory.svg +3 -0
  42. package/src/Assets/Icon/ic-timer.svg +3 -0
  43. package/src/Common/BreadCrumb/Types.ts +0 -1
  44. package/src/Common/Checkbox.tsx +1 -0
  45. package/src/Common/Constants.ts +3 -18
  46. package/src/Common/CustomInput/CustomInput.tsx +2 -1
  47. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
  48. package/src/Common/Hooks/index.ts +0 -1
  49. package/src/Common/RJSF/utils.ts +2 -0
  50. package/src/Common/SearchBar/searchBar.scss +1 -1
  51. package/src/Common/Types.ts +4 -14
  52. package/src/Common/index.ts +0 -1
  53. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +128 -0
  54. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +44 -0
  55. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +106 -0
  56. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.tsx +55 -0
  57. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.tsx +32 -0
  58. package/src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx +45 -0
  59. package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +55 -0
  60. package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +4 -0
  61. package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +139 -0
  62. package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
  63. package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +167 -0
  64. package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +339 -0
  65. package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +509 -0
  66. package/src/Pages/GlobalConfigurations/index.ts +1 -1
  67. package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +41 -0
  68. package/src/Shared/Components/APIResponseHandler/constants.tsx +5 -0
  69. package/src/Shared/Components/APIResponseHandler/index.ts +2 -0
  70. package/src/Shared/Components/APIResponseHandler/types.tsx +39 -0
  71. package/src/Shared/Components/BulkSelection/BulkSelection.tsx +81 -0
  72. package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +31 -0
  73. package/src/Shared/Components/BulkSelection/UseBulkSelection.tsx +99 -0
  74. package/src/Shared/Components/BulkSelection/constants.tsx +12 -0
  75. package/src/Shared/Components/BulkSelection/index.ts +4 -0
  76. package/src/Shared/Components/BulkSelection/types.tsx +61 -0
  77. package/src/Shared/Components/ReactSelect/index.ts +1 -0
  78. package/src/Shared/Components/ReactSelect/utils.tsx +97 -0
  79. package/src/Shared/Components/index.ts +3 -0
  80. package/src/Shared/Helpers.tsx +29 -0
  81. package/src/Shared/index.ts +3 -0
  82. package/src/Shared/validations.tsx +130 -0
  83. package/src/index.ts +1 -0
  84. package/dist/Common/Hooks/useUrlFilters/constants.d.ts +0 -8
  85. package/dist/Common/Hooks/useUrlFilters/index.d.ts +0 -2
  86. package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -6
  87. package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +0 -32
  88. package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +0 -18
  89. package/dist/Common/SortableTableHeaderCell/index.d.ts +0 -2
  90. package/dist/Common/SortableTableHeaderCell/types.d.ts +0 -25
  91. package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +0 -15
  92. package/dist/Pages/GlobalConfigurations/Authorization/index.d.ts +0 -1
  93. package/src/Assets/Icon/ic-arrow-up-down.svg +0 -3
  94. package/src/Assets/Icon/ic-sort-arrow-down.svg +0 -3
  95. package/src/Common/Hooks/useUrlFilters/constants.ts +0 -9
  96. package/src/Common/Hooks/useUrlFilters/index.ts +0 -2
  97. package/src/Common/Hooks/useUrlFilters/types.ts +0 -6
  98. package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +0 -121
  99. package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +0 -44
  100. package/src/Common/SortableTableHeaderCell/index.ts +0 -2
  101. package/src/Common/SortableTableHeaderCell/types.ts +0 -26
  102. package/src/Pages/GlobalConfigurations/Authorization/constants.ts +0 -16
  103. package/src/Pages/GlobalConfigurations/Authorization/index.ts +0 -1
@@ -0,0 +1,509 @@
1
+ import { FormEvent, useEffect, useState } from 'react'
2
+ import { toast } from 'react-toastify'
3
+ import { showError, useAsync } from '../../../Common'
4
+ import { getBuildInfraProfileByName, createBuildInfraProfile, updateBuildInfraProfile } from './services'
5
+ import {
6
+ BuildInfraConfigTypes,
7
+ BuildInfraInheritActions,
8
+ BuildInfraMetaConfigTypes,
9
+ BuildInfraProfileData,
10
+ HandleProfileInputChangeType,
11
+ ProfileInputErrorType,
12
+ UseBuildInfraFormProps,
13
+ UseBuildInfraFormResponseType,
14
+ ValidateRequestLimitResponseType,
15
+ ValidateRequestLimitType,
16
+ } from './types'
17
+ import {
18
+ BUILD_INFRA_INPUT_CONSTRAINTS,
19
+ BUILD_INFRA_TEXT,
20
+ DEFAULT_PROFILE_NAME,
21
+ PROFILE_INPUT_ERROR_FIELDS,
22
+ CREATE_MODE_REQUIRED_INPUT_FIELDS,
23
+ } from './constants'
24
+ import {
25
+ validateDescription,
26
+ validateName,
27
+ validateRequiredPositiveNumber,
28
+ getCommonSelectStyle,
29
+ validateRequiredPositiveInteger,
30
+ } from '../../../Shared'
31
+
32
+ export const validateRequestLimit = ({
33
+ request,
34
+ limit,
35
+ unitsMap,
36
+ }: ValidateRequestLimitType): ValidateRequestLimitResponseType => {
37
+ // Request <= Limit
38
+ // Request and Limit should be numbers can be decimals
39
+ // Request and Limit should be positive numbers
40
+ // Request and Limit should be less than Number.MAX_SAFE_INTEGER
41
+ // Request and Limit should can have at most BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES
42
+ // Both request and limit should be there
43
+ const requestNumber = Number(request.value)
44
+ const limitNumber = Number(limit.value)
45
+ const requestUnit = Number(unitsMap[request.unit]?.conversionFactor)
46
+ const limitUnit = Number(unitsMap[limit.unit]?.conversionFactor)
47
+
48
+ const requestLimitValidationResponse: ValidateRequestLimitResponseType = {
49
+ request: {
50
+ isValid: true,
51
+ },
52
+ limit: {
53
+ isValid: true,
54
+ },
55
+ }
56
+
57
+ const requestValidationMessage = validateRequiredPositiveNumber(request.value).message
58
+ const limitValidationMessage = validateRequiredPositiveNumber(limit.value).message
59
+
60
+ if (requestValidationMessage) {
61
+ requestLimitValidationResponse.request = {
62
+ message: requestValidationMessage,
63
+ isValid: false,
64
+ }
65
+ }
66
+
67
+ if (limitValidationMessage) {
68
+ requestLimitValidationResponse.limit = {
69
+ message: limitValidationMessage,
70
+ isValid: false,
71
+ }
72
+ }
73
+
74
+ if (limitValidationMessage || requestValidationMessage) {
75
+ return requestLimitValidationResponse
76
+ }
77
+
78
+ // only two decimal places are allowed
79
+ const requestDecimalPlaces = String(request.value).split('.')[1]?.length ?? 0
80
+ const limitDecimalPlaces = String(limit.value).split('.')[1]?.length ?? 0
81
+
82
+ if (requestDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
83
+ requestLimitValidationResponse.request = {
84
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_DECIMAL_PLACES,
85
+ isValid: false,
86
+ }
87
+
88
+ return requestLimitValidationResponse
89
+ }
90
+ if (limitDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
91
+ requestLimitValidationResponse.limit = {
92
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.LIMIT_DECIMAL_PLACES,
93
+ isValid: false,
94
+ }
95
+
96
+ return requestLimitValidationResponse
97
+ }
98
+
99
+ // Assuming requestUnit and requestNumber are not 0
100
+ // TODO: Communicate this assumption to the backend
101
+ const limitRequestUnitFactor = limitUnit / requestUnit
102
+ const limitRequestFactor = limitNumber / requestNumber
103
+
104
+ const isDifferenceBigNumber = limitRequestUnitFactor * limitRequestFactor <= Number.MAX_SAFE_INTEGER
105
+
106
+ if (!isDifferenceBigNumber) {
107
+ requestLimitValidationResponse.request = {
108
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.CAN_NOT_COMPUTE,
109
+ isValid: false,
110
+ }
111
+
112
+ return requestLimitValidationResponse
113
+ }
114
+
115
+ if (limitRequestUnitFactor * limitRequestFactor < 1) {
116
+ requestLimitValidationResponse.request = {
117
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_LESS_THAN_LIMIT,
118
+ isValid: false,
119
+ }
120
+
121
+ return requestLimitValidationResponse
122
+ }
123
+
124
+ return requestLimitValidationResponse
125
+ }
126
+
127
+ const getInitialProfileInputErrors = (fromCreateView: boolean): ProfileInputErrorType => {
128
+ if (fromCreateView) {
129
+ const initialProfileInputErrors = { ...PROFILE_INPUT_ERROR_FIELDS }
130
+ CREATE_MODE_REQUIRED_INPUT_FIELDS.forEach((field) => {
131
+ initialProfileInputErrors[field] = ''
132
+ })
133
+ return initialProfileInputErrors
134
+ }
135
+
136
+ return {
137
+ ...PROFILE_INPUT_ERROR_FIELDS,
138
+ }
139
+ }
140
+
141
+ export const useBuildInfraForm = ({
142
+ name,
143
+ editProfile,
144
+ handleSuccessRedirection,
145
+ }: UseBuildInfraFormProps): UseBuildInfraFormResponseType => {
146
+ const fromCreateView = !name
147
+
148
+ const [isLoading, profileResponse, responseError, reloadRequest] = useAsync(
149
+ () =>
150
+ getBuildInfraProfileByName({
151
+ name: name ?? DEFAULT_PROFILE_NAME,
152
+ fromCreateView,
153
+ }),
154
+ [name],
155
+ )
156
+ // If configuration is existing and is active then use it else use default from profileResponse
157
+ const [profileInput, setProfileInput] = useState<BuildInfraProfileData>(null)
158
+ const [profileInputErrors, setProfileInputErrors] = useState<ProfileInputErrorType>({
159
+ ...PROFILE_INPUT_ERROR_FIELDS,
160
+ })
161
+ const [loadingActionRequest, setLoadingActionRequest] = useState<boolean>(false)
162
+
163
+ useEffect(() => {
164
+ if (!isLoading && profileResponse?.configurationUnits && profileResponse?.profile) {
165
+ setProfileInput({
166
+ ...profileResponse.profile,
167
+ })
168
+
169
+ setProfileInputErrors(getInitialProfileInputErrors(fromCreateView))
170
+ }
171
+ }, [profileResponse, isLoading])
172
+
173
+ // NOTE: Currently sending and receiving values as string, but will parse it to number for payload
174
+ const handleProfileInputChange = ({ action, data }: HandleProfileInputChangeType) => {
175
+ const currentInput = { ...profileInput }
176
+ const currentInputErrors = { ...profileInputErrors }
177
+ const lastSavedConfiguration = profileResponse.profile.configurations
178
+ const currentConfiguration = currentInput.configurations
179
+ const { value, unit } = data ?? { value: null, unit: null }
180
+
181
+ switch (action) {
182
+ case BuildInfraMetaConfigTypes.DESCRIPTION:
183
+ currentInput.description = value
184
+ currentInputErrors.description = validateDescription(value).message
185
+ break
186
+
187
+ case BuildInfraMetaConfigTypes.NAME:
188
+ currentInput.name = value
189
+ currentInputErrors.name = validateName(value).message
190
+ break
191
+
192
+ case BuildInfraConfigTypes.CPU_LIMIT: {
193
+ currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT] = {
194
+ ...currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT],
195
+ value,
196
+ unit,
197
+ }
198
+ const { request, limit } = validateRequestLimit({
199
+ request: {
200
+ value: currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST].value,
201
+ unit: currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST].unit,
202
+ },
203
+ limit: {
204
+ value,
205
+ unit,
206
+ },
207
+ unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.CPU_LIMIT],
208
+ })
209
+
210
+ currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = limit.message
211
+ currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = request.message
212
+ break
213
+ }
214
+
215
+ case BuildInfraConfigTypes.CPU_REQUEST: {
216
+ currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST] = {
217
+ ...currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST],
218
+ value,
219
+ unit,
220
+ }
221
+ const { request, limit } = validateRequestLimit({
222
+ request: {
223
+ value,
224
+ unit,
225
+ },
226
+ limit: {
227
+ value: currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT].value,
228
+ unit: currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT].unit,
229
+ },
230
+ unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.CPU_LIMIT],
231
+ })
232
+
233
+ currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = limit.message
234
+ currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = request.message
235
+ break
236
+ }
237
+
238
+ case BuildInfraConfigTypes.MEMORY_LIMIT: {
239
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT] = {
240
+ ...currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT],
241
+ value,
242
+ unit,
243
+ }
244
+ const { request, limit } = validateRequestLimit({
245
+ request: {
246
+ value: currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].value,
247
+ unit: currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].unit,
248
+ },
249
+ limit: {
250
+ value,
251
+ unit,
252
+ },
253
+ unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.MEMORY_LIMIT],
254
+ })
255
+
256
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = limit.message
257
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = request.message
258
+ break
259
+ }
260
+
261
+ case BuildInfraConfigTypes.MEMORY_REQUEST: {
262
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST] = {
263
+ ...currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST],
264
+ value,
265
+ unit,
266
+ }
267
+ const { request, limit } = validateRequestLimit({
268
+ request: {
269
+ value,
270
+ unit,
271
+ },
272
+ limit: {
273
+ value: currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].value,
274
+ unit: currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].unit,
275
+ },
276
+ unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.MEMORY_LIMIT],
277
+ })
278
+
279
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = limit.message
280
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = request.message
281
+ break
282
+ }
283
+
284
+ case BuildInfraConfigTypes.BUILD_TIMEOUT: {
285
+ currentConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT] = {
286
+ ...currentConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT],
287
+ value,
288
+ unit,
289
+ }
290
+
291
+ currentInputErrors[BuildInfraConfigTypes.BUILD_TIMEOUT] = validateRequiredPositiveInteger(value).message
292
+ break
293
+ }
294
+
295
+ case BuildInfraInheritActions.ACTIVATE_CPU:
296
+ currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT] = {
297
+ ...lastSavedConfiguration[BuildInfraConfigTypes.CPU_LIMIT],
298
+ value: lastSavedConfiguration[BuildInfraConfigTypes.CPU_LIMIT].value,
299
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.CPU_LIMIT].unit,
300
+ active: true,
301
+ }
302
+ currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST] = {
303
+ ...lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST],
304
+ value: lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST].value,
305
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST].unit,
306
+ active: true,
307
+ }
308
+
309
+ currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = null
310
+ currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = null
311
+ break
312
+
313
+ case BuildInfraInheritActions.ACTIVATE_MEMORY:
314
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT] = {
315
+ ...lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT],
316
+ value: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].value,
317
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].unit,
318
+ active: true,
319
+ }
320
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST] = {
321
+ ...lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST],
322
+ value: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].value,
323
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].unit,
324
+ active: true,
325
+ }
326
+
327
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = null
328
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = null
329
+ break
330
+
331
+ case BuildInfraInheritActions.ACTIVATE_BUILD_TIMEOUT:
332
+ currentConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT] = {
333
+ ...lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT],
334
+ value: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].value,
335
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].unit,
336
+ active: true,
337
+ }
338
+
339
+ currentInputErrors[BuildInfraConfigTypes.BUILD_TIMEOUT] = null
340
+ break
341
+
342
+ case BuildInfraInheritActions.DE_ACTIVATE_BUILD_TIMEOUT:
343
+ // Reverting the value and unit to defaultValues
344
+ currentConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT] = {
345
+ ...currentConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT],
346
+ value: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].defaultValue.value,
347
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].defaultValue.unit,
348
+ active: false,
349
+ }
350
+
351
+ currentInputErrors[BuildInfraConfigTypes.BUILD_TIMEOUT] = null
352
+ break
353
+
354
+ case BuildInfraInheritActions.DE_ACTIVATE_CPU:
355
+ currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT] = {
356
+ ...currentConfiguration[BuildInfraConfigTypes.CPU_LIMIT],
357
+ value: lastSavedConfiguration[BuildInfraConfigTypes.CPU_LIMIT].defaultValue.value,
358
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.CPU_LIMIT].defaultValue.unit,
359
+ active: false,
360
+ }
361
+ currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST] = {
362
+ ...currentConfiguration[BuildInfraConfigTypes.CPU_REQUEST],
363
+ value: lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST].defaultValue.value,
364
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST].defaultValue.unit,
365
+ active: false,
366
+ }
367
+
368
+ currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = null
369
+ currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = null
370
+ break
371
+
372
+ case BuildInfraInheritActions.DE_ACTIVATE_MEMORY:
373
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT] = {
374
+ ...currentConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT],
375
+ value: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].defaultValue.value,
376
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_LIMIT].defaultValue.unit,
377
+ active: false,
378
+ }
379
+ currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST] = {
380
+ ...currentConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST],
381
+ value: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].defaultValue.value,
382
+ unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].defaultValue.unit,
383
+ active: false,
384
+ }
385
+
386
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = null
387
+ currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = null
388
+ break
389
+
390
+ default:
391
+ throw new Error(BUILD_INFRA_TEXT.getInvalidActionMessage(action))
392
+ }
393
+
394
+ setProfileInput(currentInput)
395
+ setProfileInputErrors(currentInputErrors)
396
+ }
397
+
398
+ const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
399
+ e.preventDefault()
400
+ // Since considering '' as a valid error message
401
+ const hasErrors =
402
+ Object.keys(profileInputErrors).filter(
403
+ (item) => profileInputErrors[item] !== null && profileInputErrors[item] !== undefined,
404
+ ).length > 0
405
+
406
+ if (hasErrors) {
407
+ toast.error(BUILD_INFRA_TEXT.INVALID_FORM_MESSAGE)
408
+ return
409
+ }
410
+
411
+ setLoadingActionRequest(true)
412
+ try {
413
+ if (editProfile) {
414
+ await updateBuildInfraProfile({ name, profileInput })
415
+ } else {
416
+ await createBuildInfraProfile({ profileInput })
417
+ }
418
+ setLoadingActionRequest(false)
419
+ toast.success(BUILD_INFRA_TEXT.getSubmitSuccessMessage(profileInput.name, editProfile))
420
+
421
+ if (handleSuccessRedirection) {
422
+ handleSuccessRedirection()
423
+ } else {
424
+ reloadRequest()
425
+ }
426
+ } catch (err) {
427
+ showError(err)
428
+ setLoadingActionRequest(false)
429
+ }
430
+ }
431
+
432
+ return {
433
+ isLoading,
434
+ profileResponse,
435
+ responseError,
436
+ reloadRequest,
437
+ profileInput,
438
+ profileInputErrors,
439
+ handleProfileInputChange,
440
+ loadingActionRequest,
441
+ handleSubmit,
442
+ }
443
+ }
444
+
445
+ const getOptionBackgroundColor = (isFocused: boolean, isSelected: boolean): string => {
446
+ if (isSelected) {
447
+ return 'var(--B100)'
448
+ }
449
+
450
+ if (isFocused) {
451
+ return 'var(--N50)'
452
+ }
453
+ return 'var(--white)'
454
+ }
455
+
456
+ export const unitSelectorStyles = () =>
457
+ getCommonSelectStyle({
458
+ control: (base, state) => ({
459
+ ...base,
460
+ borderRadius: 0,
461
+ backgroundColor: 'var(--N0)',
462
+ border: state.isFocused ? '1px solid var(--B500) !important' : '1px solid var(--N200)',
463
+ alignItems: 'center',
464
+ cursor: 'pointer',
465
+ borderTopRightRadius: '4px',
466
+ borderBottomRightRadius: '4px',
467
+ overflow: 'hidden',
468
+ textOverflow: 'ellipsis',
469
+ whiteSpace: 'nowrap',
470
+ outline: 'none',
471
+ boxShadow: 'none',
472
+ '&:hover': {
473
+ border: '1px solid var(--N400)',
474
+ },
475
+ }),
476
+ indicatorContainer: (base) => ({
477
+ ...base,
478
+ padding: '0px',
479
+ }),
480
+ dropdownIndicator: (base, state) => ({
481
+ ...base,
482
+ color: 'var(--N600)',
483
+ transition: 'all .2s ease',
484
+ transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
485
+ }),
486
+ option: (base, state) => ({
487
+ ...base,
488
+ padding: '4px 12px',
489
+ backgroundColor: getOptionBackgroundColor(state.isFocused, state.isSelected),
490
+ color: 'var(--N900)',
491
+ cursor: 'pointer',
492
+ overflow: 'hidden',
493
+ textOverflow: 'ellipsis',
494
+ whiteSpace: 'nowrap',
495
+ height: '36px',
496
+ }),
497
+ valueContainer: (base) => ({
498
+ ...base,
499
+ color: 'var(--N900)',
500
+ fontSize: '13px',
501
+ fontWeight: '400',
502
+ lineHeight: '20px',
503
+ }),
504
+ menuList: (base) => ({
505
+ ...base,
506
+ maxHeight: '164px',
507
+ height: '100%',
508
+ }),
509
+ })
@@ -1 +1 @@
1
- export * from './Authorization'
1
+ export * from './BuildInfra'
@@ -0,0 +1,41 @@
1
+ import { ErrorScreenNotAuthorized, GenericEmptyState, Progressing, Reload } from '../../../Common'
2
+ import { NOT_FOUND_DEFAULT_TEXT } from './constants'
3
+ import { APIResponseHandlerProps } from './types'
4
+
5
+ const APIResponseHandler = ({
6
+ isLoading,
7
+ progressingProps,
8
+ error,
9
+ notAuthorized,
10
+ notFoundText,
11
+ reloadProps,
12
+ children,
13
+ }: APIResponseHandlerProps) => {
14
+ // keeping it above loading since, not expected to send a call if not authorized
15
+ if (notAuthorized) {
16
+ return <ErrorScreenNotAuthorized />
17
+ }
18
+
19
+ if (isLoading) {
20
+ return <Progressing {...progressingProps} />
21
+ }
22
+
23
+ if (error) {
24
+ // TODO: Can extend ErrorScreenNotFound
25
+ if (error?.code === 404) {
26
+ return (
27
+ <GenericEmptyState
28
+ title={notFoundText?.title ?? NOT_FOUND_DEFAULT_TEXT.title}
29
+ subTitle={notFoundText?.subTitle ?? NOT_FOUND_DEFAULT_TEXT.subTitle}
30
+ />
31
+ )
32
+ }
33
+ return <Reload {...reloadProps} />
34
+ }
35
+
36
+ // Had to add this since while using it is throwing ts error
37
+ // eslint-disable-next-line react/jsx-no-useless-fragment
38
+ return <>{children}</>
39
+ }
40
+
41
+ export default APIResponseHandler
@@ -0,0 +1,5 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export const NOT_FOUND_DEFAULT_TEXT = {
3
+ title: 'Resource not found',
4
+ subTitle: 'The resource you are looking for does not exist',
5
+ } as const
@@ -0,0 +1,2 @@
1
+ export { default as APIResponseHandler } from './APIResponseHandler'
2
+ export * from './types'
@@ -0,0 +1,39 @@
1
+ import { ReactNode } from 'react'
2
+ import { GenericEmptyStateType, ProgressingProps, ReloadType, ServerErrors } from '../../../Common'
3
+
4
+ export interface EmptyPageTextType {
5
+ title?: GenericEmptyStateType['title']
6
+ subTitle?: GenericEmptyStateType['subTitle']
7
+ }
8
+
9
+ export interface APIResponseHandlerProps {
10
+ /**
11
+ * If true, would show Progressing component
12
+ */
13
+ isLoading?: boolean
14
+ /**
15
+ * If loading is true, would load send these props to Progressing component
16
+ */
17
+ progressingProps?: ProgressingProps
18
+ /**
19
+ * If true and isLoading is false would show default Reload component
20
+ * In case error code is 404 show default 404 page using GenericEmptyState
21
+ */
22
+ error?: ServerErrors
23
+ /**
24
+ * Page text for 404 page
25
+ */
26
+ notFoundText?: EmptyPageTextType
27
+ /**
28
+ * If true would show Not Authorized page
29
+ */
30
+ notAuthorized?: boolean
31
+ /**
32
+ * If given, on Error, would load these props
33
+ */
34
+ reloadProps?: ReloadType
35
+ /**
36
+ * If no Error and no Loading, would load this component
37
+ */
38
+ children: ReactNode
39
+ }
@@ -0,0 +1,81 @@
1
+ import BulkSelectionDropdownItems from './BulkSelectionDropdownItems'
2
+ import { CHECKBOX_VALUE, Checkbox, PopupMenu, noop } from '../../../Common'
3
+ import { BulkSelectionDropdownItemsType, BulkSelectionEvents, BulkSelectionProps } from './types'
4
+ import { BULK_DROPDOWN_TEST_ID, BulkSelectionOptionsLabels } from './constants'
5
+ import { ReactComponent as ICChevronDown } from '../../../Assets/Icon/ic-chevron-down.svg'
6
+ import { ReactComponent as ICCheckSquare } from '../../../Assets/Icon/ic-check-square.svg'
7
+ import { ReactComponent as ICCheckAll } from '../../../Assets/Icon/ic-check-all.svg'
8
+ import { ReactComponent as ICClose } from '../../../Assets/Icon/ic-close.svg'
9
+
10
+ const BulkSelection = <T,>({
11
+ checkboxValue,
12
+ isChecked,
13
+ selectedIdentifiers,
14
+ handleBulkSelection,
15
+ showPagination,
16
+ }: BulkSelectionProps<T>) => {
17
+ const areOptionsSelected = Object.keys(selectedIdentifiers).length > 0
18
+ const BulkSelectionItems: BulkSelectionDropdownItemsType[] = [
19
+ {
20
+ locator: BulkSelectionEvents.SELECT_ALL_ON_PAGE,
21
+ label: BulkSelectionOptionsLabels[BulkSelectionEvents.SELECT_ALL_ON_PAGE],
22
+ isSelected: isChecked && checkboxValue === CHECKBOX_VALUE.CHECKED,
23
+ icon: ICCheckSquare,
24
+ },
25
+ ...(showPagination
26
+ ? [
27
+ {
28
+ locator: BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES,
29
+ label: BulkSelectionOptionsLabels[BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES],
30
+ isSelected: isChecked && checkboxValue === CHECKBOX_VALUE.BULK_CHECKED,
31
+ icon: ICCheckAll,
32
+ },
33
+ ]
34
+ : []),
35
+ ...(areOptionsSelected
36
+ ? [
37
+ {
38
+ locator: BulkSelectionEvents.CLEAR_ALL_SELECTIONS,
39
+ label: BulkSelectionOptionsLabels[BulkSelectionEvents.CLEAR_ALL_SELECTIONS],
40
+ isSelected: false,
41
+ icon: ICClose,
42
+ },
43
+ ]
44
+ : []),
45
+ ]
46
+
47
+ return (
48
+ <PopupMenu autoClose>
49
+ <PopupMenu.Button
50
+ isKebab
51
+ rootClassName="h-20 flexbox p-0 dc__no-background dc__no-border dc__outline-none-imp"
52
+ dataTestId={BULK_DROPDOWN_TEST_ID}
53
+ >
54
+ <Checkbox
55
+ isChecked={isChecked}
56
+ onChange={noop}
57
+ rootClassName="icon-dim-20"
58
+ value={checkboxValue}
59
+ // Ideally should be disabled but was giving issue with cursor
60
+ />
61
+
62
+ <ICChevronDown className="icon-dim-20 icon-n6" />
63
+ </PopupMenu.Button>
64
+
65
+ <PopupMenu.Body rootClassName="dc__top-22 w-150 dc__right-0 pt-4 pb-4 pl-0 pr-0 bcn-0 flex column dc__content-start dc__align-start dc__position-abs bcn-0 dc__border dc__border-radius-4-imp">
66
+ {BulkSelectionItems.map((item) => (
67
+ <BulkSelectionDropdownItems<T>
68
+ key={item.locator}
69
+ locator={item.locator}
70
+ label={item.label}
71
+ isSelected={item.isSelected}
72
+ icon={item.icon}
73
+ handleBulkSelection={handleBulkSelection}
74
+ />
75
+ ))}
76
+ </PopupMenu.Body>
77
+ </PopupMenu>
78
+ )
79
+ }
80
+
81
+ export default BulkSelection