@devtron-labs/devtron-fe-common-lib 0.0.50 → 0.0.51-beta-3
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/ChartVersionAndTypeSelector.d.ts +4 -0
- package/dist/Common/Common.service.d.ts +1 -0
- package/dist/Common/Constants.d.ts +5 -0
- package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
- package/dist/Common/CustomInput/Types.d.ts +1 -0
- package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
- package/dist/Common/Helper.d.ts +9 -0
- package/dist/Common/Types.d.ts +64 -0
- package/dist/Common/index.d.ts +1 -0
- package/dist/index.js +1670 -21
- package/package.json +3 -1
- package/src/Common/ChartVersionAndTypeSelector.tsx +78 -0
- package/src/Common/Common.service.ts +4 -0
- package/src/Common/Constants.ts +7 -1
- package/src/Common/CustomInput/CustomInput.tsx +3 -2
- package/src/Common/CustomInput/Types.ts +1 -0
- package/src/Common/EmptyState/GenericEmptyState.tsx +37 -13
- package/src/Common/Helper.tsx +101 -0
- package/src/Common/Types.ts +69 -0
- package/src/Common/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtron-labs/devtron-fe-common-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51-beta-3",
|
|
4
4
|
"description": "Supporting common component library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,6 +50,8 @@
|
|
|
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",
|
|
53
55
|
"sass": "^1.56.2",
|
|
54
56
|
"tslib": "^2.4.1"
|
|
55
57
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
package/src/Common/Constants.ts
CHANGED
|
@@ -24,7 +24,8 @@ 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'
|
|
27
|
+
CD_MATERIAL_GET: 'app/cd-pipeline',
|
|
28
|
+
DEPLOYMENT_TEMPLATE_LIST: 'app/template/list'
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export enum KEY_VALUE {
|
|
@@ -239,4 +240,9 @@ export const RepositoryAction = {
|
|
|
239
240
|
CONTAINER: "CONTAINER",
|
|
240
241
|
CHART_PULL: "CHART_PULL",
|
|
241
242
|
CHART_PUSH: "CHART_PUSH"
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export enum APPROVAL_MODAL_TYPE {
|
|
246
|
+
CONFIG = 'CONFIG',
|
|
247
|
+
DEPLOYMENT = 'DEPLOYMENT',
|
|
242
248
|
}
|
|
@@ -28,7 +28,8 @@ export function CustomInput({
|
|
|
28
28
|
defaultValue,
|
|
29
29
|
onKeyDown,
|
|
30
30
|
required,
|
|
31
|
-
additionalErrorInfo
|
|
31
|
+
additionalErrorInfo,
|
|
32
|
+
inputWrapClassname = '',
|
|
32
33
|
}: CustomInputProps) {
|
|
33
34
|
|
|
34
35
|
function handleError(error: any): any[] {
|
|
@@ -92,7 +93,7 @@ export function CustomInput({
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
return (
|
|
95
|
-
<div className=
|
|
96
|
+
<div className={`flex column left top ${inputWrapClassname}`}>
|
|
96
97
|
{renderInputLabel()}
|
|
97
98
|
<input
|
|
98
99
|
data-testid={dataTestid}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React from 'react'
|
|
2
2
|
import AppNotDeployed from '../../Assets/Img/app-not-deployed.png'
|
|
3
3
|
import { GenericEmptyStateType, ImageType } from '../Types'
|
|
4
4
|
|
|
@@ -19,24 +19,48 @@ function GenericEmptyState({
|
|
|
19
19
|
SvgImage,
|
|
20
20
|
noImage,
|
|
21
21
|
layout = 'column',
|
|
22
|
-
contentClassName = ''
|
|
22
|
+
contentClassName = '',
|
|
23
23
|
}: GenericEmptyStateType): JSX.Element {
|
|
24
|
-
const isRowLayout = layout === 'row'
|
|
25
|
-
|
|
24
|
+
const isRowLayout = layout === 'row'
|
|
25
|
+
|
|
26
|
+
const getImageSize = () => {
|
|
27
|
+
switch (imageType) {
|
|
28
|
+
case ImageType.Medium:
|
|
29
|
+
return { width: '200', height: '160' }
|
|
30
|
+
case ImageType.Large:
|
|
31
|
+
return { width: '250', height: '200' }
|
|
32
|
+
default:
|
|
33
|
+
return { width: '200', height: '160' }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
return (
|
|
27
38
|
<div
|
|
28
|
-
className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${
|
|
39
|
+
className={`flex ${isRowLayout ? 'dc__gap-32' : 'column dc__gap-20'} empty-state ${
|
|
40
|
+
classname ? classname : ''
|
|
41
|
+
}`}
|
|
29
42
|
style={styles}
|
|
30
43
|
data-testid="generic-empty-state"
|
|
31
44
|
{...(heightToDeduct >= 0 && { style: { ...styles, height: `calc(100vh - ${heightToDeduct}px)` } })}
|
|
32
|
-
>
|
|
33
|
-
{!SvgImage ?
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
>
|
|
46
|
+
{!SvgImage ? (
|
|
47
|
+
!noImage && (
|
|
48
|
+
<img
|
|
49
|
+
className={imageClassName ? imageClassName : ''}
|
|
50
|
+
src={image || AppNotDeployed}
|
|
51
|
+
width={getImageSize().width}
|
|
52
|
+
height={getImageSize().height}
|
|
53
|
+
alt="empty-state"
|
|
54
|
+
/>
|
|
55
|
+
)
|
|
56
|
+
) : (
|
|
57
|
+
<SvgImage style={{ width: `${getImageSize().width}px`, height: `${getImageSize().height}px` }} />
|
|
58
|
+
)}
|
|
59
|
+
<div
|
|
60
|
+
className={`flex column dc__gap-10 dc__mxw-300 ${
|
|
61
|
+
isRowLayout ? 'dc__align-start' : ''
|
|
62
|
+
} ${contentClassName}`}
|
|
63
|
+
>
|
|
40
64
|
<h4 className="title fw-6 cn-9 mt-0 mb-0">{title}</h4>
|
|
41
65
|
{subTitle && <p className={`subtitle ${isRowLayout ? 'subtitle--text-start' : ''}`}>{subTitle}</p>}
|
|
42
66
|
{isButtonAvailable && renderButton()}
|
package/src/Common/Helper.tsx
CHANGED
|
@@ -7,6 +7,8 @@ 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'
|
|
10
12
|
|
|
11
13
|
toast.configure({
|
|
12
14
|
autoClose: 3000,
|
|
@@ -458,3 +460,102 @@ export const getUrlWithSearchParams = (url: string, params: Record<string | numb
|
|
|
458
460
|
* Custom exception logger function for logging errors to sentry
|
|
459
461
|
*/
|
|
460
462
|
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,6 +631,75 @@ 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
|
+
}
|
|
634
703
|
|
|
635
704
|
export enum PipelineType {
|
|
636
705
|
CI_PIPELINE = 'CI_PIPELINE',
|
package/src/Common/index.ts
CHANGED
|
@@ -42,5 +42,6 @@ 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'
|
|
45
46
|
export * from './AddCDButton'
|
|
46
47
|
export * from './CustomInput'
|