diff --git a/src/const.tsx b/src/const.tsx index 9a7f2b7e..9259a903 100644 --- a/src/const.tsx +++ b/src/const.tsx @@ -15,6 +15,8 @@ export enum ResourceType { export enum PublishType { BUILD_DEPLOY = 'builddeploy', DEPLOY = 'deploy', + RESTART = 'restart', + ROLLBACK = 'rollback', } export enum MemberType { diff --git a/src/pages/instances/Pods/components/ButtonBar.tsx b/src/pages/instances/Pods/components/ButtonBar.tsx index 2779a006..3e57c56c 100644 --- a/src/pages/instances/Pods/components/ButtonBar.tsx +++ b/src/pages/instances/Pods/components/ButtonBar.tsx @@ -2,14 +2,16 @@ import { DownOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { Button, Dropdown, Menu, Modal, Tooltip, } from 'antd'; -import { history, useIntl, useModel } from 'umi'; +import { + history, useIntl, useModel, useRequest, +} from 'umi'; import { stringify } from 'query-string'; import { useState } from 'react'; import { RebuilddeployModal } from '@/components/rollout'; import RBAC from '@/rbac'; import { isRestrictedStatus } from '@/components/State'; import { ClusterStatus, PublishType } from '@/const'; -import { deleteCluster, freeCluster, restart } from '@/services/clusters/clusters'; +import { createPipelineRun, deleteCluster, freeCluster } from '@/services/clusters/clusters'; import { DangerText, WarningText } from '@/components/Widget'; interface ButtonBarProps { @@ -26,6 +28,13 @@ function ButtonBar(props: ButtonBarProps) { const { successAlert } = useModel('alert'); const [enableRebuilddeployModal, setEnableRebuilddeployModal] = useState(false); + const { run: runRestart } = useRequest(() => createPipelineRun(id!, { action: 'restart' }), { + onSuccess: (pr: PIPELINES.Pipeline) => { + history.push(`/instances${fullPath}/-/pipelines/${pr.id}`); + }, + manual: true, + }); + const onClickOperation = ({ key }: { key: string }) => { switch (key) { case 'builddeploy': @@ -43,9 +52,7 @@ function ButtonBar(props: ButtonBarProps) { Modal.confirm({ title: intl.formatMessage({ id: 'pages.message.cluster.restart.confirm' }), onOk() { - restart(id).then(() => { - successAlert(intl.formatMessage({ id: 'pages.message.cluster.restart.success' })); - }); + runRestart(); }, }); break; diff --git a/src/pages/instances/Pods/components/ButtonBarV2.tsx b/src/pages/instances/Pods/components/ButtonBarV2.tsx index 4ff46796..501aa5aa 100644 --- a/src/pages/instances/Pods/components/ButtonBarV2.tsx +++ b/src/pages/instances/Pods/components/ButtonBarV2.tsx @@ -2,14 +2,16 @@ import { DownOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { Button, Dropdown, Menu, Modal, Tooltip, } from 'antd'; -import { history, useIntl, useModel } from 'umi'; +import { + history, useIntl, useModel, useRequest, +} from 'umi'; import { stringify } from 'query-string'; import { useState } from 'react'; import { RebuilddeployModal } from '@/components/rollout'; import RBAC from '@/rbac'; import { isRestrictedStatus } from '@/components/State'; import { ClusterStatus, PublishType } from '@/const'; -import { deleteCluster, freeCluster, restart } from '@/services/clusters/clusters'; +import { createPipelineRun, deleteCluster, freeCluster } from '@/services/clusters/clusters'; import { CatalogType } from '@/services/core'; import { DangerText, WarningText } from '@/components/Widget'; @@ -30,6 +32,13 @@ function ButtonBarV2(props: ButtonBarProps) { const { successAlert } = useModel('alert'); const [enableRebuilddeployModal, setEnableRebuilddeployModal] = useState(false); + const { run: runRestart } = useRequest(() => createPipelineRun(id!, { action: 'restart' }), { + onSuccess: (pr: PIPELINES.Pipeline) => { + history.push(`/instances${fullPath}/-/pipelines/${pr.id}`); + }, + manual: true, + }); + const onClickOperation = ({ key }: { key: string }) => { switch (key) { case 'builddeploy': @@ -47,9 +56,7 @@ function ButtonBarV2(props: ButtonBarProps) { Modal.confirm({ title: intl.formatMessage({ id: 'pages.message.cluster.restart.confirm' }), onOk() { - restart(id).then(() => { - successAlert(intl.formatMessage({ id: 'pages.message.cluster.restart.success' })); - }); + runRestart(); }, }); break; diff --git a/src/pages/instances/pipelines/Detail/MergeBox.tsx b/src/pages/instances/pipelines/Detail/MergeBox.tsx index 999667af..74fc3543 100644 --- a/src/pages/instances/pipelines/Detail/MergeBox.tsx +++ b/src/pages/instances/pipelines/Detail/MergeBox.tsx @@ -86,13 +86,17 @@ const Status = (props: StatusProps) => { interface ConfirmButtonProps extends Omit { pipelinerunID: number; + pipelinerunAction: string; forceRun: boolean; } const ConfirmButton = (props: ConfirmButtonProps) => { - const { pipelinerunID, forceRun: forceRunFlag, disabled } = props; + const { + pipelinerunID, pipelinerunAction, forceRun: forceRunFlag, disabled, + } = props; const intl = useIntl(); const history = useHistory(); + const { successAlert } = useModel('alert'); const { initialState } = useModel('@@initialState'); const { fullPath } = initialState?.resource || {}; @@ -109,32 +113,35 @@ const ConfirmButton = (props: ConfirmButtonProps) => { }; }, [forceRunFlag, intl, disabled]); - const { run } = useRequest(() => runPipelineRun(pipelinerunID), { - onSuccess: () => { - history.push(`${fullPath}`); - }, - manual: true, - }); + const doRun = useCallback(() => { + if (forceRunFlag) { + return forceRunPipelineRun(pipelinerunID); + } + return runPipelineRun(pipelinerunID); + }, [forceRunFlag, pipelinerunID]); - const { run: forceRun } = useRequest(() => forceRunPipelineRun(pipelinerunID), { + const { run, loading } = useRequest(() => doRun(), { onSuccess: () => { + switch (pipelinerunAction) { + case 'restart': + successAlert(intl.formatMessage({ id: 'pages.message.cluster.restart.success' })); + break; + case 'rollback': + successAlert(intl.formatMessage({ id: 'pages.message.cluster.rollback.submitted' })); + break; + default: + break; + } history.push(`${fullPath}`); }, manual: true, }); - const onClick = useCallback(() => { - if (forceRunFlag) { - forceRun(); - } else { - run(); - } - }, [forceRunFlag, forceRun, run]); - return (