Skip to content

Commit

Permalink
[Backport release-1.7] Feat: support for deleting the workflow (#682)
Browse files Browse the repository at this point in the history
* 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
github-actions[bot] and barnettZQG authored Jan 31, 2023
1 parent df90003 commit c894356
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/NumItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React from 'react';
import { Link } from 'react-router-dom';
import './index.less';

export type Props = {
title: string | React.ReactNode;
number?: number;
to?: string;
};

const NumItem: React.FC<Props> = (props) => {
return (
<div className="num-item">
<div className="number">{props.number || 0}</div>
<div className="number">
{props.to ? (
<Link to={props.to}>{props.number || 0}</Link>
) : (
<span>{props.number || 0}</span>
)}
</div>
<div className="title">{props.title}</div>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/layout/Application/components/Menus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Menu extends Component<Props, any> {
label: <Translation>Revisions</Translation>,
to: `/applications/${appName}/revisions`,
},
{
key: 'workflows',
label: <Translation>Workflows</Translation>,
to: `/applications/${appName}/workflows`,
},
],
envPage: [
{
Expand Down
12 changes: 12 additions & 0 deletions src/layout/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import ApplicationWorkflowStudio from '../../pages/ApplicationWorkflowStudio';
import PipelineStudio from '../../pages/PipelineStudio';
import ProjectPipelines from '../../pages/ProjectPipelines';
import ApplicationEnvRoute from '../../pages/ApplicationEnvRoute';
import ApplicationWorkflowList from '../../pages/ApplicationWorkflowList';

export default function Content() {
return (
Expand Down Expand Up @@ -85,6 +86,17 @@ export default function Content() {
);
}}
/>
<Route
exact
path="/applications/:appName/workflows"
render={(props: any) => {
return (
<ApplicationLayout {...props}>
<ApplicationWorkflowList {...props} />
</ApplicationLayout>
);
}}
/>
<Route
exact
path="/applications/:appName/envbinding/:envName"
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ApplicationConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,14 @@ class ApplicationConfig extends Component<Props, State> {
<Col span={6} style={{ padding: '22px 0' }}>
<NumItem
number={statistics?.revisionCount}
to={`/applications/${applicationDetail.name}/revisions`}
title={i18n.t('Revision Count').toString()}
/>
</Col>
<Col span={6} style={{ padding: '22px 0' }}>
<NumItem
number={statistics?.workflowCount}
to={`/applications/${applicationDetail.name}/workflows`}
title={i18n.t('Workflow Count').toString()}
/>
</Col>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ApplicationRevisionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class ApplicationRevisionList extends React.Component<Props, State> {
listRevisions(params).then((res) => {
if (res) {
this.setState({
revisionsList: res && res.revisions,
revisionsListTotal: res && res.total,
revisionsList: res.revisions || [],
revisionsListTotal: res.total || 0,
});
}
});
Expand Down
173 changes: 173 additions & 0 deletions src/pages/ApplicationWorkflowList/index.tsx
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;

0 comments on commit c894356

Please sign in to comment.