11// Copyright 2018-2023 the Kubeapps contributors.
22// SPDX-License-Identifier: Apache-2.0
33
4- import { CdsFormGroup } from "@cds/react/forms" ;
54import actions from "actions" ;
65import AlertGroup from "components/AlertGroup" ;
76import AvailablePackageDetailExcerpt from "components/Catalog/AvailablePackageDetailExcerpt" ;
87import Column from "components/Column" ;
98import DeploymentFormBody from "components/DeploymentForm/DeploymentFormBody" ;
109import LoadingWrapper from "components/LoadingWrapper" ;
1110import PackageHeader from "components/PackageHeader/PackageHeader" ;
12- import PackageVersionSelector from "components/PackageHeader/PackageVersionSelector" ;
1311import Row from "components/Row" ;
1412import * as jsonpatch from "fast-json-patch" ;
1513import { usePush } from "hooks/push" ;
@@ -42,7 +40,7 @@ function applyModifications(mods: jsonpatch.Operation[], values: string) {
4240 return values ;
4341}
4442
45- function UpgradeForm ( props : IUpgradeFormProps ) {
43+ function UpgradeForm ( _ : IUpgradeFormProps ) {
4644 const dispatch : ThunkDispatch < IStoreState , null , Action > = useDispatch ( ) ;
4745
4846 const {
@@ -67,40 +65,39 @@ function UpgradeForm(props: IUpgradeFormProps) {
6765 const [ valuesModified , setValuesModified ] = useState ( false ) ;
6866 const formRef = useRef < HTMLFormElement > ( null ) ;
6967
68+ /* Load the list of versions once */
7069 useEffect ( ( ) => {
71- // This block just will be run once, given that populating
72- // the list of versions does not depend on anything else
7370 if ( selectedPackage . versions . length === 0 ) {
7471 dispatch (
7572 actions . availablepackages . fetchAvailablePackageVersions (
7673 installedAppInstalledPackageDetail ?. availablePackageRef ,
7774 ) ,
7875 ) ;
79- if ( installedAppAvailablePackageDetail ) {
80- // Additionally, mark the current installed package version as the selected,
81- // next time, the selection will be handled by selectVersion()
82- dispatch (
83- actions . availablepackages . receiveSelectedAvailablePackageDetail (
84- installedAppAvailablePackageDetail ,
85- ) ,
86- ) ;
87- }
88- // If a version has been manually selected (eg. in the URL), fetch it explicitly
89- if ( props . version ) {
90- dispatch (
91- actions . availablepackages . fetchAndSelectAvailablePackageDetail (
92- installedAppInstalledPackageDetail ?. availablePackageRef ,
93- props . version ,
94- ) ,
95- ) ;
96- }
9776 }
9877 } , [
9978 dispatch ,
10079 installedAppInstalledPackageDetail ?. availablePackageRef ,
10180 selectedPackage . versions . length ,
102- installedAppAvailablePackageDetail ,
103- props . version ,
81+ ] ) ;
82+
83+ /* After versions are loaded, always select the latest (assumes list is already sorted DESC). */
84+ useEffect ( ( ) => {
85+ if (
86+ versions . length > 0 &&
87+ availablePackageDetail ?. version ?. pkgVersion !== versions [ 0 ] . pkgVersion
88+ ) {
89+ dispatch (
90+ actions . availablepackages . fetchAndSelectAvailablePackageDetail (
91+ installedAppInstalledPackageDetail ?. availablePackageRef ,
92+ versions [ 0 ] . pkgVersion ,
93+ ) ,
94+ ) ;
95+ }
96+ } , [
97+ dispatch ,
98+ versions ,
99+ availablePackageDetail ?. version ?. pkgVersion ,
100+ installedAppInstalledPackageDetail ?. availablePackageRef ,
104101 ] ) ;
105102
106103 useEffect ( ( ) => {
@@ -156,15 +153,6 @@ function UpgradeForm(props: IUpgradeFormProps) {
156153 setAppValues ( value ) ;
157154 } ;
158155
159- const selectVersion = ( e : React . ChangeEvent < HTMLSelectElement > ) => {
160- dispatch (
161- actions . availablepackages . fetchAndSelectAvailablePackageDetail (
162- installedAppInstalledPackageDetail ?. availablePackageRef ,
163- e . currentTarget . value ,
164- ) ,
165- ) ;
166- } ;
167-
168156 const push = usePush ( ) ;
169157
170158 const handleDeploy = async ( e : React . FormEvent < HTMLFormElement > ) => {
@@ -212,7 +200,7 @@ function UpgradeForm(props: IUpgradeFormProps) {
212200 releaseName = { installedAppInstalledPackageDetail ?. installedPackageRef ?. identifier }
213201 availablePackageDetail = { availablePackageDetail }
214202 versions = { versions }
215- onSelect = { selectVersion }
203+ onSelect = { ( ) => undefined }
216204 currentVersion = { installedAppAvailablePackageDetail ?. version ?. pkgVersion }
217205 selectedVersion = { pkgVersion }
218206 hideVersionsSelector = { true }
@@ -233,22 +221,6 @@ function UpgradeForm(props: IUpgradeFormProps) {
233221 </ Column >
234222 < Column span = { 9 } >
235223 < form onSubmit = { handleDeploy } ref = { formRef } >
236- < CdsFormGroup
237- className = "deployment-form"
238- layout = "vertical"
239- controlWidth = "shrink"
240- >
241- < PackageVersionSelector
242- versions = { versions }
243- selectedVersion = { pkgVersion }
244- onSelect = { selectVersion }
245- currentVersion = {
246- installedAppInstalledPackageDetail ?. currentVersion ?. pkgVersion
247- }
248- label = { "Package Version" }
249- message = { "Select the version this package will be upgraded to." }
250- />
251- </ CdsFormGroup >
252224 < DeploymentFormBody
253225 deploymentEvent = "upgrade"
254226 packageId = {
0 commit comments