Skip to content

Commit cd5e727

Browse files
committed
refactor: replace select picker in chart values view
1 parent f8c6ecb commit cd5e727

File tree

4 files changed

+40
-141
lines changed

4 files changed

+40
-141
lines changed

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

Lines changed: 38 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { useEffect, useState } from 'react'
1818
import { GroupBase } from 'react-select'
1919
import { useParams } from 'react-router-dom'
20-
import ReactSelect from 'react-select'
2120
import {
2221
Progressing,
2322
DeleteDialog,
@@ -34,16 +33,8 @@ import {
3433
getSelectPickerOptionByValue,
3534
} from '@devtron-labs/devtron-fe-common-lib'
3635
import Tippy from '@tippyjs/react'
37-
import {
38-
DropdownIndicator,
39-
EnvFormatOptions,
40-
formatHighlightedText,
41-
getCommonSelectStyle,
42-
GroupHeading,
43-
Option,
44-
} from '../../common/ReactSelect.utils'
4536
import { ReactComponent as Error } from '../../../../assets/icons/ic-warning.svg'
46-
import { importComponentFromFELibrary, Select } from '../../../common'
37+
import { importComponentFromFELibrary } from '../../../common'
4738
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
4839
import { ReactComponent as EditIcon } from '../../../../assets/icons/ic-pencil.svg'
4940
import { AUTO_GENERATE_GITOPS_REPO, GITOPS_REPO_REQUIRED, GITOPS_REPO_REQUIRED_FOR_ENV } from './constant'
@@ -76,7 +67,6 @@ import {
7667
import { DeploymentAppTypeNameMapping, REQUIRED_FIELD_MSG } from '../../../../config/constantMessaging'
7768
import { ReactComponent as ArgoCD } from '../../../../assets/icons/argo-cd-app.svg'
7869
import { ReactComponent as Helm } from '../../../../assets/icons/helm-app.svg'
79-
import { envGroupStyle } from './ChartValuesView.utils'
8070
import { DELETE_ACTION, repoType } from '../../../../config'
8171
import UserGitRepo from '../../../gitOps/UserGitRepo'
8272
import { getChartValuesFiltered } from '@Components/charts/charts.helper'
@@ -92,18 +82,17 @@ export const ChartEnvironmentSelector = ({
9282
selectedEnvironment,
9383
handleEnvironmentSelection,
9484
environments,
95-
invalidaEnvironment,
85+
invalidEnvironment,
9686
isVirtualEnvironmentOnSelector,
9787
isVirtualEnvironment,
9888
}: ChartEnvironmentSelectorType): JSX.Element => {
99-
const singleOption = (props) => {
100-
return <EnvFormatOptions {...props} environmentfieldName="label" />
101-
}
10289

10390
const renderVirtualEnvironmentInfoText = (): JSX.Element => {
10491
if (isVirtualEnvironmentOnSelector && VirtualEnvSelectionInfoText) {
10592
return <VirtualEnvSelectionInfoText />
10693
}
94+
95+
return null
10796
}
10897

10998
const renderVirtualTippy = (): JSX.Element => {
@@ -117,10 +106,6 @@ export const ChartEnvironmentSelector = ({
117106
}
118107
}
119108

120-
const handleFormatHighlightedText = (opt, { inputValue }) => {
121-
return formatHighlightedText(opt, inputValue, 'label')
122-
}
123-
124109
return !isDeployChartView ? (
125110
<div className="chart-values__environment-container mb-12">
126111
<h2
@@ -143,26 +128,17 @@ export const ChartEnvironmentSelector = ({
143128
</div>
144129
) : (
145130
<div className="form__row form__row--w-100 fw-4">
146-
<span className="form__label required-field" data-testid="environment-name-heading">
147-
Deploy to environment
148-
</span>
149-
<ReactSelect
150-
components={{
151-
IndicatorSeparator: null,
152-
DropdownIndicator,
153-
SingleValue: singleOption,
154-
GroupHeading,
155-
}}
156-
classNamePrefix="values-environment-select"
131+
<SelectPicker
132+
label="Deploy to environment"
133+
inputId="values-environment-select"
157134
placeholder="Select Environment"
158135
value={selectedEnvironment}
159-
styles={envGroupStyle}
160136
onChange={handleEnvironmentSelection}
161137
options={environments}
162-
formatOptionLabel={handleFormatHighlightedText}
138+
required
139+
error={invalidEnvironment ? REQUIRED_FIELD_MSG : null}
140+
helperText={renderVirtualEnvironmentInfoText()}
163141
/>
164-
{invalidaEnvironment && renderValidationErrorLabel()}
165-
{renderVirtualEnvironmentInfoText()}
166142
</div>
167143
)
168144
}
@@ -476,65 +452,50 @@ export const ChartProjectSelector = ({
476452
invalidProject,
477453
}: ChartProjectSelectorType): JSX.Element => {
478454
return (
479-
<label className="form__row form__row--w-100 fw-4">
480-
<span className="form__label required-field" data-testid="project-name-heading">
481-
Project
482-
</span>
483-
<ReactSelect
484-
components={{
485-
IndicatorSeparator: null,
486-
DropdownIndicator,
487-
Option,
488-
}}
455+
<div className="form__row form__row--w-100">
456+
<SelectPicker
457+
label="Project"
458+
inputId="select-chart-project"
489459
placeholder="Select Project"
490-
classNamePrefix="select-chart-project"
491460
value={selectedProject}
492-
styles={getCommonSelectStyle()}
493461
onChange={handleProjectSelection}
494462
options={projects}
463+
required
464+
error={invalidProject ? REQUIRED_FIELD_MSG : null}
495465
/>
496-
{invalidProject && renderValidationErrorLabel()}
497-
</label>
466+
</div>
498467
)
499468
}
500469

501470
export const ChartVersionSelector = ({
502471
selectedVersion,
503-
chartVersionObj,
504472
selectedVersionUpdatePage,
505473
handleVersionSelection,
506474
chartVersionsData,
507475
}: ChartVersionSelectorType) => {
476+
const selectOptions = chartVersionsData.map(chartVersion => ({
477+
value: chartVersion.id,
478+
label: chartVersion.version,
479+
}))
480+
481+
const selectedOption = selectOptions.find(
482+
(option) => option.value === selectedVersionUpdatePage?.id || option.value === selectedVersion,
483+
)
484+
508485
return (
509486
<div className="w-100 mb-12">
510-
<span className="form__label fs-13 fw-4 lh-20 cn-7" data-testid="chart-version-heading">
511-
Chart Version
512-
</span>
513-
<Select
514-
tabIndex={4}
515-
rootClassName="select-button--default chart-values-selector"
516-
onChange={(event) => {
517-
handleVersionSelection(event.target.value, {
518-
id: event.target.value,
519-
version: event.target.innerText,
487+
<SelectPicker<number, false>
488+
label="Chart Version"
489+
inputId="chart-values-selector"
490+
options={selectOptions}
491+
onChange={(option) =>
492+
handleVersionSelection(option.value, {
493+
id: option.value,
494+
version: option.label as string,
520495
})
521-
}}
522-
value={selectedVersionUpdatePage?.id || selectedVersion}
523-
dataTestId="select-chart-version"
524-
>
525-
<Select.Button dataTestIdDropdown="chart-version-of-preset">
526-
{selectedVersionUpdatePage?.version || chartVersionObj?.version}
527-
</Select.Button>
528-
{chartVersionsData.map((_chartVersion, index) => (
529-
<Select.Option
530-
key={_chartVersion.id}
531-
value={_chartVersion.id}
532-
dataTestIdMenuList={`chart-select-${index}`}
533-
>
534-
{_chartVersion.version}
535-
</Select.Option>
536-
))}
537-
</Select>
496+
}
497+
value={selectedOption}
498+
/>
538499
</div>
539500
)
540501
}
@@ -588,7 +549,7 @@ export const ChartValuesSelector = ({
588549

589550
return (
590551
<button
591-
className="dc__transparent fs-13 lh-20 flex left dc__gap-4 cb-5 px-8 py-6"
552+
className="dc__transparent fs-13 lh-20 flex left dc__gap-6 cb-5 px-12 py-4"
592553
onClick={redirectToChartValues}
593554
data-testid="add-preset-values-button-dropdown"
594555
>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ const ChartValuesView = ({
16801680
selectedEnvironment={commonState.selectedEnvironment}
16811681
handleEnvironmentSelection={handleEnvironmentSelection}
16821682
environments={commonState.environments}
1683-
invalidaEnvironment={commonState.invalidaEnvironment}
1683+
invalidEnvironment={commonState.invalidaEnvironment}
16841684
isVirtualEnvironmentOnSelector={isVirtualEnvironmentOnSelector}
16851685
isVirtualEnvironment={appDetails?.isVirtualEnvironment}
16861686
/>

src/components/v2/values/chartValuesDiff/ChartValuesView.type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface ChartEnvironmentSelectorType extends ChartSelectorType {
9494
selectedEnvironment?: ChartEnvironmentOptionType
9595
handleEnvironmentSelection?: (selected: ChartEnvironmentOptionType) => void
9696
environments?: ChartEnvironmentOptionType[] | ChartEnvironmentListType[]
97-
invalidaEnvironment: boolean
97+
invalidEnvironment: boolean
9898
isVirtualEnvironmentOnSelector?: boolean
9999
isVirtualEnvironment?: boolean
100100
}

src/components/v2/values/chartValuesDiff/ChartValuesView.utils.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,6 @@ import {
2222
ChartDeploymentManifestDetailResponse,
2323
getDeploymentManifestDetails,
2424
} from '../../chartDeploymentHistory/chartDeploymentHistory.service'
25-
import { groupStyle } from '../../common/ReactSelect.utils'
26-
27-
export const getCommonSelectStyle = (styleOverrides = {}) => {
28-
return {
29-
menuList: (base) => ({
30-
...base,
31-
paddingTop: 0,
32-
paddingBottom: 0,
33-
}),
34-
control: (base, state) => ({
35-
...base,
36-
minHeight: '32px',
37-
boxShadow: 'none',
38-
backgroundColor: 'var(--N50)',
39-
border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)',
40-
cursor: 'pointer',
41-
}),
42-
option: (base, state) => ({
43-
...base,
44-
color: 'var(--N900)',
45-
backgroundColor: state.isFocused ? 'var(--N100)' : 'white',
46-
padding: '10px 12px',
47-
}),
48-
dropdownIndicator: (base, state) => ({
49-
...base,
50-
color: 'var(--N400)',
51-
padding: '0 8px',
52-
transition: 'all .2s ease',
53-
transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
54-
}),
55-
valueContainer: (base) => ({
56-
...base,
57-
padding: '0 8px',
58-
}),
59-
loadingMessage: (base) => ({
60-
...base,
61-
color: 'var(--N600)',
62-
}),
63-
noOptionsMessage: (base) => ({
64-
...base,
65-
color: 'var(--N600)',
66-
}),
67-
...styleOverrides,
68-
}
69-
}
7025

7126
export const getCompareValuesSelectStyles = () => {
7227
return {
@@ -390,20 +345,3 @@ export const convertSchemaJsonToMap = (valuesSchemaJson: string): Map<string, an
390345
}
391346
return null
392347
}
393-
394-
export const envGroupStyle = {
395-
...groupStyle(),
396-
control: (base) => ({
397-
...base,
398-
border: '1px solid #d6dbdf',
399-
background: 'var(--N50)',
400-
minHeight: '32px',
401-
}),
402-
dropdownIndicator: (base, state) => ({
403-
...base,
404-
color: 'var(--N400)',
405-
padding: '0 8px',
406-
transition: 'all .2s ease',
407-
transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
408-
}),
409-
}

0 commit comments

Comments
 (0)