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

likyh 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 e68c77dc6 fix(config-ui): something error. (#3965)
e68c77dc6 is described below

commit e68c77dc6a511320f4e72885089dbc86e003b634
Author: 青湛 <[email protected]>
AuthorDate: Mon Dec 19 14:50:10 2022 +0800

    fix(config-ui): something error. (#3965)
    
    * fix(config-ui): the advanced mode in bp cannot be used
    
    * fix(config-ui): the connection store type error
    
    * refactor(config-ui): adjust the style
    
    * fix(config-ui): transformation is lost when scope selected
    
    * fix(config-ui): redirect link error
    
    * refactor(config-ui): improve the put scope fields
---
 config-ui/src/hooks/useConnectionManager.jsx       |  2 +-
 config-ui/src/index.css                            |  4 --
 .../src/pages/blueprint/create/bp-context.tsx      |  4 +-
 .../src/pages/blueprint/create/step-one/index.tsx  | 67 ++++++++++++----------
 config-ui/src/pages/blueprint/create/styled.ts     |  8 +++
 config-ui/src/pages/blueprint/detail/styled.ts     |  2 +-
 .../common/data-scope-list/use-data-scope-list.ts  |  2 +-
 config-ui/src/plugins/common/data-scope/api.ts     |  3 +
 .../plugins/common/data-scope/use-data-scope.ts    | 67 ++++++++++++----------
 .../common/transformation/use-transformation.ts    |  2 +-
 .../github/components/miller-columns/index.tsx     |  7 ++-
 .../miller-columns/use-miller-columns.ts           |  7 ++-
 .../components/repo-selector/use-repo-selector.ts  |  7 ++-
 config-ui/src/plugins/github/types.ts              |  5 ++
 .../gitlab/components/miller-columns/index.tsx     | 11 +++-
 .../miller-columns/use-miller-columns.ts           | 11 +++-
 .../project-selector/use-project-selector.ts       | 11 +++-
 config-ui/src/plugins/gitlab/types.ts              |  9 +++
 .../jenkins/components/miller-columns/index.tsx    |  4 +-
 config-ui/src/plugins/jenkins/types.ts             |  2 +-
 config-ui/src/plugins/jira/types.ts                |  3 +
 .../src/store/connections/use-context-value.ts     |  4 +-
 22 files changed, 163 insertions(+), 79 deletions(-)

diff --git a/config-ui/src/hooks/useConnectionManager.jsx 
b/config-ui/src/hooks/useConnectionManager.jsx
index 805e8bf2b..e6c5de58e 100644
--- a/config-ui/src/hooks/useConnectionManager.jsx
+++ b/config-ui/src/hooks/useConnectionManager.jsx
@@ -580,7 +580,7 @@ function useConnectionManager(
           })
       )
       if (!updateMode) {
-        history.replace(`/integrations/${provider?.id}`)
+        history.replace(`/connections/${provider?.id}`)
         notifyConnectionSaveSuccess()
       } else {
         notifyConnectionSaveSuccess()
diff --git a/config-ui/src/index.css b/config-ui/src/index.css
index aed437a07..fb1a71a35 100644
--- a/config-ui/src/index.css
+++ b/config-ui/src/index.css
@@ -22,7 +22,3 @@
 @import '~@blueprintjs/select/lib/css/blueprint-select.css';
 @import '~@blueprintjs/popover2/lib/css/blueprint-popover2.css';
 @import '~@blueprintjs/datetime/lib/css/blueprint-datetime.css';
-
-.bp4-button + .bp4-button {
-  margin-left: 8px;
-}
diff --git a/config-ui/src/pages/blueprint/create/bp-context.tsx 
b/config-ui/src/pages/blueprint/create/bp-context.tsx
index ba670a508..700c5bc35 100644
--- a/config-ui/src/pages/blueprint/create/bp-context.tsx
+++ b/config-ui/src/pages/blueprint/create/bp-context.tsx
@@ -156,7 +156,9 @@ export const BPContextProvider = ({ from, projectName, 
children }: Props) => {
     }
 
     if (mode === ModeEnum.advanced) {
-      params.plan = validRawPlan(rawPlan) ? JSON.parse(rawPlan) : [[]]
+      params.plan = !validRawPlan(rawPlan)
+        ? JSON.parse(rawPlan)
+        : JSON.stringify([[]], null, '  ')
     }
 
     return params
diff --git a/config-ui/src/pages/blueprint/create/step-one/index.tsx 
b/config-ui/src/pages/blueprint/create/step-one/index.tsx
index 5976e4d5b..cdf077115 100644
--- a/config-ui/src/pages/blueprint/create/step-one/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-one/index.tsx
@@ -16,7 +16,7 @@
  *
  */
 
-import React, { useState } from 'react'
+import React from 'react'
 import {
   InputGroup,
   TextArea,
@@ -38,8 +38,6 @@ import { DEFAULT_CONFIG } from './example'
 import * as S from './styled'
 
 export const StepOne = () => {
-  const [isOpen, setIsOpen] = useState(false)
-
   const { connections, onTest } = useConnection()
 
   const {
@@ -129,35 +127,46 @@ export const StepOne = () => {
               value={rawPlan}
               onChange={(e) => onChangeRawPlan(e.target.value)}
             />
-            <ButtonGroup minimal>
-              <Button small text='Reset' icon='eraser' />
-              <Popover2
-                placement={Position.TOP}
-                isOpen={isOpen}
-                content={
-                  <Menu>
-                    {DEFAULT_CONFIG.map((it) => (
-                      <MenuItem
-                        key={it.id}
-                        icon='code'
-                        text={it.name}
-                        onClick={() => {
-                          setIsOpen(false)
-                          onChangeRawPlan(JSON.stringify(it.config, null, '  
'))
-                        }}
-                      />
-                    ))}
-                  </Menu>
-                }
-              >
+            <div className='btns'>
+              <ButtonGroup className='btns' minimal>
                 <Button
                   small
-                  text='Load Templates'
-                  rightIcon='caret-down'
-                  onClick={() => setIsOpen(!isOpen)}
+                  text='Reset'
+                  icon='eraser'
+                  onClick={() =>
+                    onChangeRawPlan(JSON.stringify([[]], null, '  '))
+                  }
+                />
+                <Popover2
+                  placement={Position.TOP}
+                  content={
+                    <Menu>
+                      {DEFAULT_CONFIG.map((it) => (
+                        <MenuItem
+                          key={it.id}
+                          icon='code'
+                          text={it.name}
+                          onClick={() =>
+                            onChangeRawPlan(
+                              JSON.stringify(it.config, null, '  ')
+                            )
+                          }
+                        />
+                      ))}
+                    </Menu>
+                  }
+                  renderTarget={({ isOpen, ref, ...targetProps }) => (
+                    <Button
+                      {...targetProps}
+                      elementRef={ref}
+                      small
+                      text='Load Templates'
+                      rightIcon='caret-down'
+                    />
+                  )}
                 />
-              </Popover2>
-            </ButtonGroup>
+              </ButtonGroup>
+            </div>
           </Card>
           <S.Tips>
             <span>To visually define blueprint tasks, please use </span>
diff --git a/config-ui/src/pages/blueprint/create/styled.ts 
b/config-ui/src/pages/blueprint/create/styled.ts
index 4e32c2b83..d50f1fd9d 100644
--- a/config-ui/src/pages/blueprint/create/styled.ts
+++ b/config-ui/src/pages/blueprint/create/styled.ts
@@ -43,6 +43,14 @@ export const Content = styled.div`
     font-weight: 600;
   }
 
+  textarea {
+    margin-bottom: 8px;
+    min-height: 240px;
+    font-size: 12px;
+    background-color: #f9f9f9;
+    font-family: 'JetBrains Mono', monospace;
+  }
+
   .back {
     display: flex;
     align-items: center;
diff --git a/config-ui/src/pages/blueprint/detail/styled.ts 
b/config-ui/src/pages/blueprint/detail/styled.ts
index f821b1f50..a0790596f 100644
--- a/config-ui/src/pages/blueprint/detail/styled.ts
+++ b/config-ui/src/pages/blueprint/detail/styled.ts
@@ -55,7 +55,7 @@ export const ConnectionColumn = styled.div`
 `
 
 export const ActionColumn = styled.div`
-  display: flex;
+  display: inline-flex;
   flex-direction: column;
   align-items: flex-start;
 
diff --git 
a/config-ui/src/plugins/common/data-scope-list/use-data-scope-list.ts 
b/config-ui/src/plugins/common/data-scope-list/use-data-scope-list.ts
index 2455608de..22347cbce 100644
--- a/config-ui/src/plugins/common/data-scope-list/use-data-scope-list.ts
+++ b/config-ui/src/plugins/common/data-scope-list/use-data-scope-list.ts
@@ -66,7 +66,7 @@ export const useDataScopeList = ({
           }
         case plugin === Plugins.Jenkins:
           return {
-            id: sc.fullName,
+            id: sc.jobFullName,
             name: sc.name,
             transformationRuleName: sc.transformationRuleName
           }
diff --git a/config-ui/src/plugins/common/data-scope/api.ts 
b/config-ui/src/plugins/common/data-scope/api.ts
index 45f0b40d8..7cac928a1 100644
--- a/config-ui/src/plugins/common/data-scope/api.ts
+++ b/config-ui/src/plugins/common/data-scope/api.ts
@@ -18,6 +18,9 @@
 
 import request from '@/components/utils/request'
 
+export const getDataScope = (plugin: string, connectionId: ID, repoId: ID) =>
+  request(`/plugins/${plugin}/connections/${connectionId}/scopes/${repoId}`)
+
 export const updateDataScope = (
   plugin: string,
   connectionId: ID,
diff --git a/config-ui/src/plugins/common/data-scope/use-data-scope.ts 
b/config-ui/src/plugins/common/data-scope/use-data-scope.ts
index 79b7ef878..c7b64dd13 100644
--- a/config-ui/src/plugins/common/data-scope/use-data-scope.ts
+++ b/config-ui/src/plugins/common/data-scope/use-data-scope.ts
@@ -51,42 +51,44 @@ export const useDataScope = ({
     setSelectedEntities(entities ?? [])
   }, [entities])
 
-  const formatScope = (scope: any) => {
-    return scope.map((sc: any) => {
-      switch (true) {
-        case plugin === Plugins.GitHub:
-          return {
-            ...sc,
-            id: sc.githubId,
-            entities: selectedEntities
-          }
-        case plugin === Plugins.JIRA:
-          return {
-            ...sc,
-            id: sc.boardId,
-            entities: selectedEntities
-          }
-        case plugin === Plugins.GitLab:
-          return {
-            ...sc,
-            id: sc.gitlabId,
-            entities: selectedEntities
-          }
-        case plugin === Plugins.Jenkins:
-          return {
-            ...sc,
-            id: sc.fullName,
-            entities: selectedEntities
-          }
+  const getPluginId = (scope: any) => {
+    switch (true) {
+      case plugin === Plugins.GitHub:
+        return scope.githubId
+      case plugin === Plugins.JIRA:
+        return scope.boardId
+      case plugin === Plugins.GitLab:
+        return scope.gitlabId
+      case plugin === Plugins.Jenkins:
+        return scope.jobFullName
+    }
+  }
+
+  const getDataScope = async (scope: any) => {
+    try {
+      const res = await API.getDataScope(
+        plugin,
+        connectionId,
+        getPluginId(scope)
+      )
+      return {
+        ...scope,
+        transformationRuleId: res.transformationRuleId
       }
-    })
+    } catch {
+      return scope
+    }
   }
 
   const handleSave = async () => {
+    const scope = await Promise.all(
+      selectedScope.map((sc: any) => getDataScope(sc))
+    )
+
     const [success, res] = await operator(
       () =>
         API.updateDataScope(plugin, connectionId, {
-          data: selectedScope.map((sc: any) => omit(sc, 'from'))
+          data: scope.map((sc: any) => omit(sc, 'from'))
         }),
       {
         setOperating: setSaving
@@ -94,7 +96,12 @@ export const useDataScope = ({
     )
 
     if (success) {
-      onSave?.(formatScope(res))
+      onSave?.(
+        res.map((it: any) => ({
+          id: getPluginId(it),
+          entities
+        }))
+      )
     }
   }
 
diff --git a/config-ui/src/plugins/common/transformation/use-transformation.ts 
b/config-ui/src/plugins/common/transformation/use-transformation.ts
index 9b04dd9f7..9641cc05d 100644
--- a/config-ui/src/plugins/common/transformation/use-transformation.ts
+++ b/config-ui/src/plugins/common/transformation/use-transformation.ts
@@ -143,7 +143,7 @@ export const useTransformation = ({
           case plugin === Plugins.GitLab:
             return sc.gitlabId
           case plugin === Plugins.Jenkins:
-            return sc.fullName
+            return sc.jobFullName
         }
       },
       onSave: handleSave,
diff --git a/config-ui/src/plugins/github/components/miller-columns/index.tsx 
b/config-ui/src/plugins/github/components/miller-columns/index.tsx
index 73a930b7b..c90ded983 100644
--- a/config-ui/src/plugins/github/components/miller-columns/index.tsx
+++ b/config-ui/src/plugins/github/components/miller-columns/index.tsx
@@ -57,7 +57,12 @@ export const MillerColumns = ({
         from: ScopeFromEnum.MILLER_COLUMNS,
         connectionId,
         githubId: it.githubId,
-        name: it.name
+        name: it.name,
+        ownerId: it.ownerId,
+        language: it.language,
+        description: it.description,
+        cloneUrl: it.cloneUrl,
+        HTMLUrl: it.HTMLUrl
       }))
 
     onChangeItems(result)
diff --git 
a/config-ui/src/plugins/github/components/miller-columns/use-miller-columns.ts 
b/config-ui/src/plugins/github/components/miller-columns/use-miller-columns.ts
index 411d6537e..e44a3a49d 100644
--- 
a/config-ui/src/plugins/github/components/miller-columns/use-miller-columns.ts
+++ 
b/config-ui/src/plugins/github/components/miller-columns/use-miller-columns.ts
@@ -63,7 +63,12 @@ export const useMillerColumns = ({ connectionId }: 
UseMillerColumnsProps) => {
       title: it.name,
       type: 'repo',
       githubId: it.id,
-      name: `${it.owner.login}/${it.name}`
+      name: `${it.owner.login}/${it.name}`,
+      ownerId: it.owner.id,
+      language: it.language,
+      description: it.description,
+      cloneUrl: it.clone_url,
+      HTMLUrl: it.html_url
     }))
 
   const setLoaded = useCallback(
diff --git 
a/config-ui/src/plugins/github/components/repo-selector/use-repo-selector.ts 
b/config-ui/src/plugins/github/components/repo-selector/use-repo-selector.ts
index 00a1aa059..02f122733 100644
--- a/config-ui/src/plugins/github/components/repo-selector/use-repo-selector.ts
+++ b/config-ui/src/plugins/github/components/repo-selector/use-repo-selector.ts
@@ -47,7 +47,12 @@ export const useRepoSelector = ({ connectionId }: 
UseRepoSelectorProps) => {
             from: ScopeFromEnum.REPO_SELECTOR,
             connectionId,
             githubId: it.id,
-            name: `${it.owner.login}/${it.name}`
+            name: `${it.owner.login}/${it.name}`,
+            ownerId: it.owner.id,
+            language: it.language,
+            description: it.description,
+            cloneUrl: it.clone_url,
+            HTMLUrl: it.html_url
           }))
         )
       } finally {
diff --git a/config-ui/src/plugins/github/types.ts 
b/config-ui/src/plugins/github/types.ts
index f88907a5b..7caec3897 100644
--- a/config-ui/src/plugins/github/types.ts
+++ b/config-ui/src/plugins/github/types.ts
@@ -26,4 +26,9 @@ export type ScopeItemType = {
   connectionId: ID
   githubId: number
   name: string
+  ownerId: ID
+  language: string
+  description: string
+  cloneUrl: string
+  HTMLUrl: string
 }
diff --git a/config-ui/src/plugins/gitlab/components/miller-columns/index.tsx 
b/config-ui/src/plugins/gitlab/components/miller-columns/index.tsx
index b31c16997..9ce2a4dcb 100644
--- a/config-ui/src/plugins/gitlab/components/miller-columns/index.tsx
+++ b/config-ui/src/plugins/gitlab/components/miller-columns/index.tsx
@@ -60,7 +60,16 @@ export const MillerColumns = ({
         from: ScopeFromEnum.MILLER_COLUMNS,
         connectionId,
         gitlabId: it.id,
-        name: it.name
+        name: it.name,
+        pathWithNamespace: it.pathWithNamespace,
+        creatorId: it.creatorId,
+        defaultBranch: it.defaultBranch,
+        description: it.description,
+        openIssuesCount: it.openIssuesCount,
+        starCount: it.starCount,
+        visibility: it.visibility,
+        webUrl: it.webUrl,
+        httpUrlToRepo: it.httpUrlToRepo
       }))
     onChangeItems(result)
   }, [seletedIds])
diff --git 
a/config-ui/src/plugins/gitlab/components/miller-columns/use-miller-columns.ts 
b/config-ui/src/plugins/gitlab/components/miller-columns/use-miller-columns.ts
index 1fc62ba2f..34d1e561c 100644
--- 
a/config-ui/src/plugins/gitlab/components/miller-columns/use-miller-columns.ts
+++ 
b/config-ui/src/plugins/gitlab/components/miller-columns/use-miller-columns.ts
@@ -81,7 +81,16 @@ export const useMillerColumns = <T>({
       title: it.name,
       type: 'project',
       gitlabId: it.id,
-      name: it.path_with_namespace
+      name: it.path_with_namespace,
+      pathWithNamespace: it.path_with_namespace,
+      creatorId: it.creator_id,
+      defaultBranch: it.default_branch,
+      description: it.description,
+      openIssuesCount: it.open_issues_count,
+      starCount: it.star_count,
+      visibility: it.visibility,
+      webUrl: it.web_url,
+      httpUrlToRepo: it.http_url_to_repo
     }))
 
   const setLoaded = (id: ID, params: MapValueType) => {
diff --git 
a/config-ui/src/plugins/gitlab/components/project-selector/use-project-selector.ts
 
b/config-ui/src/plugins/gitlab/components/project-selector/use-project-selector.ts
index 2d4a01f10..238cd2cdd 100644
--- 
a/config-ui/src/plugins/gitlab/components/project-selector/use-project-selector.ts
+++ 
b/config-ui/src/plugins/gitlab/components/project-selector/use-project-selector.ts
@@ -52,7 +52,16 @@ export const usebProjectSelector = ({
           res.map((it: any) => ({
             from: ScopeFromEnum.PROJECT_SELECTOR,
             gitlabId: it.id,
-            name: it.path_with_namespace
+            name: it.path_with_namespace,
+            pathWithNamespace: it.path_with_namespace,
+            creatorId: it.creator_id,
+            defaultBranch: it.default_branch,
+            description: it.description,
+            openIssuesCount: it.open_issues_count,
+            starCount: it.star_count,
+            visibility: it.visibility,
+            webUrl: it.web_url,
+            httpUrlToRepo: it.http_url_to_repo
           }))
         )
       } finally {
diff --git a/config-ui/src/plugins/gitlab/types.ts 
b/config-ui/src/plugins/gitlab/types.ts
index 3a143533c..d8ffb1fd8 100644
--- a/config-ui/src/plugins/gitlab/types.ts
+++ b/config-ui/src/plugins/gitlab/types.ts
@@ -26,4 +26,13 @@ export type ScopeItemType = {
   connectionId: ID
   gitlabId: ID
   name: string
+  pathWithNamespace: string
+  creatorId: ID
+  defaultBranch: string
+  description: string
+  openIssuesCount: number
+  starCount: number
+  visibility: string
+  webUrl: string
+  httpUrlToRepo: string
 }
diff --git a/config-ui/src/plugins/jenkins/components/miller-columns/index.tsx 
b/config-ui/src/plugins/jenkins/components/miller-columns/index.tsx
index 411973b4e..8d8a34962 100644
--- a/config-ui/src/plugins/jenkins/components/miller-columns/index.tsx
+++ b/config-ui/src/plugins/jenkins/components/miller-columns/index.tsx
@@ -43,7 +43,7 @@ export const MillerColumns = ({
   })
 
   useEffect(() => {
-    setSelectedIds(selectedItems.map((it) => it.fullName))
+    setSelectedIds(selectedItems.map((it) => it.jobFullName))
   }, [])
 
   useEffect(() => {
@@ -51,7 +51,7 @@ export const MillerColumns = ({
       .filter((it) => seletedIds.includes(it.id) && it.type !== 'folder')
       .map((it: any) => ({
         connectionId,
-        fullName: it.name
+        jobFullName: it.name
       }))
 
     onChangeItems(result)
diff --git a/config-ui/src/plugins/jenkins/types.ts 
b/config-ui/src/plugins/jenkins/types.ts
index e6d6b7f8b..d490f948e 100644
--- a/config-ui/src/plugins/jenkins/types.ts
+++ b/config-ui/src/plugins/jenkins/types.ts
@@ -18,5 +18,5 @@
 
 export type ScopeItemType = {
   connectionId: ID
-  fullName: string
+  jobFullName: string
 }
diff --git a/config-ui/src/plugins/jira/types.ts 
b/config-ui/src/plugins/jira/types.ts
index 9196794ff..c1fe9105a 100644
--- a/config-ui/src/plugins/jira/types.ts
+++ b/config-ui/src/plugins/jira/types.ts
@@ -20,4 +20,7 @@ export type ScopeItemType = {
   connectionId: ID
   boardId: ID
   name: string
+  projectId: ID
+  self: string
+  type: string
 }
diff --git a/config-ui/src/store/connections/use-context-value.ts 
b/config-ui/src/store/connections/use-context-value.ts
index cb7d9c32e..0b5396292 100644
--- a/config-ui/src/store/connections/use-context-value.ts
+++ b/config-ui/src/store/connections/use-context-value.ts
@@ -30,8 +30,8 @@ export const useContextValue = (plugins: string[]) => {
 
   const allConnections = useMemo(
     () =>
-      PluginConfig.filter((p) => p.plugin === PluginType.Connection).filter(
-        (p) => (!plugins.length ? true : plugins.includes(p.plugin))
+      PluginConfig.filter((p) => p.type === PluginType.Connection).filter((p) 
=>
+        !plugins.length ? true : plugins.includes(p.plugin)
       ),
     [plugins]
   )

Reply via email to