-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport release-1.7] Feat: support for deleting the workflow (#682)
* Feat: support for deleting the workflow Signed-off-by: barnettZQG <[email protected]> (cherry picked from commit 8bce563) * Fix: enhance the code style Signed-off-by: barnettZQG <[email protected]> (cherry picked from commit f252bd6) --------- Co-authored-by: barnettZQG <[email protected]>
- Loading branch information
1 parent
df90003
commit c894356
Showing
6 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import React from 'react'; | ||
import { connect } from 'dva'; | ||
import { Button, Dialog, Message, Table } from '@b-design/ui'; | ||
import type { ApplicationDetail, EnvBinding, Workflow } from '../../interface/application'; | ||
import type { Dispatch } from 'redux'; | ||
import { deleteWorkflow, listWorkflow } from '../../api/workflows'; | ||
import i18n from '../../i18n'; | ||
import { momentDate } from '../../utils/common'; | ||
import Permission from '../../components/Permission'; | ||
import { AiFillDelete } from 'react-icons/ai'; | ||
import Translation from '../../components/Translation'; | ||
import { Link } from 'dva/router'; | ||
import { If } from 'tsx-control-statements/components'; | ||
import locale from '../../utils/locale'; | ||
|
||
type Props = { | ||
revisions: []; | ||
applicationDetail?: ApplicationDetail; | ||
envbinding?: EnvBinding[]; | ||
dispatch: Dispatch<any>; | ||
match: { | ||
params: { | ||
appName: string; | ||
}; | ||
}; | ||
}; | ||
|
||
type State = { | ||
workflowList: Workflow[]; | ||
}; | ||
|
||
@connect((store: any) => { | ||
return { ...store.application }; | ||
}) | ||
class ApplicationWorkflowList extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { | ||
workflowList: [], | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.getWorkflowList(); | ||
} | ||
|
||
getWorkflowList = async () => { | ||
const { applicationDetail } = this.props; | ||
if (applicationDetail) { | ||
const params = { | ||
appName: applicationDetail?.name, | ||
}; | ||
|
||
listWorkflow(params).then((res) => { | ||
if (res) { | ||
this.setState({ | ||
workflowList: res.workflows || [], | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
onDeleteWorkflow = (name: string) => { | ||
const { applicationDetail } = this.props; | ||
if (applicationDetail) { | ||
Dialog.confirm({ | ||
type: 'confirm', | ||
content: ( | ||
<Translation>Unrecoverable after deletion, are you sure to delete it?</Translation> | ||
), | ||
onOk: () => { | ||
deleteWorkflow({ | ||
appName: applicationDetail.name, | ||
name: name, | ||
}).then((res) => { | ||
if (res) { | ||
Message.success(i18n.t('The Workflow removed successfully')); | ||
this.getWorkflowList(); | ||
} | ||
}); | ||
}, | ||
locale: locale().Dialog, | ||
}); | ||
} | ||
}; | ||
|
||
render() { | ||
const { workflowList } = this.state; | ||
const { applicationDetail } = this.props; | ||
const projectName = applicationDetail?.project?.name; | ||
return ( | ||
<div> | ||
<Message type="notice" style={{ marginBottom: '8px' }}> | ||
<Translation>One environment corresponds to one workflow</Translation> | ||
</Message> | ||
<Table dataSource={workflowList}> | ||
<Table.Column dataIndex="name" title={i18n.t('Name')} /> | ||
<Table.Column | ||
dataIndex="envName" | ||
title={i18n.t('Environment')} | ||
cell={(v: string) => { | ||
return ( | ||
<Link | ||
to={`/applications/${applicationDetail?.name}/envbinding/${v}/workflow/studio`} | ||
> | ||
{v} | ||
</Link> | ||
); | ||
}} | ||
/> | ||
<Table.Column dataIndex="mode" title={i18n.t('Mode')} /> | ||
<Table.Column | ||
dataIndex="steps" | ||
title={i18n.t('Step Number')} | ||
cell={(steps: []) => { | ||
return steps ? steps.length : 0; | ||
}} | ||
/> | ||
<Table.Column | ||
dataIndex="createTime" | ||
title={i18n.t('Create Time')} | ||
cell={(v: string) => { | ||
return momentDate(v); | ||
}} | ||
/> | ||
<Table.Column | ||
dataIndex="updateTime" | ||
title={i18n.t('Update Time')} | ||
cell={(v: string) => { | ||
return momentDate(v); | ||
}} | ||
/> | ||
<Table.Column | ||
dataIndex="name" | ||
title={i18n.t('Action')} | ||
cell={(v: string, w: Workflow) => { | ||
return ( | ||
<div> | ||
<If condition={v === w.envName + '-workflow'}> | ||
<Permission | ||
project={projectName} | ||
resource={{ | ||
resource: `project:${projectName}/application:${applicationDetail?.name}/workflow:${v}`, | ||
action: 'delete', | ||
}} | ||
> | ||
<Button | ||
text | ||
size={'medium'} | ||
ghost={true} | ||
className={'danger-btn'} | ||
component={'a'} | ||
onClick={() => { | ||
this.onDeleteWorkflow(v); | ||
}} | ||
> | ||
<AiFillDelete /> | ||
<Translation>Remove</Translation> | ||
</Button> | ||
</Permission> | ||
</If> | ||
</div> | ||
); | ||
}} | ||
/> | ||
</Table> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ApplicationWorkflowList; |