1515 */
1616
1717import { useEffect , useState } from 'react'
18+ import { GroupBase } from 'react-select'
1819import { useParams } from 'react-router-dom'
1920import ReactSelect from 'react-select'
2021import {
@@ -28,6 +29,9 @@ import {
2829 Drawer ,
2930 TippyTheme ,
3031 GitOpsAuthModeType ,
32+ SelectPicker ,
33+ SelectPickerOptionType ,
34+ getSelectPickerOptionByValue ,
3135} from '@devtron-labs/devtron-fe-common-lib'
3236import Tippy from '@tippyjs/react'
3337import {
@@ -39,12 +43,12 @@ import {
3943 Option ,
4044} from '../../common/ReactSelect.utils'
4145import { ReactComponent as Error } from '../../../../assets/icons/ic-warning.svg'
42- import { ChartValuesSelect } from '../../../charts/util/ChartValueSelect'
4346import { importComponentFromFELibrary , Select } from '../../../common'
4447import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
4548import { ReactComponent as EditIcon } from '../../../../assets/icons/ic-pencil.svg'
4649import { AUTO_GENERATE_GITOPS_REPO , GITOPS_REPO_REQUIRED , GITOPS_REPO_REQUIRED_FOR_ENV } from './constant'
4750import './ChartValuesView.scss'
51+ import { ReactComponent as ICAdd } from '@Icons/ic-add.svg'
4852
4953import {
5054 ActiveReadmeColumnProps ,
@@ -75,6 +79,8 @@ import { ReactComponent as Helm } from '../../../../assets/icons/helm-app.svg'
7579import { envGroupStyle } from './ChartValuesView.utils'
7680import { DELETE_ACTION , repoType } from '../../../../config'
7781import UserGitRepo from '../../../gitOps/UserGitRepo'
82+ import { getChartValuesFiltered } from '@Components/charts/charts.helper'
83+ import { ChartValuesType } from '@Components/charts/charts.types'
7884
7985const VirtualEnvSelectionInfoText = importComponentFromFELibrary ( 'VirtualEnvSelectionInfoText' )
8086const VirtualEnvHelpTippy = importComponentFromFELibrary ( 'VirtualEnvHelpTippy' )
@@ -541,21 +547,69 @@ export const ChartValuesSelector = ({
541547 hideVersionFromLabel,
542548 hideCreateNewOption,
543549} : 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+
544603 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+ />
559613 )
560614}
561615
0 commit comments