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/04/18 08:54:55 UTC

(incubator-devlake) branch feat-tapd-connection-companyId updated (d917e8c7f -> 841afeb84)

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

mintsweet pushed a change to branch feat-tapd-connection-companyId
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


 discard d917e8c7f feat: remove companyId to connection in tapd
     new 841afeb84 feat: remove companyId to connection in tapd

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d917e8c7f)
            \
             N -- N -- N   refs/heads/feat-tapd-connection-companyId (841afeb84)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 config-ui/src/plugins/register/tapd/index.ts | 1 -
 1 file changed, 1 deletion(-)


(incubator-devlake) 01/01: feat: remove companyId to connection in tapd

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

mintsweet pushed a commit to branch feat-tapd-connection-companyId
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 841afeb843ad7481014414e0cbc4cbae74447666
Author: mintsweet <0x...@gmail.com>
AuthorDate: Thu Apr 18 16:54:11 2024 +0800

    feat: remove companyId to connection in tapd
---
 config-ui/src/api/connection/index.ts              |  11 +-
 .../components/connection-form/fields/token.tsx    |  17 ---
 .../plugins/components/connection-form/index.tsx   |   2 +
 config-ui/src/plugins/register/github/config.tsx   |   1 +
 config-ui/src/plugins/register/tapd/config.tsx     |  17 ++-
 .../register/tapd/connection-fields/company-id.tsx |  62 ++++++++++
 .../register/tapd/{ => connection-fields}/index.ts |   4 +-
 config-ui/src/plugins/register/tapd/data-scope.tsx | 128 ---------------------
 config-ui/src/plugins/register/tapd/index.ts       |   1 -
 config-ui/src/types/connection.ts                  |   2 +
 10 files changed, 93 insertions(+), 152 deletions(-)

diff --git a/config-ui/src/api/connection/index.ts b/config-ui/src/api/connection/index.ts
index a546c9855..e376036c0 100644
--- a/config-ui/src/api/connection/index.ts
+++ b/config-ui/src/api/connection/index.ts
@@ -42,7 +42,16 @@ export const test = (
   payload?: Partial<
     Pick<
       IConnectionAPI,
-      'endpoint' | 'authMethod' | 'username' | 'password' | 'token' | 'appId' | 'secretKey' | 'proxy' | 'dbUrl'
+      | 'endpoint'
+      | 'authMethod'
+      | 'username'
+      | 'password'
+      | 'token'
+      | 'appId'
+      | 'secretKey'
+      | 'proxy'
+      | 'dbUrl'
+      | 'companyId'
     >
   >,
 ): Promise<IConnectionTestResult> =>
diff --git a/config-ui/src/plugins/components/connection-form/fields/token.tsx b/config-ui/src/plugins/components/connection-form/fields/token.tsx
index 1788ed395..344a100ba 100644
--- a/config-ui/src/plugins/components/connection-form/fields/token.tsx
+++ b/config-ui/src/plugins/components/connection-form/fields/token.tsx
@@ -15,23 +15,6 @@
  * limitations under the License.
  *
  */
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
 
 import { useEffect } from 'react';
 import { Input } from 'antd';
