Skip to content

Commit

Permalink
fix: webhook will be deleted when disconnected from project (#8007)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsweet authored Sep 9, 2024
1 parent 55135f9 commit 247b962
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import { operator } from '@/utils';
interface Props {
initialId: ID;
onCancel: () => void;
onSubmitAfter?: (id: ID) => void;
}

export const DeleteDialog = ({ initialId, onCancel, onSubmitAfter }: Props) => {
export const DeleteDialog = ({ initialId, onCancel }: Props) => {
const [operating, setOperating] = useState(false);

const dispatch = useAppDispatch();
Expand All @@ -41,7 +40,6 @@ export const DeleteDialog = ({ initialId, onCancel, onSubmitAfter }: Props) => {
});

if (success) {
onSubmitAfter?.(initialId);
onCancel();
}
};
Expand Down
45 changes: 35 additions & 10 deletions config-ui/src/plugins/register/webhook/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@
*/

import { useState } from 'react';
import { EyeOutlined, FormOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
import { Flex, Table, Space, Button } from 'antd';
import { EyeOutlined, FormOutlined, CloseCircleOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
import { Flex, Table, Space, Button, Modal } from 'antd';

import { Message } from '@/components';
import { useAppSelector } from '@/hooks';
import { selectWebhooks } from '@/features/connections';
import { IWebhook } from '@/types';

import { CreateDialog, ViewDialog, EditDialog, DeleteDialog } from './components';

type Type = 'add' | 'edit' | 'show' | 'delete';
type Type = 'add' | 'edit' | 'show' | 'delete' | 'remove';

interface Props {
fromProject?: boolean;
filterIds?: ID[];
onCreateAfter?: (id: ID) => void;
onDeleteAfter?: (id: ID) => void;
onAssociate?: (id: ID) => void;
onRemove?: (id: ID) => void;
}

export const WebHookConnection = ({ filterIds, onCreateAfter, onDeleteAfter }: Props) => {
export const WebHookConnection = ({ filterIds, fromProject = false, onAssociate, onRemove }: Props) => {
const [type, setType] = useState<Type>();
const [currentID, setCurrentID] = useState<ID>();

Expand Down Expand Up @@ -76,7 +78,21 @@ export const WebHookConnection = ({ filterIds, onCreateAfter, onDeleteAfter }: P
<Space>
<Button type="primary" icon={<EyeOutlined />} onClick={() => handleShowDialog('show', row)} />
<Button type="primary" icon={<FormOutlined />} onClick={() => handleShowDialog('edit', row)} />
<Button type="primary" icon={<DeleteOutlined />} onClick={() => handleShowDialog('delete', row)} />
{fromProject ? (
<Button
type="primary"
danger
icon={<CloseCircleOutlined />}
onClick={() => handleShowDialog('remove', row)}
/>
) : (
<Button
type="primary"
danger
icon={<DeleteOutlined />}
onClick={() => handleShowDialog('delete', row)}
/>
)}
</Space>
),
},
Expand All @@ -89,11 +105,20 @@ export const WebHookConnection = ({ filterIds, onCreateAfter, onDeleteAfter }: P
Add a Webhook
</Button>
</Flex>
{type === 'add' && <CreateDialog open onCancel={handleHideDialog} onSubmitAfter={(id) => onCreateAfter?.(id)} />}
{type === 'add' && <CreateDialog open onCancel={handleHideDialog} onSubmitAfter={(id) => onAssociate?.(id)} />}
{type === 'show' && currentID && <ViewDialog initialId={currentID} onCancel={handleHideDialog} />}
{type === 'edit' && currentID && <EditDialog initialId={currentID} onCancel={handleHideDialog} />}
{type === 'delete' && currentID && (
<DeleteDialog initialId={currentID} onCancel={handleHideDialog} onSubmitAfter={(id) => onDeleteAfter?.(id)} />
{type === 'delete' && currentID && <DeleteDialog initialId={currentID} onCancel={handleHideDialog} />}
{type === 'remove' && currentID && (
<Modal
open
title="Remove this Webhook?"
okText="Confirm"
onCancel={handleHideDialog}
onOk={() => onRemove?.(currentID)}
>
<Message content="This will only remove the webhook from this project. To permanently delete the webhook, please visit the Connections page." />
</Modal>
)}
</Flex>
);
Expand Down
5 changes: 4 additions & 1 deletion config-ui/src/routes/project/webhook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const ProjectWebhook = () => {

if (success) {
setVersion(version + 1);
handleCancel();
}
};

Expand All @@ -96,6 +97,7 @@ export const ProjectWebhook = () => {

if (success) {
setVersion(version + 1);
handleCancel();
}
};

Expand All @@ -115,6 +117,7 @@ export const ProjectWebhook = () => {

if (success) {
setVersion(version + 1);
handleCancel();
}
};

Expand Down Expand Up @@ -161,7 +164,7 @@ export const ProjectWebhook = () => {
)}
</>
) : (
<WebHookConnection filterIds={webhookIds} onCreateAfter={handleCreate} onDeleteAfter={handleDelete} />
<WebHookConnection fromProject filterIds={webhookIds} onAssociate={handleCreate} onRemove={handleDelete} />
)}
</>
);
Expand Down

0 comments on commit 247b962

Please sign in to comment.