From bf1657c03fa4212de958a44a506ec8e642d4c175 Mon Sep 17 00:00:00 2001 From: Mia Wong Date: Wed, 12 Jun 2024 19:59:34 +0000 Subject: [PATCH] display available updates for embedded cluster start upgrade service when click on deploy --- web/src/components/apps/AppVersionHistory.tsx | 276 ++++++++++-------- 1 file changed, 160 insertions(+), 116 deletions(-) diff --git a/web/src/components/apps/AppVersionHistory.tsx b/web/src/components/apps/AppVersionHistory.tsx index 2a997faa68..629693d2d5 100644 --- a/web/src/components/apps/AppVersionHistory.tsx +++ b/web/src/components/apps/AppVersionHistory.tsx @@ -62,6 +62,7 @@ type Props = { app: App; displayErrorModal: boolean; isBundleUploading: boolean; + isEmbeddedCluster: boolean; makeCurrentVersion: ( slug: string, version: Version | null, @@ -84,6 +85,7 @@ type Props = { type State = { airgapUploader: AirgapUploader | null; airgapUploadError: string; + availableUpdates: Version[] | null; appUpdateChecker: Repeater; checkedReleasesToDiff: Version[]; checkingForUpdateError: boolean; @@ -155,6 +157,7 @@ class AppVersionHistory extends Component { this.state = { airgapUploader: null, airgapUploadError: "", + availableUpdates: null, appUpdateChecker: new Repeater(), checkedReleasesToDiff: [], checkingForUpdateError: false, @@ -223,6 +226,7 @@ class AppVersionHistory extends Component { _mounted: boolean | undefined; componentDidMount() { + console.log(this.props.outletContext, "outlet cnotext"); this.getPreflightState( this.props.outletContext.app.downstream.currentVersion ); @@ -254,41 +258,7 @@ class AppVersionHistory extends Component { } } - // fetch for available updates this.fetchAvailableUpdates(); - // TODO NOW: remove this - // const appSlug = this.props.params.slug; - // fetch(`${process.env.API_ENDPOINT}/app/${appSlug}/start-upgrade-service`, { - // headers: { - // "Content-Type": "application/json", - // Accept: "application/json", - // }, - // body: JSON.stringify({ - // // not used// doesn't matter right now - // kotsVersion: "v1.109.3", - - // versionLabel: "0.1.24", - // // channel sequence - // updateCursor: "25", - // }), - // credentials: "include", - // method: "POST", - // }) - // .then(async (res) => { - // if (res.ok) { - // this.setState({ - // shouldShowUpgradeServiceModal: true, - // }); - // return; - // } - // const text = await res.text(); - // console.log("failed to init upgrade service", text); - // }) - // .catch((err) => { - // console.log(err); - // }); - - // this._mounted = true; } componentDidUpdate = async (lastProps: Props) => { @@ -337,7 +307,8 @@ class AppVersionHistory extends Component { return; } const response = await res.json(); - console.log(response, " resposne"); + + this.setState({ availableUpdates: response.updates }); return response; }; @@ -1424,6 +1395,69 @@ class AppVersionHistory extends Component { } }; + startUpgraderService = (version: Version) => { + const appSlug = this.props.params.slug; + fetch(`${process.env.API_ENDPOINT}/app/${appSlug}/start-upgrade-service`, { + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ + // not used// doesn't matter right now + kotsVersion: "v1.109.3", + versionLabel: version.versionLabel, + // channel sequence + updateCursor: version.updateCursor, + }), + credentials: "include", + method: "POST", + }) + .then(async (res) => { + if (res.ok) { + this.setState({ + shouldShowUpgradeServiceModal: true, + }); + return; + } + const text = await res.text(); + console.log("failed to init upgrade service", text); + }) + .catch((err) => { + console.log(err); + }); + + this._mounted = true; + }; + + renderAvailableECUpdatesRow = (versions: Version[]) => { + console.log(versions, "versions"); + return ( +
+

+ Available Updates +

+
+ {versions.map((version, index) => ( +
+

+ {version.versionLabel} +

+ +
+ ))} +
+
+ ); + }; + renderAppVersionHistoryRow = (version: Version, index?: number) => { if ( !version || @@ -1834,94 +1868,104 @@ class AppVersionHistory extends Component { ) : (
-
-

- {this.state.updatesAvailable - ? "New version available" - : ""} -

-
+ {!this.props.outletContext.isEmbeddedCluster && ( +
+

+ {this.state.updatesAvailable + ? "New version available" + : ""} +

- {app?.isAirgap && airgapUploader ? ( - - airgapUploader?.assignElement(el) - } - > -
- - - Upload new version - -
-
- ) : ( -
- {checkingForUpdates && - !this.props.outletContext - .isBundleUploading ? ( -
- - - {checkingUpdateMessage === "" - ? "Checking for updates" - : checkingUpdateTextShort} +
+ {app?.isAirgap && airgapUploader ? ( + + airgapUploader?.assignElement(el) + } + > +
+ + + Upload new version
- ) : ( -
- - + ) : ( +
+ {checkingForUpdates && + !this.props.outletContext + .isBundleUploading ? ( +
+ - Check for update - -
- )} - - - Configure automatic updates - -
- )} + + {checkingUpdateMessage === "" + ? "Checking for updates" + : checkingUpdateTextShort} + +
+ ) : ( +
+ + + Check for update + +
+ )} + + + Configure automatic updates + +
+ )} +
+ {versionHistory.length > 1 && !gitopsIsConnected + ? this.renderDiffBtn() + : null}
- {versionHistory.length > 1 && !gitopsIsConnected - ? this.renderDiffBtn() - : null} -
-
- {pendingVersion ? ( - this.renderAppVersionHistoryRow(pendingVersion) - ) : ( -
-

- Application up to date. -

)} + {this.state.availableUpdates && + this.props.outletContext.isEmbeddedCluster && + this.renderAvailableECUpdatesRow( + this.state.availableUpdates + )} + {!this.props.outletContext.isEmbeddedCluster && + (pendingVersion ? ( + this.renderAppVersionHistoryRow(pendingVersion) + ) : ( +
+

+ Application up to date. +

+
+ ))} {(this.state.numOfSkippedVersions > 0 || this.state.numOfRemainingVersions > 0) && (