You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by mi...@apache.org on 2024/09/06 06:57:56 UTC

(incubator-devlake) branch fix-8001 created (now 812997031)

This is an automated email from the ASF dual-hosted git repository.

mintsweet pushed a change to branch fix-8001
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


      at 812997031 fix: webhook will be deleted when disconnect with project

This branch includes the following new commits:

     new 812997031 fix: webhook will be deleted when disconnect with project

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-devlake) 01/01: fix: webhook will be deleted when disconnect with project

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mintsweet pushed a commit to branch fix-8001
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 812997031f9ca29b6d10c000be2ba7d49331108a
Author: mintsweet <0x...@gmail.com>
AuthorDate: Fri Sep 6 18:57:41 2024 +1200

    fix: webhook will be deleted when disconnect with project
---
 .../register/webhook/components/delete-dialog.tsx  |  4 +-
 .../src/plugins/register/webhook/connection.tsx    | 45 +++++++++++++++++-----
 config-ui/src/routes/project/webhook/index.tsx     |  5 ++-
 3 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/config-ui/src/plugins/register/webhook/components/delete-dialog.tsx b/config-ui/src/plugins/register/webhook/components/delete-dialog.tsx
index 846d51eca..8b05c3cd4 100644
--- a/config-ui/src/plugins/register/webhook/components/delete-dialog.tsx
+++ b/config-ui/src/plugins/register/webhook/components/delete-dialog.tsx
@@ -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();
@@ -41,7 +40,6 @@ export const DeleteDialog = ({ initialId, onCancel, onSubmitAfter }: Props) => {
     });
 
     if (success) {
-      onSubmitAfter?.(initialId);
       onCancel();
     }
   };
diff --git a/config-ui/src/plugins/register/webhook/connection.tsx b/config-ui/src/plugins/register/webhook/connection.tsx
index 4ad661db3..32bfd6f5e 100644
--- a/config-ui/src/plugins/register/webhook/connection.tsx
+++ b/config-ui/src/plugins/register/webhook/connection.tsx
@@ -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>();
 
@@ -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>
             ),
           },
@@ -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>
   );
diff --git a/config-ui/src/routes/project/webhook/index.tsx b/config-ui/src/routes/project/webhook/index.tsx
index fafd41d05..9d267b243 100644
--- a/config-ui/src/routes/project/webhook/index.tsx
+++ b/config-ui/src/routes/project/webhook/index.tsx
@@ -71,6 +71,7 @@ export const ProjectWebhook = () => {
 
     if (success) {
       setVersion(version + 1);
+      handleCancel();
     }
   };
 
@@ -96,6 +97,7 @@ export const ProjectWebhook = () => {
 
     if (success) {
       setVersion(version + 1);
+      handleCancel();
     }
   };
 
@@ -115,6 +117,7 @@ export const ProjectWebhook = () => {
 
     if (success) {
       setVersion(version + 1);
+      handleCancel();
     }
   };
 
@@ -161,7 +164,7 @@ export const ProjectWebhook = () => {
           )}
         </>
       ) : (
-        <WebHookConnection filterIds={webhookIds} onCreateAfter={handleCreate} onDeleteAfter={handleDelete} />
+        <WebHookConnection fromProject filterIds={webhookIds} onAssociate={handleCreate} onRemove={handleDelete} />
       )}
     </>
   );