15
15
*/
16
16
17
17
import { useEffect , useState } from 'react'
18
+ import { GroupBase } from 'react-select'
18
19
import { useParams } from 'react-router-dom'
19
20
import ReactSelect from 'react-select'
20
21
import {
@@ -28,6 +29,9 @@ import {
28
29
Drawer ,
29
30
TippyTheme ,
30
31
GitOpsAuthModeType ,
32
+ SelectPicker ,
33
+ SelectPickerOptionType ,
34
+ getSelectPickerOptionByValue ,
31
35
} from '@devtron-labs/devtron-fe-common-lib'
32
36
import Tippy from '@tippyjs/react'
33
37
import {
@@ -39,12 +43,12 @@ import {
39
43
Option ,
40
44
} from '../../common/ReactSelect.utils'
41
45
import { ReactComponent as Error } from '../../../../assets/icons/ic-warning.svg'
42
- import { ChartValuesSelect } from '../../../charts/util/ChartValueSelect'
43
46
import { importComponentFromFELibrary , Select } from '../../../common'
44
47
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
45
48
import { ReactComponent as EditIcon } from '../../../../assets/icons/ic-pencil.svg'
46
49
import { AUTO_GENERATE_GITOPS_REPO , GITOPS_REPO_REQUIRED , GITOPS_REPO_REQUIRED_FOR_ENV } from './constant'
47
50
import './ChartValuesView.scss'
51
+ import { ReactComponent as ICAdd } from '@Icons/ic-add.svg'
48
52
49
53
import {
50
54
ActiveReadmeColumnProps ,
@@ -75,6 +79,8 @@ import { ReactComponent as Helm } from '../../../../assets/icons/helm-app.svg'
75
79
import { envGroupStyle } from './ChartValuesView.utils'
76
80
import { DELETE_ACTION , repoType } from '../../../../config'
77
81
import UserGitRepo from '../../../gitOps/UserGitRepo'
82
+ import { getChartValuesFiltered } from '@Components/charts/charts.helper'
83
+ import { ChartValuesType } from '@Components/charts/charts.types'
78
84
79
85
const VirtualEnvSelectionInfoText = importComponentFromFELibrary ( 'VirtualEnvSelectionInfoText' )
80
86
const VirtualEnvHelpTippy = importComponentFromFELibrary ( 'VirtualEnvHelpTippy' )
@@ -541,21 +547,69 @@ export const ChartValuesSelector = ({
541
547
hideVersionFromLabel,
542
548
hideCreateNewOption,
543
549
} : ChartValuesSelectorType ) => {
550
+ const filteredChartValues = getChartValuesFiltered ( chartValuesList )
551
+
552
+ const selectOptions : GroupBase < SelectPickerOptionType < ChartValuesType > > [ ] = [
553
+ {
554
+ label : 'Deployed' ,
555
+ options : filteredChartValues . deployedChartValues . map ( ( chartValue ) => ( {
556
+ value : chartValue ,
557
+ label : `${ chartValue . name } ${ chartValue . chartVersion } ` ,
558
+ description : `Deployed on: ${ chartValue . environmentName || '' } ` ,
559
+ } ) ) ,
560
+ } ,
561
+ {
562
+ label : 'Preset Values' ,
563
+ options : filteredChartValues . savedChartValues . map ( ( chartValue ) => ( {
564
+ value : chartValue ,
565
+ label : `${ chartValue . name } ${ chartValue . chartVersion } ` ,
566
+ } ) ) ,
567
+ } ,
568
+ {
569
+ label : 'Existing' ,
570
+ options : filteredChartValues . existingChartValues . map ( ( chartValue ) => ( {
571
+ value : chartValue ,
572
+ label : `${ chartValue . name } ${ hideVersionFromLabel || ! chartValue . chartVersion ? '' : ` (${ chartValue . chartVersion } )` } ` ,
573
+ } ) ) ,
574
+ } ,
575
+ {
576
+ label : 'Default' ,
577
+ options : filteredChartValues . defaultChartValues . map ( ( chartValue ) => ( {
578
+ value : chartValue ,
579
+ label : `${ chartValue . name } ${ chartValue . chartVersion } ` ,
580
+ } ) ) ,
581
+ } ,
582
+ ]
583
+
584
+ const renderMenuListFooter = ( ) => {
585
+ if ( hideCreateNewOption ) {
586
+ return null
587
+ }
588
+
589
+ return (
590
+ < button
591
+ className = "dc__transparent fs-13 lh-20 flex left dc__gap-4 cb-5 px-8 py-6"
592
+ onClick = { redirectToChartValues }
593
+ data-testid = "add-preset-values-button-dropdown"
594
+ >
595
+ < ICAdd className = "icon-dim-20 dc__no-shrink fcb-5" />
596
+ Create preset value
597
+ </ button >
598
+ )
599
+ }
600
+
601
+ const selectedOption = getSelectPickerOptionByValue ( selectOptions , chartValues , null )
602
+
544
603
return (
545
- < div className = "w-100 mb-12" >
546
- < span className = "form__label fs-13 fw-4 lh-20 cn-7" data-testid = "chart-values-heading" >
547
- Chart Values
548
- </ span >
549
- < ChartValuesSelect
550
- className = "chart-values-selector"
551
- chartValuesList = { chartValuesList }
552
- chartValues = { chartValues }
553
- redirectToChartValues = { redirectToChartValues }
554
- onChange = { handleChartValuesSelection }
555
- hideVersionFromLabel = { hideVersionFromLabel }
556
- hideCreateNewOption = { hideCreateNewOption }
557
- />
558
- </ div >
604
+ < SelectPicker < ChartValuesType , false >
605
+ inputId = "chart-values-selector"
606
+ options = { selectOptions }
607
+ renderMenuListFooter = { renderMenuListFooter }
608
+ getOptionValue = { ( option ) => `${ option . value . id } ${ option . value . kind } ` }
609
+ label = "Chart Values"
610
+ onChange = { ( selectedOption ) => handleChartValuesSelection ( selectedOption . value ) }
611
+ value = { selectedOption }
612
+ />
559
613
)
560
614
}
561
615
0 commit comments