@devtron-labs/devtron-fe-common-lib 0.0.50-beta-1 → 0.0.50
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.
- package/dist/Common/Common.service.d.ts +0 -1
- package/dist/Common/Constants.d.ts +1 -2
- package/dist/Common/Helper.d.ts +0 -9
- package/dist/Common/Types.d.ts +0 -64
- package/dist/Common/index.d.ts +0 -1
- package/dist/index.js +22 -1654
- package/package.json +1 -3
- package/src/Common/Api.ts +4 -2
- package/src/Common/Common.service.ts +0 -4
- package/src/Common/Constants.ts +2 -3
- package/src/Common/Helper.tsx +0 -101
- package/src/Common/Types.ts +0 -69
- package/src/Common/index.ts +0 -1
- package/dist/Common/ChartVersionAndTypeSelector.d.ts +0 -4
- package/src/Common/ChartVersionAndTypeSelector.tsx +0 -78
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtron-labs/devtron-fe-common-lib",
|
|
3
|
-
"version": "0.0.50
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,8 +50,6 @@
|
|
|
50
50
|
"react-router-dom": "^5.3.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"fast-json-patch": "^3.1.1",
|
|
54
|
-
"jsonpath-plus": "^7.2.0",
|
|
55
53
|
"sass": "^1.56.2",
|
|
56
54
|
"tslib": "^2.4.1"
|
|
57
55
|
}
|
package/src/Common/Api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServerErrors } from './ServerError'
|
|
2
|
-
import {
|
|
2
|
+
import { FALLBACK_REQUEST_TIMEOUT, Host, URLS } from './Constants'
|
|
3
3
|
import { ResponseType, APIOptions } from './Types'
|
|
4
4
|
|
|
5
5
|
const responseMessages = {
|
|
@@ -176,7 +176,9 @@ function fetchInTime(
|
|
|
176
176
|
const controller = new AbortController()
|
|
177
177
|
const { signal } = controller
|
|
178
178
|
const timeoutPromise: Promise<ResponseType> = new Promise((resolve, reject) => {
|
|
179
|
-
|
|
179
|
+
const requestTimeout = (window as any)?._env_?.GLOBAL_API_TIMEOUT || FALLBACK_REQUEST_TIMEOUT
|
|
180
|
+
const timeout = options?.timeout ? options.timeout : requestTimeout
|
|
181
|
+
|
|
180
182
|
setTimeout(() => {
|
|
181
183
|
controller.abort()
|
|
182
184
|
reject({
|
package/src/Common/Constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RegistryTypeDetailType } from "./Types"
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const FALLBACK_REQUEST_TIMEOUT = 60000
|
|
4
4
|
export const Host = process.env.REACT_APP_ORCHESTRATOR_ROOT
|
|
5
5
|
|
|
6
6
|
export const DOCUMENTATION_HOME_PAGE = 'https://docs.devtron.ai'
|
|
@@ -24,8 +24,7 @@ export const ROUTES = {
|
|
|
24
24
|
PROJECT_LIST_MIN: 'team/autocomplete',
|
|
25
25
|
USER_CHECK_ROLE: 'user/check/roles',
|
|
26
26
|
IMAGE_TAGGING:'app/image-tagging',
|
|
27
|
-
CD_MATERIAL_GET: 'app/cd-pipeline'
|
|
28
|
-
DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
|
|
27
|
+
CD_MATERIAL_GET: 'app/cd-pipeline'
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
export enum KEY_VALUE {
|
package/src/Common/Helper.tsx
CHANGED
|
@@ -7,8 +7,6 @@ import { ERROR_EMPTY_SCREEN, TOKEN_COOKIE_NAME } from './Constants'
|
|
|
7
7
|
import { ServerErrors } from './ServerError'
|
|
8
8
|
import { toastAccessDenied } from './ToastBody'
|
|
9
9
|
import { AsyncOptions, AsyncState, UseSearchString } from './Types'
|
|
10
|
-
import { JSONPath } from 'jsonpath-plus'
|
|
11
|
-
import * as jsonpatch from 'fast-json-patch'
|
|
12
10
|
|
|
13
11
|
toast.configure({
|
|
14
12
|
autoClose: 3000,
|
|
@@ -460,102 +458,3 @@ export const getUrlWithSearchParams = (url: string, params: Record<string | numb
|
|
|
460
458
|
* Custom exception logger function for logging errors to sentry
|
|
461
459
|
*/
|
|
462
460
|
export const logExceptionToSentry = Sentry.captureException.bind(window)
|
|
463
|
-
|
|
464
|
-
export const customStyles = {
|
|
465
|
-
control: (base, state) => ({
|
|
466
|
-
...base,
|
|
467
|
-
minHeight: '32px',
|
|
468
|
-
boxShadow: 'none',
|
|
469
|
-
border: 'none',
|
|
470
|
-
cursor: 'pointer',
|
|
471
|
-
background: 'transparent',
|
|
472
|
-
}),
|
|
473
|
-
indicatorSeparator: (base, state) => ({
|
|
474
|
-
...base,
|
|
475
|
-
width: 0,
|
|
476
|
-
}),
|
|
477
|
-
valueContainer: (base, state) => ({
|
|
478
|
-
...base,
|
|
479
|
-
padding: '0',
|
|
480
|
-
fontSize: '13px',
|
|
481
|
-
fontWeight: '600',
|
|
482
|
-
}),
|
|
483
|
-
dropdownIndicator: (base, state) => ({
|
|
484
|
-
...base,
|
|
485
|
-
color: 'var(--N400)',
|
|
486
|
-
padding: '0 8px',
|
|
487
|
-
transition: 'all .2s ease',
|
|
488
|
-
transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
489
|
-
}),
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
export const getFilteredChartVersions = (charts, selectedChartType) => {
|
|
493
|
-
// Filter chart versions based on selected chart type
|
|
494
|
-
return charts
|
|
495
|
-
.filter((item) => item?.chartType === selectedChartType.value)
|
|
496
|
-
.map((item) => ({
|
|
497
|
-
value: item?.chartVersion,
|
|
498
|
-
label: item?.chartVersion,
|
|
499
|
-
chartRefId: item.chartRefId,
|
|
500
|
-
}))
|
|
501
|
-
}
|
|
502
|
-
function removeEmptyObjectKeysAndNullValues(obj) {
|
|
503
|
-
// It recursively removes empty object keys and array values that are null
|
|
504
|
-
for (let key in obj) {
|
|
505
|
-
if (Array.isArray(obj[key])) {
|
|
506
|
-
if (obj[key].length === 0) continue
|
|
507
|
-
obj[key] = obj[key].filter((item) => item !== null)
|
|
508
|
-
// Check if the array is empty
|
|
509
|
-
if (obj[key].length === 0) {
|
|
510
|
-
delete obj[key] // Delete the key if the array is empty
|
|
511
|
-
}
|
|
512
|
-
} else if (obj[key] && typeof obj[key] === 'object') {
|
|
513
|
-
if (removeEmptyObjectKeysAndNullValues(obj[key])) {
|
|
514
|
-
delete obj[key]
|
|
515
|
-
}
|
|
516
|
-
} else if (obj[key] === undefined) {
|
|
517
|
-
delete obj[key]
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return Object.keys(obj).length === 0
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
export function getUnlockedJSON(json, jsonPathArray) {
|
|
524
|
-
const jsonCopy = JSON.parse(JSON.stringify(json))
|
|
525
|
-
let patches = jsonPathArray.flatMap((jsonPath) => {
|
|
526
|
-
const pathsToRemove = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' })
|
|
527
|
-
return pathsToRemove.map((result) =>
|
|
528
|
-
Array.isArray(result.parent)
|
|
529
|
-
? { op: 'replace', path: result.pointer, value: null }
|
|
530
|
-
: { op: 'remove', path: result.pointer },
|
|
531
|
-
)
|
|
532
|
-
})
|
|
533
|
-
let newDocument = jsonpatch.applyPatch(jsonCopy, patches).newDocument
|
|
534
|
-
|
|
535
|
-
removeEmptyObjectKeysAndNullValues(newDocument)
|
|
536
|
-
return newDocument
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
export function getLockedJSON(json, jsonPathArray: string[]) {
|
|
540
|
-
const jsonCopy = JSON.parse(JSON.stringify(json))
|
|
541
|
-
let resultJson = {}
|
|
542
|
-
jsonPathArray.forEach((jsonPath) => {
|
|
543
|
-
const elements = JSONPath({ path: jsonPath, json: jsonCopy, resultType: 'all' })
|
|
544
|
-
elements.forEach((element) => {
|
|
545
|
-
const pathArray: string[] = JSONPath.toPathArray(element.path)
|
|
546
|
-
const lastPath = pathArray.pop()
|
|
547
|
-
let current = resultJson
|
|
548
|
-
for (let i = 0; i < pathArray.length; i++) {
|
|
549
|
-
let key = isNaN(Number(pathArray[i])) ? pathArray[i] : parseInt(pathArray[i])
|
|
550
|
-
if (!current[key]) {
|
|
551
|
-
current[key] = isNaN(Number(pathArray[i + 1]??lastPath)) ? {} : []
|
|
552
|
-
}
|
|
553
|
-
current = current[key]
|
|
554
|
-
}
|
|
555
|
-
let key = isNaN(Number(lastPath)) ? lastPath : parseInt(lastPath)
|
|
556
|
-
current[key] = element.value
|
|
557
|
-
})
|
|
558
|
-
})
|
|
559
|
-
return resultJson['$']
|
|
560
|
-
}
|
|
561
|
-
|
package/src/Common/Types.ts
CHANGED
|
@@ -631,75 +631,6 @@ export interface CiPipeline {
|
|
|
631
631
|
isOffendingMandatoryPlugin?: boolean
|
|
632
632
|
pipelineType?: string
|
|
633
633
|
}
|
|
634
|
-
export interface InformationBarProps {
|
|
635
|
-
text: string
|
|
636
|
-
className?: string
|
|
637
|
-
children?: React.ReactNode
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
export interface CodeEditorInterface {
|
|
641
|
-
value?: string
|
|
642
|
-
lineDecorationsWidth?: number
|
|
643
|
-
responseType?: string
|
|
644
|
-
onChange?: (string) => void
|
|
645
|
-
onBlur?: () => void
|
|
646
|
-
onFocus?: () => void
|
|
647
|
-
children?: any
|
|
648
|
-
defaultValue?: string
|
|
649
|
-
mode?: 'json' | 'yaml' | 'shell' | 'dockerfile' | 'plaintext'
|
|
650
|
-
tabSize?: number
|
|
651
|
-
readOnly?: boolean
|
|
652
|
-
noParsing?: boolean
|
|
653
|
-
minHeight?: number
|
|
654
|
-
maxHeight?: number
|
|
655
|
-
inline?: boolean
|
|
656
|
-
height?: number | string
|
|
657
|
-
shebang?: string | JSX.Element
|
|
658
|
-
diffView?: boolean
|
|
659
|
-
loading?: boolean
|
|
660
|
-
customLoader?: JSX.Element
|
|
661
|
-
theme?: string
|
|
662
|
-
original?: string
|
|
663
|
-
focus?: boolean
|
|
664
|
-
validatorSchema?: any
|
|
665
|
-
isKubernetes?: boolean
|
|
666
|
-
cleanData?: boolean
|
|
667
|
-
chartVersion?: any
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
export interface CodeEditorComposition {
|
|
671
|
-
Header?: React.FC<any>
|
|
672
|
-
LanguageChanger?: React.FC<any>
|
|
673
|
-
ThemeChanger?: React.FC<any>
|
|
674
|
-
ValidationError?: React.FC<any>
|
|
675
|
-
Clipboard?: React.FC<any>
|
|
676
|
-
Warning?: React.FC<InformationBarProps>
|
|
677
|
-
ErrorBar?: React.FC<InformationBarProps>
|
|
678
|
-
Information?: React.FC<InformationBarProps>
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
export interface CodeEditorHeaderComposition {
|
|
682
|
-
LanguageChanger?: React.FC<any>;
|
|
683
|
-
ThemeChanger?: React.FC<any>;
|
|
684
|
-
ValidationError?: React.FC<any>;
|
|
685
|
-
Clipboard?: React.FC<any>;
|
|
686
|
-
}
|
|
687
|
-
export interface CodeEditorHeaderInterface {
|
|
688
|
-
children?: any;
|
|
689
|
-
className?: string
|
|
690
|
-
hideDefaultSplitHeader?: boolean;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
export interface DeploymentChartVersionType {
|
|
694
|
-
chartRefId: number
|
|
695
|
-
chartVersion: string
|
|
696
|
-
chartType: string
|
|
697
|
-
type: number
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
export interface ChartVersionAndTypeSelectorProps {
|
|
701
|
-
setSelectedChartRefId: React.Dispatch<React.SetStateAction<number>>
|
|
702
|
-
}
|
|
703
634
|
|
|
704
635
|
export enum PipelineType {
|
|
705
636
|
CI_PIPELINE = 'CI_PIPELINE',
|
package/src/Common/index.ts
CHANGED
|
@@ -42,6 +42,5 @@ export * from './Hooks'
|
|
|
42
42
|
export { AppStatus } from './AppStatus'
|
|
43
43
|
export * from './RJSF'
|
|
44
44
|
export * from './DevtronProgressing'
|
|
45
|
-
export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSelector'
|
|
46
45
|
export * from './AddCDButton'
|
|
47
46
|
export * from './CustomInput'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react'
|
|
2
|
-
import { fetchChartTemplateVersions } from './Common.service'
|
|
3
|
-
import { ChartVersionAndTypeSelectorProps, DeploymentChartVersionType } from './Types'
|
|
4
|
-
import ReactSelect from 'react-select'
|
|
5
|
-
import { customStyles, getFilteredChartVersions, showError } from './Helper'
|
|
6
|
-
|
|
7
|
-
// @TODO: Generalize this component to be used in CodeEditor as Chart selector toolbar
|
|
8
|
-
// when the Code Editor is moved to the fe-common-lib
|
|
9
|
-
const ChartVersionAndTypeSelector = ({ setSelectedChartRefId }: ChartVersionAndTypeSelectorProps) => {
|
|
10
|
-
const [charts, setCharts] = useState<DeploymentChartVersionType[]>([])
|
|
11
|
-
const [selectedChartType, setSelectedChartType] = useState(null)
|
|
12
|
-
const [chartVersionOptions, setChartVersionOptions] = useState([])
|
|
13
|
-
const [chartTypeOptions, setChartTypeOptions] = useState([])
|
|
14
|
-
const [selectedChartVersion, setSelectedChartVersion] = useState(null)
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
fetchChartTemplateVersions()
|
|
18
|
-
.then((res) => {
|
|
19
|
-
const charts = res?.result || []
|
|
20
|
-
setCharts(charts)
|
|
21
|
-
// Extract unique chart types from the data
|
|
22
|
-
const chartTypeOptions = [...new Set(charts.map((item) => item.chartType))].map((type) => ({
|
|
23
|
-
value: type,
|
|
24
|
-
label: type,
|
|
25
|
-
}))
|
|
26
|
-
setChartTypeOptions(chartTypeOptions)
|
|
27
|
-
const filteredVersions = getFilteredChartVersions(charts, chartTypeOptions[0])
|
|
28
|
-
selectFirstChartVersion(filteredVersions)
|
|
29
|
-
})
|
|
30
|
-
.catch((err) => {
|
|
31
|
-
showError(err)
|
|
32
|
-
})
|
|
33
|
-
}, [])
|
|
34
|
-
|
|
35
|
-
const selectFirstChartVersion = (filteredVersions) => {
|
|
36
|
-
setChartVersionOptions(filteredVersions)
|
|
37
|
-
setSelectedChartVersion(filteredVersions[0]) // Select the first chart version by default
|
|
38
|
-
setSelectedChartRefId(filteredVersions[0]?.chartRefId)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Function to update chart version options based on selected chart type
|
|
42
|
-
const handleChartTypeChange = (selectedOption) => {
|
|
43
|
-
setSelectedChartType(selectedOption)
|
|
44
|
-
const filteredVersions = getFilteredChartVersions(charts, selectedOption)
|
|
45
|
-
selectFirstChartVersion(filteredVersions)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Function to handle the change of the selected chart version
|
|
49
|
-
const handleChartVersionChange = (selectedOption) => {
|
|
50
|
-
setSelectedChartVersion(selectedOption)
|
|
51
|
-
setSelectedChartRefId(selectedOption.chartRefId)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<div className="flex">
|
|
56
|
-
<div className="chart-type-options flex" data-testid="chart-type-options">
|
|
57
|
-
<span className="chart-type-options-label mr-4">Chart Type</span>
|
|
58
|
-
<ReactSelect
|
|
59
|
-
value={selectedChartType ?? chartTypeOptions[0]}
|
|
60
|
-
options={chartTypeOptions}
|
|
61
|
-
onChange={handleChartTypeChange}
|
|
62
|
-
styles={customStyles}
|
|
63
|
-
/>
|
|
64
|
-
</div>
|
|
65
|
-
<div className="chart-version-options flex" data-testid="chart-version-options">
|
|
66
|
-
<span className="chart-version-options-label mr-4">Chart Version</span>
|
|
67
|
-
<ReactSelect
|
|
68
|
-
value={selectedChartVersion ?? chartVersionOptions[0]}
|
|
69
|
-
options={chartVersionOptions}
|
|
70
|
-
onChange={handleChartVersionChange}
|
|
71
|
-
styles={customStyles}
|
|
72
|
-
/>
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default ChartVersionAndTypeSelector
|