This is an automated email from the ASF dual-hosted git repository.
mintsweet 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 309b1b33a feat(config-ui): use remote api to replace proxy api in
jenkins (#5392)
309b1b33a is described below
commit 309b1b33a12717a32c067ce0a34611e9bb65a099
Author: 青湛 <[email protected]>
AuthorDate: Wed Jun 7 15:29:46 2023 +0800
feat(config-ui): use remote api to replace proxy api in jenkins (#5392)
---
config-ui/src/plugins/register/jenkins/api.ts | 24 ------
.../plugins/register/jenkins/components/index.ts | 19 -----
.../jenkins/components/miller-columns/index.tsx | 89 ----------------------
.../miller-columns/use-miller-columns.ts | 77 -------------------
.../src/plugins/register/jenkins/data-scope.tsx | 26 ++++++-
config-ui/src/plugins/register/jenkins/types.ts | 1 +
6 files changed, 23 insertions(+), 213 deletions(-)
diff --git a/config-ui/src/plugins/register/jenkins/api.ts
b/config-ui/src/plugins/register/jenkins/api.ts
deleted file mode 100644
index 7e469cf32..000000000
--- a/config-ui/src/plugins/register/jenkins/api.ts
+++ /dev/null
@@ -1,24 +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 { request } from '@/utils';
-
-export const getJobs = (prefix: string) =>
request(`${prefix}/api/json?tree=jobs[name,jobs]{0,10000}`);
-
-export const getJobChildJobs = (prefix: string, childPath: string) =>
- request(`${prefix}/job/${childPath}/api/json?tree=jobs[name,jobs]{0,10000}`);
diff --git a/config-ui/src/plugins/register/jenkins/components/index.ts
b/config-ui/src/plugins/register/jenkins/components/index.ts
deleted file mode 100644
index 30c0d1fa0..000000000
--- a/config-ui/src/plugins/register/jenkins/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/jenkins/components/miller-columns/index.tsx
b/config-ui/src/plugins/register/jenkins/components/miller-columns/index.tsx
deleted file mode 100644
index 0c1fd19fa..000000000
--- a/config-ui/src/plugins/register/jenkins/components/miller-columns/index.tsx
+++ /dev/null
@@ -1,89 +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 type { ScopeItemType } from '../../types';
-
-import type { UseMillerColumnsProps, ExtraType } 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, onExpand } = useMillerColumns({
- connectionId,
- });
-
- useEffect(() => {
- setSelectedIds(selectedItems.map((it) => it.jobFullName));
- }, [selectedItems]);
-
- useEffect(() => {
- setDisabledIds((disabledItems ?? []).map((it) => it.jobFullName));
- }, [disabledItems]);
-
- const handleChangeItems = (selectedIds: ID[]) => {
- const result = selectedIds.map((id) => {
- const selectedItem = selectedItems.find((it) => it.jobFullName === id);
- if (selectedItem) {
- return selectedItem;
- }
-
- const item = items.find((it) => it.id === id) as McsItem<ExtraType>;
- return {
- connectionId,
- jobFullName: item.id as string,
- name: item.id,
- };
- });
-
- onChangeItems(result);
- };
-
- const renderLoading = () => {
- return <Loading size={20} style={{ padding: '4px 12px' }} />;
- };
-
- return (
- <MillerColumnsSelect
- showSelectAll
- items={items}
- getCanExpand={(it) => it.type === 'folder'}
- onExpand={onExpand}
- columnCount={2.5}
- columnHeight={300}
- getHasMore={getHasMore}
- renderLoading={renderLoading}
- disabledIds={disabledIds}
- selectedIds={selectedIds}
- onSelectItemIds={handleChangeItems}
- />
- );
-};
diff --git
a/config-ui/src/plugins/register/jenkins/components/miller-columns/use-miller-columns.ts
b/config-ui/src/plugins/register/jenkins/components/miller-columns/use-miller-columns.ts
deleted file mode 100644
index 527ddef9d..000000000
---
a/config-ui/src/plugins/register/jenkins/components/miller-columns/use-miller-columns.ts
+++ /dev/null
@@ -1,77 +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 { McsID, McsItem } from 'miller-columns-select';
-
-import { useProxyPrefix } from '@/hooks';
-
-import type { ScopeItemType } from '../../types';
-import * as API from '../../api';
-
-export type ExtraType = {
- type: 'folder' | 'file';
-} & ScopeItemType;
-
-export interface UseMillerColumnsProps {
- connectionId: ID;
-}
-
-export const useMillerColumns = ({ connectionId }: UseMillerColumnsProps) => {
- const [items, setItems] = useState<McsItem<ExtraType>[]>([]);
- const [loadedIds, setLoadedIds] = useState<ID[]>([]);
-
- const prefix = useProxyPrefix({
- plugin: 'jenkins',
- connectionId,
- });
-
- const formatJobs = (jobs: any, parentId: ID | null = null) =>
- jobs.map((it: any) => ({
- parentId,
- id: parentId ? `${parentId}/${it.name}` : it.name,
- title: it.name,
- type: it.jobs ? 'folder' : 'file',
- }));
-
- useEffect(() => {
- (async () => {
- const res = await API.getJobs(prefix);
- setItems(formatJobs(res.jobs));
- setLoadedIds(['root']);
- })();
- }, [prefix]);
-
- const onExpand = async (id: McsID) => {
- const res = await API.getJobChildJobs(prefix, (id as
string).split('/').join('/job/'));
-
- setLoadedIds([...loadedIds, id]);
- setItems([...items, ...formatJobs(res.jobs, id)]);
- };
-
- return useMemo(
- () => ({
- items,
- getHasMore(id: McsID | null) {
- return !loadedIds.includes(id ?? 'root');
- },
- onExpand,
- }),
- [items, loadedIds],
- );
-};
diff --git a/config-ui/src/plugins/register/jenkins/data-scope.tsx
b/config-ui/src/plugins/register/jenkins/data-scope.tsx
index bf8322840..2dbb9003b 100644
--- a/config-ui/src/plugins/register/jenkins/data-scope.tsx
+++ b/config-ui/src/plugins/register/jenkins/data-scope.tsx
@@ -16,9 +16,11 @@
*
*/
-import type { ScopeItemType } from './types';
+import { useMemo } from 'react';
+
+import { DataScopeMillerColumns } from '@/plugins';
-import { MillerColumns } from './components';
+import type { ScopeItemType } from './types';
interface Props {
connectionId: ID;
@@ -27,12 +29,28 @@ interface Props {
onChangeItems: (selectedItems: ScopeItemType[]) => void;
}
-export const JenkinsDataScope = ({ connectionId, disabledItems, selectedItems,
onChangeItems }: Props) => {
+export const JenkinsDataScope = ({ connectionId, onChangeItems, ...props }:
Props) => {
+ const selectedItems = useMemo(
+ () => props.selectedItems.map((it) => ({ id: `${it.jobFullName}`, name:
it.name, data: it })),
+ [props.selectedItems],
+ );
+
+ const disabledItems = useMemo(
+ () => (props.disabledItems ?? []).map((it) => ({ id: `${it.jobFullName}`,
name: it.name, data: it })),
+ [props.disabledItems],
+ );
+
return (
<>
<h3>Jobs *</h3>
<p>Select the jobs you would like to sync.</p>
- <MillerColumns connectionId={connectionId} selectedItems={selectedItems}
onChangeItems={onChangeItems} />
+ <DataScopeMillerColumns
+ plugin="jenkins"
+ connectionId={connectionId}
+ disabledItems={disabledItems}
+ selectedItems={selectedItems}
+ onChangeItems={onChangeItems}
+ />
</>
);
};
diff --git a/config-ui/src/plugins/register/jenkins/types.ts
b/config-ui/src/plugins/register/jenkins/types.ts
index 9636ea6ec..9ac6a76d3 100644
--- a/config-ui/src/plugins/register/jenkins/types.ts
+++ b/config-ui/src/plugins/register/jenkins/types.ts
@@ -19,4 +19,5 @@
export type ScopeItemType = {
connectionId: ID;
jobFullName: string;
+ name: string;
};