@devtron-labs/devtron-fe-common-lib 0.0.58-beta-5 → 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.
@@ -19,8 +19,7 @@ export declare const BUILD_INFRA_TEXT: {
19
19
  NEGATIVE_REQUEST: string;
20
20
  NEGATIVE_LIMIT: string;
21
21
  REQUEST_LESS_THAN_LIMIT: string;
22
- REQUEST_TOO_BIG: string;
23
- LIMIT_TOO_BIG: string;
22
+ CAN_NOT_COMPUTE: string;
24
23
  REQUEST_DECIMAL_PLACES: string;
25
24
  LIMIT_DECIMAL_PLACES: string;
26
25
  };
@@ -246,6 +246,7 @@ export interface CreateBuildInfraServiceConfigurationType {
246
246
  id?: number;
247
247
  }
248
248
  export interface CreateBuildInfraServicePayloadType {
249
+ id: number;
249
250
  name: string;
250
251
  description: string;
251
252
  type: BuildInfraProfileVariants;
package/dist/index.js CHANGED
@@ -28905,8 +28905,7 @@ var BUILD_INFRA_TEXT = {
28905
28905
  NEGATIVE_REQUEST: 'Request should be a positive number.',
28906
28906
  NEGATIVE_LIMIT: 'Limit should be a positive number.',
28907
28907
  REQUEST_LESS_THAN_LIMIT: 'Request should be less than or equal to limit.',
28908
- REQUEST_TOO_BIG: 'Request is too big to compute.',
28909
- LIMIT_TOO_BIG: 'Limit is too big to compute.',
28908
+ CAN_NOT_COMPUTE: 'Request and limit value diff are too high to validate.',
28910
28909
  REQUEST_DECIMAL_PLACES: 'Request should be upto 2 decimal places.',
28911
28910
  LIMIT_DECIMAL_PLACES: 'Limit should be upto 2 decimal places.',
28912
28911
  },
@@ -29126,6 +29125,7 @@ var getBuildInfraProfilePayload = function (profileInput) {
29126
29125
  }, []);
29127
29126
  var payload = {
29128
29127
  name: profileInput.name,
29128
+ id: profileInput.id,
29129
29129
  description: profileInput.description,
29130
29130
  type: profileInput.type,
29131
29131
  configurations: configurations,
@@ -29280,7 +29280,7 @@ var validateRequiredPositiveNumber = function (value) {
29280
29280
  message: 'This field should be a valid positive number',
29281
29281
  };
29282
29282
  }
