Skip to content

Commit f8c6ecb

Browse files
committed
refactor: replace chart values select
1 parent 7151d5d commit f8c6ecb

File tree

4 files changed

+69
-197
lines changed

4 files changed

+69
-197
lines changed

src/components/charts/util/ChartValueSelect.tsx

Lines changed: 0 additions & 167 deletions
This file was deleted.

src/components/common/Select/select.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@
9999
margin-right: 12px;
100100
}
101101

102-
.option-with-subtitle__subtitle {
103-
font-size: 10px;
104-
font-weight: normal;
105-
font-stretch: normal;
106-
line-height: 1.33;
107-
letter-spacing: normal;
108-
color: #404040;
109-
}
110-
111102
.option-group__label {
112103
padding: 8px 16px;
113104
font-size: 12px;

src/components/v2/values/chartValuesDiff/ChartValuesView.component.tsx

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { useEffect, useState } from 'react'
18+
import { GroupBase } from 'react-select'
1819
import { useParams } from 'react-router-dom'
1920
import ReactSelect from 'react-select'
2021
import {
@@ -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'
3236
import Tippy from '@tippyjs/react'
3337
import {
@@ -39,12 +43,12 @@ import {
3943
Option,
4044
} from '../../common/ReactSelect.utils'
4145
import { ReactComponent as Error } from '../../../../assets/icons/ic-warning.svg'
42-
import { ChartValuesSelect } from '../../../charts/util/ChartValueSelect'
4346
import { importComponentFromFELibrary, Select } from '../../../common'
4447
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
4548
import { ReactComponent as EditIcon } from '../../../../assets/icons/ic-pencil.svg'
4649
import { AUTO_GENERATE_GITOPS_REPO, GITOPS_REPO_REQUIRED, GITOPS_REPO_REQUIRED_FOR_ENV } from './constant'
4750
import './ChartValuesView.scss'
51+
import { ReactComponent as ICAdd } from '@Icons/ic-add.svg'
4852

4953
import {
5054
ActiveReadmeColumnProps,
@@ -75,6 +79,8 @@ import { ReactComponent as Helm } from '../../../../assets/icons/helm-app.svg'
7579
import { envGroupStyle } from './ChartValuesView.utils'
7680
import { DELETE_ACTION, repoType } from '../../../../config'
7781
import UserGitRepo from '../../../gitOps/UserGitRepo'
82+
import { getChartValuesFiltered } from '@Components/charts/charts.helper'
83+
import { ChartValuesType } from '@Components/charts/charts.types'
7884

7985
const VirtualEnvSelectionInfoText = importComponentFromFELibrary('VirtualEnvSelectionInfoText')
8086
const 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

src/components/v2/values/chartValuesDiff/ChartValuesView.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@
174174
width: 268px;
175175
}
176176

177-
button.chart-values-selector {
178-
min-height: 32px;
179-
background-color: var(--N50);
180-
padding: 0 8px 0 10px;
181-
}
182-
183177
.chart-deprecated-wrapper {
184178
padding: 10px 12px;
185179
line-height: 18px;

0 commit comments

Comments
 (0)