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 52df28494 feat(config-ui): use remote api to replace proxy api in jira 
(#5379)
52df28494 is described below

commit 52df284941e8c0f2d1c27ecc366fe38481338b3f
Author: 青湛 <[email protected]>
AuthorDate: Wed Jun 7 10:17:21 2023 +0800

    feat(config-ui): use remote api to replace proxy api in jira (#5379)
---
 .../src/plugins/register/jira/components/index.ts  | 19 -----
 .../jira/components/miller-columns/index.tsx       | 90 ----------------------
 .../miller-columns/use-miller-columns.ts           | 78 -------------------
 config-ui/src/plugins/register/jira/data-scope.tsx | 22 +++++-
 4 files changed, 18 insertions(+), 191 deletions(-)

diff --git a/config-ui/src/plugins/register/jira/components/index.ts 
b/config-ui/src/plugins/register/jira/components/index.ts
deleted file mode 100644
index 30c0d1fa0..000000000
--- a/config-ui/src/plugins/register/jira/components/index.ts
+++ /dev/null
@@ -1,19 +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.
- *
- */
-
-export * from './miller-columns';
diff --git 
a/config-ui/src/plugins/register/jira/components/miller-columns/index.tsx 
b/config-ui/src/plugins/register/jira/components/miller-columns/index.tsx
deleted file mode 100644
index c8a92ccdf..000000000
--- a/config-ui/src/plugins/register/jira/components/miller-columns/index.tsx
+++ /dev/null
@@ -1,90 +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 { useState, useEffect } from 'react';
-import type { McsItem } from 'miller-columns-select';
-import MillerColumnsSelect from 'miller-columns-select';
-
-import { Loading } from '@/components';
-
-import { ScopeItemType } from '../../types';
-
-import type { UseMillerColumnsProps } from './use-miller-columns';
-import { useMillerColumns } from './use-miller-columns';
-
-interface Props extends UseMillerColumnsProps {
-  disabledItems?: ScopeItemType[];
-  selectedItems: ScopeItemType[];
-  onChangeItems: (selectedItems: ScopeItemType[]) => void;
-}
-
-export const MillerColumns = ({ connectionId, disabledItems, selectedItems, 
onChangeItems }: Props) => {
-  const [selectedIds, setSelectedIds] = useState<ID[]>([]);
-  const [disabledIds, setDisabledIds] = useState<ID[]>([]);
-
-  const { items, getHasMore, onScroll } = useMillerColumns({
-    connectionId,
-  });
-
-  useEffect(() => {
-    setSelectedIds(selectedItems.map((it) => it.boardId));
-  }, [selectedItems]);
-
-  useEffect(() => {
-    setDisabledIds((disabledItems ?? []).map((it) => it.boardId));
-  }, [disabledItems]);
-
-  const handleChangeItems = (selectedIds: ID[]) => {
-    const result = selectedIds.map((id) => {
-      const selectedItem = selectedItems.find((it) => it.boardId === id);
-      if (selectedItem) {
-        return selectedItem;
-      }
-
-      const item = items.find((it) => it.id === id) as McsItem<ScopeItemType>;
-      return {
-        connectionId,
-        boardId: item.boardId,
-        name: item.name,
-        self: item.self,
-        type: item.type,
-        projectId: item.projectId,
-      };
-    });
-
-    onChangeItems(result);
-  };
-
-  const renderLoading = () => {
-    return <Loading size={20} style={{ padding: '4px 12px' }} />;
-  };
-
-  return (
-    <MillerColumnsSelect
-      items={items}
-      getHasMore={getHasMore}
-      onScroll={onScroll}
-      columnCount={1}
-      columnHeight={300}
-      renderLoading={renderLoading}
-      disabledIds={disabledIds}
-      selectedIds={selectedIds}
-      onSelectItemIds={handleChangeItems}
-    />
-  );
-};
diff --git 
a/config-ui/src/plugins/register/jira/components/miller-columns/use-miller-columns.ts
 
b/config-ui/src/plugins/register/jira/components/miller-columns/use-miller-columns.ts
deleted file mode 100644
index 41d7981da..000000000
--- 
a/config-ui/src/plugins/register/jira/components/miller-columns/use-miller-columns.ts
+++ /dev/null
@@ -1,78 +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 { useState, useEffect, useMemo } from 'react';
-import type { McsItem } from 'miller-columns-select';
-
-import { useProxyPrefix } from '@/hooks';
-
-import type { ScopeItemType } from '../../types';
-import * as API from '../../api';
-
-const DEFAULT_PAGE_SIZE = 50;
-
-export interface UseMillerColumnsProps {
-  connectionId: ID;
-}
-
-export const useMillerColumns = ({ connectionId }: UseMillerColumnsProps) => {
-  const [items, setItems] = useState<McsItem<ScopeItemType>[]>([]);
-  const [isLast, setIsLast] = useState(false);
-  const [page, setPage] = useState(1);
-
-  const prefix = useProxyPrefix({
-    plugin: 'jira',
-    connectionId,
-  });
-
-  const updateItems = (arr: any) =>
-    arr.map((it: any) => ({
-      parentId: null,
-      id: it.id,
-      title: it.name,
-      boardId: it.id,
-      name: it.name,
-      self: it.self,
-      type: it.type,
-      projectId: it?.location?.projectId,
-    }));
-
-  useEffect(() => {
-    (async () => {
-      const res = await API.getBoards(prefix, {
-        startAt: (page - 1) * DEFAULT_PAGE_SIZE,
-        maxResults: DEFAULT_PAGE_SIZE,
-      });
-      setIsLast(res.isLast);
-      setItems([...items, ...updateItems(res.values)]);
-    })();
-  }, [prefix, page]);
-
-  return useMemo(
-    () => ({
-      items,
-      getHasMore() {
-        return !isLast;
-      },
-      onScroll() {
-        setPage(page + 1);
-      },
-    }),
-    [items, isLast, page],
-  );
-};
diff --git a/config-ui/src/plugins/register/jira/data-scope.tsx 
b/config-ui/src/plugins/register/jira/data-scope.tsx
index 15f4e3800..83a781b2a 100644
--- a/config-ui/src/plugins/register/jira/data-scope.tsx
+++ b/config-ui/src/plugins/register/jira/data-scope.tsx
@@ -16,9 +16,11 @@
  *
  */
 
-import type { ScopeItemType } from './types';
+import { useMemo } from 'react';
+
+import { DataScopeMillerColumns } from '@/plugins';
 
-import { MillerColumns } from './components/miller-columns';
+import type { ScopeItemType } from './types';
 
 interface Props {
   connectionId: ID;
@@ -27,12 +29,24 @@ interface Props {
   onChangeItems: (selectedItems: ScopeItemType[]) => void;
 }
 
-export const JiraDataScope = ({ connectionId, disabledItems, selectedItems, 
onChangeItems }: Props) => {
+export const JiraDataScope = ({ connectionId, onChangeItems, ...props }: 
Props) => {
+  const selectedItems = useMemo(
+    () => props.selectedItems.map((it) => ({ id: `${it.boardId}`, name: 
it.name, data: it })),
+    [props.selectedItems],
+  );
+
+  const disabledItems = useMemo(
+    () => (props.disabledItems ?? []).map((it) => ({ id: `${it.boardId}`, 
name: it.name, data: it })),
+    [props.disabledItems],
+  );
+
   return (
     <>
       <h3>Boards *</h3>
       <p>Select the boards you would like to sync.</p>
-      <MillerColumns
+      <DataScopeMillerColumns
+        plugin="jira"
+        columnCount={1}
         connectionId={connectionId}
         disabledItems={disabledItems}
         selectedItems={selectedItems}

Reply via email to