diff --git a/config-ui/src/plugins/components/connection-form/index.tsx b/config-ui/src/plugins/components/connection-form/index.tsx
index 4f6582e05..af2852599 100644
--- a/config-ui/src/plugins/components/connection-form/index.tsx
+++ b/config-ui/src/plugins/components/connection-form/index.tsx
@@ -72,6 +72,7 @@ export const ConnectionForm = ({ plugin, connectionId, onSuccess }: Props) => {
               secretKey: isEqual(connection?.secretKey, values.secretKey) ? undefined : values.secretKey,
               proxy: isEqual(connection?.proxy, values.proxy) ? undefined : values.proxy,
               dbUrl: isEqual(connection?.dbUrl, values.dbUrl) ? undefined : values.dbUrl,
+              companyId: isEqual(connection?.companyId, values.companyId) ? undefined : values.companyId,
             })
           : API.connection.testOld(
               plugin,
@@ -87,6 +88,7 @@ export const ConnectionForm = ({ plugin, connectionId, onSuccess }: Props) => {
                 'tenantId',
                 'tenantType',
                 'dbUrl',
+                'companyId',
               ]),
             ),
       {
diff --git a/config-ui/src/plugins/register/github/config.tsx b/config-ui/src/plugins/register/github/config.tsx
index 295d9d1ad..1679cdfae 100644
--- a/config-ui/src/plugins/register/github/config.tsx
+++ b/config-ui/src/plugins/register/github/config.tsx
@@ -100,6 +100,7 @@ export const GitHubConfig: IPluginConfig = {
     ],
   },
   dataScope: {
+    localSearch: true,
     title: 'Repositories',
     millerColumn: {
       columnCount: 2,
diff --git a/config-ui/src/plugins/register/tapd/config.tsx b/config-ui/src/plugins/register/tapd/config.tsx
index d0124db17..cdce22db3 100644
--- a/config-ui/src/plugins/register/tapd/config.tsx
+++ b/config-ui/src/plugins/register/tapd/config.tsx
@@ -20,7 +20,7 @@ import { ExternalLink } from '@/components';
 import { DOC_URL } from '@/release';
 import { IPluginConfig } from '@/types';
 
-import { DataScope } from './data-scope';
+import { CompanyId } from './connection-fields';
 import Icon from './assets/icon.svg?react';
 
 export const TAPDConfig: IPluginConfig = {
@@ -56,6 +56,16 @@ export const TAPDConfig: IPluginConfig = {
         label: 'API Token',
         placeholder: 'Your API Token',
       },
+      ({ initialValues, values, errors, setValues, setErrors }: any) => (
+        <CompanyId
+          key="companyId"
+          initialValue={initialValues.companyId}
+          value={values.companyId}
+          error={errors.companyId}
+          setValue={(value) => setValues({ companyId: value })}
+          setError={(error) => setErrors({ companyId: error })}
+        />
+      ),
       'proxy',
       {
         key: 'rateLimitPerHour',
@@ -68,7 +78,10 @@ export const TAPDConfig: IPluginConfig = {
     ],
   },
   dataScope: {
-    render: ({ ...props }: any) => <DataScope {...props} />,
+    title: 'Workspaces',
+    millerColumn: {
+      columnCount: 2.5,
+    },
   },
   scopeConfig: {
     entities: ['TICKET', 'CROSS'],
diff --git a/config-ui/src/plugins/register/tapd/connection-fields/company-id.tsx b/config-ui/src/plugins/register/tapd/connection-fields/company-id.tsx
new file mode 100644
index 000000000..afb8f8b5d
--- /dev/null
+++ b/config-ui/src/plugins/register/tapd/connection-fields/company-id.tsx
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { ChangeEvent, useEffect } from 'react';
+import { Input } from 'antd';
+
+import { Block } from '@/components';
+
+interface Props {
+  initialValue: number;
+  value: number;
+  error: string;
+  setValue: (value: number) => void;
+  setError: (value: string) => void;
+}
+
+export const CompanyId = ({ initialValue, value, setValue, setError }: Props) => {
+  useEffect(() => {
+    setValue(initialValue);
+  }, [initialValue]);
+
+  useEffect(() => {
+    let error = '';
+
+    if (!value) {
+      error = 'company id is required';
+    } else if (!/\d/.test(value.toString())) {
+      error = 'company id is a number';
+    }
+
+    setError(error);
+  }, [value]);
+
+  const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
+    const value = +e.target.value;
+
+    if (typeof value === 'number' && !isNaN(value)) {
+      setValue(value);
+    }
+  };
+
+  return (
+    <Block title="Company ID" description="" required>
+      <Input style={{ width: 386 }} placeholder="Company ID" value={value} onChange={handleChange} />
+    </Block>
+  );
+};
diff --git a/config-ui/src/plugins/register/tapd/index.ts b/config-ui/src/plugins/register/tapd/connection-fields/index.ts
similarity index 89%
copy from config-ui/src/plugins/register/tapd/index.ts
copy to config-ui/src/plugins/register/tapd/connection-fields/index.ts
index 14fdb67cd..98afdfa28 100644
--- a/config-ui/src/plugins/register/tapd/index.ts
+++ b/config-ui/src/plugins/register/tapd/connection-fields/index.ts
@@ -16,6 +16,4 @@
  *
  */
 
-export * from './config';
-export * from './data-scope';
-export * from './transformation';
+export * from './company-id';
diff --git a/config-ui/src/plugins/register/tapd/data-scope.tsx b/config-ui/src/plugins/register/tapd/data-scope.tsx
deleted file mode 100644
index 2aee59e15..000000000
--- a/config-ui/src/plugins/register/tapd/data-scope.tsx
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { useEffect, useState } from 'react';
-import { Input, Button } from 'antd';
-import type { McsID, McsItem } from 'miller-columns-select';
-import MillerColumnsSelect from 'miller-columns-select';
-
-import API from '@/api';
-import { ExternalLink, Loading } from '@/components';
-import * as T from '@/plugins/components/data-scope-remote/types';
-// import * as API from '@/plugins/components/data-scope-remote/api';
-
-// import { prepareToken } from './api';
-
-interface Props {
-  connectionId: ID;
-  disabledItems: T.ResItem[];
-  selectedItems: T.ResItem[];
-  onChangeSelectedItems: (items: T.ResItem[]) => void;
-}
-
-export const DataScope = ({ connectionId, disabledItems, selectedItems, onChangeSelectedItems }: Props) => {
-  const [pageToken, setPageToken] = useState<string | undefined>(undefined);
-  const [companyId, setCompanyId] = useState<string>(
-    localStorage.getItem(`plugin/tapd/connections/${connectionId}/company_id`) || '',
-  );
-
-  const [miller, setMiller] = useState<{
-    items: McsItem<T.ResItem>[];
-    loadedIds: ID[];
-  }>({
-    items: [],
-    loadedIds: [],
-  });
-
-  useEffect(() => {
-    if (!pageToken) return;
-    getItems(null, pageToken);
-  }, [pageToken]);
-
-  const getItems = async (groupId: ID | null, currentPageToken?: string) => {
-    const res = await API.scope.remote('tapd', connectionId, {
-      groupId,
-      pageToken: currentPageToken,
-    });
-
-    const newItems = (res.children ?? []).map((it) => ({
-      ...it,
-      title: it.name,
-    }));
-
-    setMiller((m) => ({
-      ...m,
-      items: [...m.items, ...newItems],
-      loadedIds: [...m.loadedIds, groupId ? groupId : 'root'],
-    }));
-  };
-
-  const getPageToken = async (companyId: string | undefined) => {
-    if (!companyId) {
-      setPageToken(undefined);
-      return;
-    }
-    const res = await API.plugin.tapd.remoteScopePrepareToken(connectionId, {
-      companyId,
-    });
-    setPageToken(res.pageToken);
-  };
-
-  return (
-    <>
-      <h4>Workspaces *</h4>
-      <p>Type in the company ID to list all the workspaces you want to sync. </p>
-      <ExternalLink link="https://www.tapd.cn/help/show#1120003271001000103">
-        Learn about how to get your company ID
-      </ExternalLink>
-
-      <div>
-        <Input
-          placeholder="Your company ID"
-          value={companyId}
-          style={{ width: 300 }}
-          onChange={(e) => {
-            setCompanyId(e.target.value);
-            localStorage.setItem(`plugin/tapd/connections/${connectionId}/company_id`, e.target.value);
-          }}
-        />
-        <Button type="primary" onClick={() => getPageToken(companyId)}>
-          Search
-        </Button>
-      </div>
-
-      {pageToken && (
-        <MillerColumnsSelect
-          items={miller.items}
-          getCanExpand={(it) => it.type === 'group'}
-          getHasMore={(id) => !miller.loadedIds.includes(id ?? 'root')}
-          onExpand={(id: McsID) => getItems(id, pageToken)}
-          onScroll={(id: McsID | null) => getItems(id, pageToken)}
-          columnCount={2.5}
-          columnHeight={300}
-          renderLoading={() => <Loading size={20} style={{ padding: '4px 12px' }} />}
-          disabledIds={(disabledItems ?? []).map((it) => it.id)}
-          selectedIds={selectedItems.map((it) => it.id)}
-          onSelectItemIds={(selectedIds: ID[]) =>
-            onChangeSelectedItems(miller.items.filter((it) => selectedIds.includes(it.id)))
-          }
-        />
-      )}
-    </>
-  );
-};
diff --git a/config-ui/src/plugins/register/tapd/index.ts b/config-ui/src/plugins/register/tapd/index.ts
index 14fdb67cd..5f16858cb 100644
--- a/config-ui/src/plugins/register/tapd/index.ts
+++ b/config-ui/src/plugins/register/tapd/index.ts
@@ -17,5 +17,4 @@
  */
 
 export * from './config';
-export * from './data-scope';
 export * from './transformation';
diff --git a/config-ui/src/types/connection.ts b/config-ui/src/types/connection.ts
index 806eb18d3..b5b957306 100644
--- a/config-ui/src/types/connection.ts
+++ b/config-ui/src/types/connection.ts
@@ -28,6 +28,7 @@ export interface IConnectionAPI {
   secretKey?: string;
   dbUrl?: string;
   enableGraphql?: boolean;
+  companyId?: number;
   proxy: string;
   rateLimitPerHour?: number;
 }
@@ -81,6 +82,7 @@ export interface IConnection {
   secretKey?: string;
   dbUrl?: string;
   enableGraphql?: boolean;
+  companyId?: number;
   proxy: string;
   rateLimitPerHour?: number;
 }