From d02382d83c06bd7e91ade00d7e7064cd887ef699 Mon Sep 17 00:00:00 2001 From: Mia Wong Date: Thu, 22 Aug 2024 20:10:58 +0000 Subject: [PATCH] refactor to reuse available updates component --- .../apps/AvailableUpdatesComponent.tsx | 171 ++++++++++-------- .../components/AvailableUpdateCard.tsx | 100 ++-------- .../components/DashboardVersionCard.tsx | 7 - 3 files changed, 120 insertions(+), 158 deletions(-) diff --git a/web/src/components/apps/AvailableUpdatesComponent.tsx b/web/src/components/apps/AvailableUpdatesComponent.tsx index c817d1c57c..cc47821f65 100644 --- a/web/src/components/apps/AvailableUpdatesComponent.tsx +++ b/web/src/components/apps/AvailableUpdatesComponent.tsx @@ -5,6 +5,80 @@ import { Utilities } from "@src/utilities/utilities"; import { AvailableUpdate } from "@types"; import ReactTooltip from "react-tooltip"; +export const AvailableUpdateRow = ({ + update, + index, + showReleaseNotes, + children, + upgradeService, +}: { + update: AvailableUpdate; + index: number; + showReleaseNotes: (releaseNotes: string) => void; + children: React.ReactNode; + upgradeService?: { + versionLabel?: string; + isLoading?: boolean; + error?: string; + } | null; +}) => { + return ( +
+
+
+
+

+ {update.versionLabel} +

+ {update.isRequired && ( + + {" "} + Required{" "} + + )} +
+ {update.upstreamReleasedAt && ( +

+ {" "} + Released{" "} + + {Utilities.dateFormat( + update.upstreamReleasedAt, + "MM/DD/YY @ hh:mm a z" + )} + +

+ )} +
+
+ {update?.releaseNotes && ( + <> + showReleaseNotes(update?.releaseNotes)} + data-tip="View release notes" + className="u-marginRight--5 clickable" + /> + + + )} + {children} +
+
+ {upgradeService?.error && + upgradeService?.versionLabel === update.versionLabel && ( +
+ + {upgradeService.error} + error + +
+ )} +
+ ); +}; + const AvailableUpdatesComponent = ({ updates, showReleaseNotes, @@ -71,78 +145,33 @@ const AvailableUpdatesComponent = ({ upgradeService?.versionLabel === update.versionLabel && upgradeService.isLoading; return ( -
-
-
-
-

- {update.versionLabel} -

- {update.isRequired && ( - - {" "} - Required{" "} - - )} -
- {update.upstreamReleasedAt && ( -

- {" "} - Released{" "} - - {Utilities.dateFormat( - update.upstreamReleasedAt, - "MM/DD/YY @ hh:mm a z" - )} - -

- )} -
-
- {update?.releaseNotes && ( - <> - showReleaseNotes(update?.releaseNotes)} - data-tip="View release notes" - className="u-marginRight--5 clickable" - /> - - - )} - - -
-
- {upgradeService?.error && - upgradeService?.versionLabel === update.versionLabel && ( -
- - {upgradeService.error} - -
- )} -
+ {isCurrentVersionLoading ? "Preparing..." : "Deploy"} + + + + + ); })} diff --git a/web/src/features/Dashboard/components/AvailableUpdateCard.tsx b/web/src/features/Dashboard/components/AvailableUpdateCard.tsx index a25042d39e..be93b6dce8 100644 --- a/web/src/features/Dashboard/components/AvailableUpdateCard.tsx +++ b/web/src/features/Dashboard/components/AvailableUpdateCard.tsx @@ -1,30 +1,19 @@ import { useNavigate } from "react-router-dom"; -import ReactTooltip from "react-tooltip"; -import Icon from "@components/Icon"; -import { Utilities } from "@src/utilities/utilities"; import { AvailableUpdate } from "@types"; +import { AvailableUpdateRow } from "@components/apps/AvailableUpdatesComponent"; const AvailableUpdateCard = ({ updates, showReleaseNotes, - upgradeService, appSlug, }: { updates: AvailableUpdate[]; showReleaseNotes: (releaseNotes: string) => void; - upgradeService: { - versionLabel?: string; - isLoading?: boolean; - error?: string; - } | null; appSlug: string; }) => { const navigate = useNavigate(); const update = updates[0]; - const isCurrentVersionLoading = - upgradeService?.versionLabel === update.versionLabel && - upgradeService.isLoading; return (
@@ -38,74 +27,25 @@ const AvailableUpdateCard = ({

-
-
-
-
-

- {update.versionLabel} -

- {update.isRequired && ( - - {" "} - Required{" "} - - )} -
- {update.upstreamReleasedAt && ( -

- {" "} - Released{" "} - - {Utilities.dateFormat( - update.upstreamReleasedAt, - "MM/DD/YY @ hh:mm a z" - )} - -

- )} -
-
- {update?.releaseNotes && ( - <> - showReleaseNotes(update?.releaseNotes)} - data-tip="View release notes" - className="u-marginRight--5 clickable" - /> - - - )} - - - - -
-
- {upgradeService?.error && - upgradeService?.versionLabel === update.versionLabel && ( -
- - {upgradeService.error} - -
- )} -
+ + +
); diff --git a/web/src/features/Dashboard/components/DashboardVersionCard.tsx b/web/src/features/Dashboard/components/DashboardVersionCard.tsx index 822a4bcfcf..7f8bc99dad 100644 --- a/web/src/features/Dashboard/components/DashboardVersionCard.tsx +++ b/web/src/features/Dashboard/components/DashboardVersionCard.tsx @@ -114,11 +114,6 @@ type State = { versionToDeploy: Version | null; viewLogsErrMsg: string; yamlErrorDetails: string[]; - upgradeService: { - versionLabel?: string; - isLoading?: boolean; - error?: string; - } | null; }; const DashboardVersionCard = (props: Props) => { @@ -167,7 +162,6 @@ const DashboardVersionCard = (props: Props) => { versionToDeploy: null, viewLogsErrMsg: "", yamlErrorDetails: [], - upgradeService: {}, } ); const navigate = useNavigate(); @@ -1595,7 +1589,6 @@ const DashboardVersionCard = (props: Props) => { )}