29283
- if (Number(value) < 0) {
29283
+ if (Number(value) <= 0) {
29284
29284
  return {
29285
29285
  isValid: false,
29286
29286
  message: 'Only positive numbers are allowed',
@@ -29329,22 +29329,6 @@ var validateRequestLimit = function (_a) {
29329
29329
  if (!isRequestValidNumber || !isLimitValidNumber) {
29330
29330
  return requestLimitValidationResponse;
29331
29331
  }
29332
- var isSafeRequestNumber = requestNumber * requestUnit < Number.MAX_SAFE_INTEGER;
29333
- var isSafeLimitNumber = limitNumber * limitUnit < Number.MAX_SAFE_INTEGER;
29334
- if (!isSafeRequestNumber) {
29335
- requestLimitValidationResponse.request = {
29336
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_TOO_BIG,
29337
- isValid: false,
29338
- };
29339
- return requestLimitValidationResponse;
29340
- }
29341
- if (!isSafeLimitNumber) {
29342
- requestLimitValidationResponse.limit = {
29343
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.LIMIT_TOO_BIG,
29344
- isValid: false,
29345
- };
29346
- return requestLimitValidationResponse;
29347
- }
29348
29332
  // only two decimal places are allowed
29349
29333
  var requestDecimalPlaces = (_c = (_b = String(request.value).split('.')[1]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
29350
29334
  var limitDecimalPlaces = (_e = (_d = String(limit.value).split('.')[1]) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0;
@@ -29362,11 +29346,22 @@ var validateRequestLimit = function (_a) {
29362
29346
  };
29363
29347
  return requestLimitValidationResponse;
29364
29348
  }
29365
- if (requestNumber * requestUnit > limitNumber * limitUnit) {
29349
+ var limitRequestUnitFactor = limitUnit / requestUnit;
29350
+ var limitRequestFactor = limitNumber / requestNumber;
29351
+ var isProductSafe = limitRequestUnitFactor * limitRequestFactor <= Number.MAX_SAFE_INTEGER;
29352
+ if (!isProductSafe) {
29353
+ requestLimitValidationResponse.request = {
29354
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.CAN_NOT_COMPUTE,
29355
+ isValid: false,
29356
+ };
29357
+ return requestLimitValidationResponse;
29358
+ }
29359
+ if (limitRequestUnitFactor * limitRequestFactor < 1) {
29366
29360
  requestLimitValidationResponse.request = {
29367
29361
  message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_LESS_THAN_LIMIT,
29368
29362
  isValid: false,
29369
29363
  };
29364
+ return requestLimitValidationResponse;
29370
29365
  }
29371
29366
  return requestLimitValidationResponse;
29372
29367
  };
@@ -29589,7 +29584,7 @@ var getOptionBackgroundColor = function (isFocused, isSelected) {
29589
29584
  };
29590
29585
  var unitSelectorStyles = function () {
29591
29586
  return getCommonSelectStyle({
29592
- control: function (base, state) { return (__assign(__assign({}, base), { borderRadius: 0, backgroundColor: 'var(--N0)', border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)', alignItems: 'center', cursor: 'pointer', borderTopRightRadius: '4px', borderBottomRightRadius: '4px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', outline: 'none', boxShadow: 'none', '&:hover': {
29587
+ control: function (base, state) { return (__assign(__assign({}, base), { borderRadius: 0, backgroundColor: 'var(--N0)', border: state.isFocused ? '1px solid var(--B500) !important' : '1px solid var(--N200)', alignItems: 'center', cursor: 'pointer', borderTopRightRadius: '4px', borderBottomRightRadius: '4px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', outline: 'none', boxShadow: 'none', '&:hover': {
29593
29588
  border: '1px solid var(--N400)',
29594
29589
  } })); },
29595
29590
  indicatorContainer: function (base) { return (__assign(__assign({}, base), { padding: '0px' })); },
@@ -29604,7 +29599,6 @@ var unitSelectorStyles = function () {
29604
29599
  * In case need arise for variants break this CustomInput and Select as a separate component
29605
29600
  */
29606
29601
  var BuildInfraFormAction = function (_a) {
29607
- var _b, _c;
29608
29602
  var actionType = _a.actionType, label = _a.label, placeholder = _a.placeholder, error = _a.error, isRequired = _a.isRequired, profileUnitsMap = _a.profileUnitsMap, handleProfileInputChange = _a.handleProfileInputChange, currentUnitName = _a.currentUnitName, currentValue = _a.currentValue;
29609
29603
  var handleUnitChange = function (selectedUnit) {
29610
29604
  var data = {
@@ -29620,11 +29614,16 @@ var BuildInfraFormAction = function (_a) {
29620
29614
  };
29621
29615
  handleProfileInputChange({ action: actionType, data: data });
29622
29616
  };
29623
- var unitOptions = (_c = (_b = Object.values(profileUnitsMap)) === null || _b === void 0 ? void 0 : _b.map(function (unit) { return ({
29624
- label: unit.name,
29625
- value: unit.name,
29626
- }); })) !== null && _c !== void 0 ? _c : [];
29627
- var currentUnit = unitOptions.find(function (unit) { return unit.value === currentUnitName; });
29617
+ // would also sort the units in order of conversionFactor
29618
+ var _b = React.useMemo(function () {
29619
+ var _a, _b;
29620
+ var units = (_b = (_a = Object.values(profileUnitsMap)) === null || _a === void 0 ? void 0 : _a.map(function (unit) { return ({
29621
+ label: unit.name,
29622
+ value: String(unit.conversionFactor),
29623
+ }); })) !== null && _b !== void 0 ? _b : [];
29624
+ var _currentUnit = units.find(function (unit) { return unit.label === currentUnitName; });
29625
+ return { unitOptions: units.sort(function (a, b) { return Number(a.value) - Number(b.value); }), currentUnit: _currentUnit };
29626
+ }, [profileUnitsMap]), unitOptions = _b.unitOptions, currentUnit = _b.currentUnit;
29628
29627
  return (jsxRuntime.jsxs("div", __assign({ className: "flexbox-col dc__gap-4 dc__mxw-420 w-100 dc__align-start" }, { children: [jsxRuntime.jsx("label", __assign({ htmlFor: "".concat(actionType, "-input"), className: "fs-13 fw-4 lh-20 cn-7 ".concat(isRequired ? 'dc__required-field' : '') }, { children: label })), jsxRuntime.jsxs("div", __assign({ className: "w-100 flexbox dc__align-items-center" }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex-grow-1" }, { children: jsxRuntime.jsx("input", { "data-testid": actionType, name: actionType, type: "number", step: BUILD_INFRA_INPUT_CONSTRAINTS.STEP, min: BUILD_INFRA_INPUT_CONSTRAINTS.MIN, className: "form__input dc__no-right-border dc__no-right-radius", placeholder: placeholder, value: currentValue, onChange: handleInputChange, required: isRequired, autoComplete: "off", id: "".concat(actionType, "-input") }) })), profileUnitsMap && (jsxRuntime.jsx(ReactSelect, { name: "".concat(actionType, "-unit"), className: "bcn-0 dc__mxw-120", options: unitOptions, value: currentUnit, onChange: handleUnitChange, isSearchable: false, components: {
29629
29628
  IndicatorSeparator: null,
29630
29629
  ClearIndicator: null,
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-5",
3
+ "version": "0.0.58-beta-7",
4
4
  "description": "Supporting common component library",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { FormEvent, FunctionComponent } from 'react'
1
+ import { FormEvent, FunctionComponent, useMemo } from 'react'
2
2
  import ReactSelect from 'react-select'
3
3
  import { BuildInfraFormActionProps } from './types'
4
4
  import { OptionType } from '../../../Common'
@@ -36,12 +36,17 @@ const BuildInfraFormAction: FunctionComponent<BuildInfraFormActionProps> = ({
36
36
  handleProfileInputChange({ action: actionType, data })
37
37
  }
38
38
 
39
- const unitOptions: OptionType[] =
40
- Object.values(profileUnitsMap)?.map((unit) => ({
41
- label: unit.name,
42
- value: unit.name,
43
- })) ?? []
44
- const currentUnit = unitOptions.find((unit) => unit.value === currentUnitName)
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])
45
50
 
46
51
  return (
47
52
  <div className="flexbox-col dc__gap-4 dc__mxw-420 w-100 dc__align-start">
@@ -33,8 +33,7 @@ export const BUILD_INFRA_TEXT = {
33
33
  NEGATIVE_REQUEST: 'Request should be a positive number.',
34
34
  NEGATIVE_LIMIT: 'Limit should be a positive number.',
35
35
  REQUEST_LESS_THAN_LIMIT: 'Request should be less than or equal to limit.',
36
- REQUEST_TOO_BIG: 'Request is too big to compute.',
37
- LIMIT_TOO_BIG: 'Limit is too big to compute.',
36
+ CAN_NOT_COMPUTE: 'Request and limit value diff are too high to validate.',
38
37
  REQUEST_DECIMAL_PLACES: 'Request should be upto 2 decimal places.',
39
38
  LIMIT_DECIMAL_PLACES: 'Limit should be upto 2 decimal places.',
40
39
  },
@@ -143,6 +143,7 @@ const getBuildInfraProfilePayload = (
143
143
 
144
144
  const payload: CreateBuildInfraServicePayloadType = {
145
145
  name: profileInput.name,
146
+ id: profileInput.id,
146
147
  description: profileInput.description,
147
148
  type: profileInput.type,
148
149
  configurations,
@@ -292,6 +292,7 @@ export interface CreateBuildInfraServiceConfigurationType {
292
292
  }
293
293
 
294
294
  export interface CreateBuildInfraServicePayloadType {
295
+ id: number
295
296
  name: string
296
297
  description: string
297
298
  type: BuildInfraProfileVariants
@@ -74,53 +74,48 @@ export const validateRequestLimit = ({
74
74
  return requestLimitValidationResponse
75
75
  }
76
76
 
77
- const isSafeRequestNumber = requestNumber * requestUnit < Number.MAX_SAFE_INTEGER
78
- const isSafeLimitNumber = limitNumber * limitUnit < Number.MAX_SAFE_INTEGER
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
79
80
 
80
- if (!isSafeRequestNumber) {
81
+ if (requestDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
81
82
  requestLimitValidationResponse.request = {
82
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_TOO_BIG,
83
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_DECIMAL_PLACES,
83
84
  isValid: false,
84
85
  }
85
86
 
86
87
  return requestLimitValidationResponse
87
88
  }
88
-
89
- if (!isSafeLimitNumber) {
89
+ if (limitDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
90
90
  requestLimitValidationResponse.limit = {
91
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.LIMIT_TOO_BIG,
91
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.LIMIT_DECIMAL_PLACES,
92
92
  isValid: false,
93
93
  }
94
94
 
95
95
  return requestLimitValidationResponse
96
96
  }
97
97
 
98
- // only two decimal places are allowed
99
- const requestDecimalPlaces = String(request.value).split('.')[1]?.length ?? 0
100
- const limitDecimalPlaces = String(limit.value).split('.')[1]?.length ?? 0
98
+ const limitRequestUnitFactor = limitUnit / requestUnit
99
+ const limitRequestFactor = limitNumber / requestNumber
101
100
 
102
- if (requestDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
103
- requestLimitValidationResponse.request = {
104
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_DECIMAL_PLACES,
105
- isValid: false,
106
- }
101
+ const isProductSafe = limitRequestUnitFactor * limitRequestFactor <= Number.MAX_SAFE_INTEGER
107
102
 
108
- return requestLimitValidationResponse
109
- }
110
- if (limitDecimalPlaces > BUILD_INFRA_INPUT_CONSTRAINTS.DECIMAL_PLACES) {
111
- requestLimitValidationResponse.limit = {
112
- message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.LIMIT_DECIMAL_PLACES,
103
+ if (!isProductSafe) {
104
+ requestLimitValidationResponse.request = {
105
+ message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.CAN_NOT_COMPUTE,
113
106
  isValid: false,
114
107
  }
115
108
 
116
109
  return requestLimitValidationResponse
117
110
  }
118
111
 
119
- if (requestNumber * requestUnit > limitNumber * limitUnit) {
112
+ if (limitRequestUnitFactor * limitRequestFactor < 1) {
120
113
  requestLimitValidationResponse.request = {
121
114
  message: BUILD_INFRA_TEXT.VALIDATE_REQUEST_LIMIT.REQUEST_LESS_THAN_LIMIT,
122
115
  isValid: false,
123
116
  }
117
+
118
+ return requestLimitValidationResponse
124
119
  }
125
120
 
126
121
  return requestLimitValidationResponse
@@ -208,6 +203,7 @@ export const useBuildInfraForm = ({
208
203
  },
209
204
  unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.CPU_LIMIT],
210
205
  })
206
+
211
207
  currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = limit.message
212
208
  currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = request.message
213
209
  break
@@ -229,6 +225,7 @@ export const useBuildInfraForm = ({
229
225
  },
230
226
  unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.CPU_LIMIT],
231
227
  })
228
+
232
229
  currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = limit.message
233
230
  currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = request.message
234
231
  break
@@ -251,6 +248,7 @@ export const useBuildInfraForm = ({
251
248
  },
252
249
  unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.MEMORY_LIMIT],
253
250
  })
251
+
254
252
  currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = limit.message
255
253
  currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = request.message
256
254
  break
@@ -273,6 +271,7 @@ export const useBuildInfraForm = ({
273
271
  },
274
272
  unitsMap: profileResponse.configurationUnits[BuildInfraConfigTypes.MEMORY_LIMIT],
275
273
  })
274
+
276
275
  currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = limit.message
277
276
  currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = request.message
278
277
  break
@@ -320,6 +319,7 @@ export const useBuildInfraForm = ({
320
319
  unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].unit,
321
320
  active: true,
322
321
  }
322
+
323
323
  currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = null
324
324
  currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = null
325
325
  break
@@ -331,6 +331,7 @@ export const useBuildInfraForm = ({
331
331
  unit: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].unit,
332
332
  active: true,
333
333
  }
334
+
334
335
  currentInputErrors[BuildInfraConfigTypes.BUILD_TIMEOUT] = null
335
336
  break
336
337
 
@@ -342,6 +343,7 @@ export const useBuildInfraForm = ({
342
343
  unit: lastSavedConfiguration[BuildInfraConfigTypes.BUILD_TIMEOUT].defaultValue.unit,
343
344
  active: false,
344
345
  }
346
+
345
347
  currentInputErrors[BuildInfraConfigTypes.BUILD_TIMEOUT] = null
346
348
  break
347
349
 
@@ -358,6 +360,7 @@ export const useBuildInfraForm = ({
358
360
  unit: lastSavedConfiguration[BuildInfraConfigTypes.CPU_REQUEST].defaultValue.unit,
359
361
  active: false,
360
362
  }
363
+
361
364
  currentInputErrors[BuildInfraConfigTypes.CPU_LIMIT] = null
362
365
  currentInputErrors[BuildInfraConfigTypes.CPU_REQUEST] = null
363
366
  break
@@ -375,6 +378,7 @@ export const useBuildInfraForm = ({
375
378
  unit: lastSavedConfiguration[BuildInfraConfigTypes.MEMORY_REQUEST].defaultValue.unit,
376
379
  active: false,
377
380
  }
381
+
378
382
  currentInputErrors[BuildInfraConfigTypes.MEMORY_LIMIT] = null
379
383
  currentInputErrors[BuildInfraConfigTypes.MEMORY_REQUEST] = null
380
384
  break
@@ -440,7 +444,7 @@ export const unitSelectorStyles = () =>
440
444
  ...base,
441
445
  borderRadius: 0,
442
446
  backgroundColor: 'var(--N0)',
443
- border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)',
447
+ border: state.isFocused ? '1px solid var(--B500) !important' : '1px solid var(--N200)',
444
448
  alignItems: 'center',
445
449
  cursor: 'pointer',
446
450
  borderTopRightRadius: '4px',
@@ -59,7 +59,7 @@ export const validateRequiredPositiveNumber = (value: string | Number): Validati
59
59
  }
60
60
  }
61
61
 
62
- if (Number(value) < 0) {
62
+ if (Number(value) <= 0) {
63
63
  return {
64
64
  isValid: false,
65
65
  message: 'Only positive numbers are allowed',