From 2002e2d6c5c6937ea773c707f5e3b6eb499fb6ea Mon Sep 17 00:00:00 2001 From: Tim Soslow Date: Tue, 9 May 2023 21:58:46 -0500 Subject: [PATCH] Restore table action rebuild Signed-off-by: Tim Soslow Signed-off-by: Christopher Diaz --- .../BuildsPage/lib/CITable/CITable.tsx | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx index 6fc5f2d35c..f2d108eaf7 100644 --- a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx +++ b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Link, Table, TableColumn } from '@backstage/core-components'; -import { useRouteRef } from '@backstage/core-plugin-api'; -import { Box, IconButton, Typography } from '@material-ui/core'; +import { Link, Progress, Table, TableColumn } from '@backstage/core-components'; +import { alertApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api'; +import { useEntityPermission } from '@backstage/plugin-catalog-react/alpha'; +import { Box, IconButton, Tooltip, Typography } from '@material-ui/core'; import RetryIcon from '@material-ui/icons/Replay'; import VisibilityIcon from '@material-ui/icons/Visibility'; -import { default as React } from 'react'; +import { default as React, useState } from 'react'; import { Project } from '../../../../api/JenkinsApi'; import JenkinsLogo from '../../../../assets/JenkinsLogo.svg'; import { buildRouteRef } from '../../../../plugin'; import { useBuilds } from '../../../useBuilds'; import { JenkinsRunStatus } from '../Status'; +import { jenkinsExecutePermission } from '@backstage/plugin-jenkins-common'; const FailCount = ({ count }: { count: number }): JSX.Element | null => { if (count !== 0) { @@ -173,16 +175,55 @@ const generatedColumns: TableColumn[] = [ title: 'Actions', sorting: false, render: (row: Partial) => { - return row.lastBuild?.url ? ( -
- - - - - - -
- ) : null; + const ActionWrapper = () => { + const [isLoadingRebuild, setIsLoadingRebuild] = useState(false); + const { allowed, loading } = useEntityPermission( + jenkinsExecutePermission, + ); + + const alertApi = useApi(alertApiRef); + + const onRebuild = async () => { + if (row.onRestartClick) { + setIsLoadingRebuild(true); + try { + await row.onRestartClick(); + alertApi.post({ + message: 'Jenkins re-build has successfully executed', + severity: 'success', + }); + } catch (e) { + alertApi.post({ + message: `Jenkins re-build has failed. Error: ${e.message}`, + severity: 'error', + }); + } finally { + setIsLoadingRebuild(false); + } + } + }; + + return ( +
+ {row.lastBuild?.url && ( + + + + + + )} + {isLoadingRebuild && } + {!isLoadingRebuild && ( + + + + + + )} +
+ ); + }; + return ; }, width: '10%', },