@devtron-labs/devtron-fe-common-lib 0.0.58-beta-22 → 0.0.58-beta-25

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