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

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


The following commit(s) were added to refs/heads/main by this push:
     new 511b08fe4 fix(config-ui): webhook url shows incorrectly (#5642)
511b08fe4 is described below

commit 511b08fe453b04ebfca4db043e04c8b855905114
Author: 青湛 <[email protected]>
AuthorDate: Mon Jul 10 17:25:56 2023 +1200

    fix(config-ui): webhook url shows incorrectly (#5642)
---
 .../plugins/register/webook/connection/index.tsx   | 14 ++++----
 .../register/webook/delete-dialog/use-delete.ts    | 12 +++----
 .../webook/view-or-edit-dialog/use-view-or-edit.ts | 37 +++++++++++-----------
 3 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/config-ui/src/plugins/register/webook/connection/index.tsx 
b/config-ui/src/plugins/register/webook/connection/index.tsx
index 211c548a5..6ec521c8a 100644
--- a/config-ui/src/plugins/register/webook/connection/index.tsx
+++ b/config-ui/src/plugins/register/webook/connection/index.tsx
@@ -39,18 +39,18 @@ interface Props {
 
 export const WebHookConnection = ({ filterIds, onCreateAfter, onDeleteAfter }: 
Props) => {
   const [type, setType] = useState<Type>();
-  const [record, setRecord] = useState<WebhookItemType>();
+  const [currentID, setCurrentID] = useState<ID>();
 
   const { connections, onRefresh } = useConnections({ plugin: 'webhook' });
 
   const handleHideDialog = () => {
     setType(undefined);
-    setRecord(undefined);
+    setCurrentID(undefined);
   };
 
   const handleShowDialog = (t: Type, r?: WebhookItemType) => {
     setType(t);
-    setRecord(r);
+    setCurrentID(r?.id);
   };
 
   const columns: ColumnType<WebhookItemType> = [
@@ -108,10 +108,10 @@ export const WebHookConnection = ({ filterIds, 
onCreateAfter, onDeleteAfter }: P
           }}
         />
       )}
-      {type === 'delete' && (
+      {type === 'delete' && currentID && (
         <WebhookDeleteDialog
           isOpen
-          initialValues={record}
+          initialID={currentID}
           onCancel={handleHideDialog}
           onSubmitAfter={(id) => {
             onRefresh();
@@ -119,11 +119,11 @@ export const WebHookConnection = ({ filterIds, 
onCreateAfter, onDeleteAfter }: P
           }}
         />
       )}
-      {(type === 'edit' || type === 'show') && (
+      {(type === 'edit' || type === 'show') && currentID && (
         <WebhookViewOrEditDialog
           type={type}
           isOpen
-          initialValues={record}
+          initialID={currentID}
           onCancel={handleHideDialog}
           onSubmitAfter={() => onRefresh()}
         />
diff --git a/config-ui/src/plugins/register/webook/delete-dialog/use-delete.ts 
b/config-ui/src/plugins/register/webook/delete-dialog/use-delete.ts
index e8516d3e7..71d959f06 100644
--- a/config-ui/src/plugins/register/webook/delete-dialog/use-delete.ts
+++ b/config-ui/src/plugins/register/webook/delete-dialog/use-delete.ts
@@ -23,24 +23,20 @@ import { operator } from '@/utils';
 import * as API from '../api';
 
 export interface UseDeleteProps {
-  initialValues?: {
-    id: ID;
-  };
+  initialID: ID;
   onSubmitAfter?: (id: ID) => void;
 }
 
-export const useDelete = ({ initialValues, onSubmitAfter }: UseDeleteProps) => 
{
+export const useDelete = ({ initialID, onSubmitAfter }: UseDeleteProps) => {
   const [saving, setSaving] = useState(false);
 
   const handleDelete = async () => {
-    if (!initialValues) return;
-
-    const [success] = await operator(() => 
API.deleteConnection(initialValues.id), {
+    const [success] = await operator(() => API.deleteConnection(initialID), {
       setOperating: setSaving,
     });
 
     if (success) {
-      onSubmitAfter?.(initialValues.id);
+      onSubmitAfter?.(initialID);
     }
   };
 
diff --git 
a/config-ui/src/plugins/register/webook/view-or-edit-dialog/use-view-or-edit.ts 
b/config-ui/src/plugins/register/webook/view-or-edit-dialog/use-view-or-edit.ts
index c3d2c851a..e7d14b18c 100644
--- 
a/config-ui/src/plugins/register/webook/view-or-edit-dialog/use-view-or-edit.ts
+++ 
b/config-ui/src/plugins/register/webook/view-or-edit-dialog/use-view-or-edit.ts
@@ -23,13 +23,11 @@ import { operator } from '@/utils';
 import * as API from '../api';
 
 export interface UseViewOrEditProps {
-  initialValues?: {
-    id: ID;
-  } & any;
+  initialID: ID;
   onSubmitAfter?: (id: ID) => void;
 }
 
-export const useViewOrEdit = ({ initialValues, onSubmitAfter }: 
UseViewOrEditProps) => {
+export const useViewOrEdit = ({ initialID, onSubmitAfter }: 
UseViewOrEditProps) => {
   const [saving, setSaving] = useState(false);
   const [name, setName] = useState('');
   const [record, setRecord] = useState({
@@ -41,27 +39,28 @@ export const useViewOrEdit = ({ initialValues, 
onSubmitAfter }: UseViewOrEditPro
   const prefix = useMemo(() => `${window.location.origin}/api`, []);
 
   useEffect(() => {
-    setName(initialValues.name);
-    setRecord({
-      postIssuesEndpoint: `${prefix}${initialValues.postIssuesEndpoint}`,
-      closeIssuesEndpoint: `${prefix}${initialValues.closeIssuesEndpoint}`,
-      postDeploymentsCurl: `curl 
${prefix}${initialValues.postPipelineDeployTaskEndpoint} -X 'POST' -d "{
-\\"commit_sha\\":\\"the sha of deployment commit\\",
-\\"repo_url\\":\\"the repo URL of the deployment commit\\",
-\\"start_time\\":\\"Optional, eg. 2020-01-01T12:00:00+00:00\\"
-}"`,
-    });
-  }, [initialValues]);
+    (async () => {
+      const res = await API.getConnection(initialID);
+      setName(res.name);
+      setRecord({
+        postIssuesEndpoint: `${prefix}${res.postIssuesEndpoint}`,
+        closeIssuesEndpoint: `${prefix}${res.closeIssuesEndpoint}`,
+        postDeploymentsCurl: `curl 
${prefix}${res.postPipelineDeployTaskEndpoint} -X 'POST' -d "{
+      \\"commit_sha\\":\\"the sha of deployment commit\\",
+      \\"repo_url\\":\\"the repo URL of the deployment commit\\",
+      \\"start_time\\":\\"Optional, eg. 2020-01-01T12:00:00+00:00\\"
+      }"`,
+      });
+    })();
+  }, [initialID]);
 
   const handleUpdate = async () => {
-    if (!initialValues) return;
-
-    const [success] = await operator(() => 
API.updateConnection(initialValues.id, { name }), {
+    const [success] = await operator(() => API.updateConnection(initialID, { 
name }), {
       setOperating: setSaving,
     });
 
     if (success) {
-      onSubmitAfter?.(initialValues.id);
+      onSubmitAfter?.(initialID);
     }
   };
 

Reply via email to