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