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 9f2c08c81 feat(config-ui): improve plugin component data scope remote
(#6568)
9f2c08c81 is described below
commit 9f2c08c8169de99908742b79679d1abe5e11693d
Author: 青湛 <[email protected]>
AuthorDate: Thu Dec 7 10:31:48 2023 +0800
feat(config-ui): improve plugin component data scope remote (#6568)
---
.../components/data-scope-remote/search-local.tsx | 102 ++++++++++++---------
.../components/data-scope-remote/search-remote.tsx | 78 ++++++++++------
2 files changed, 107 insertions(+), 73 deletions(-)
diff --git
a/config-ui/src/plugins/components/data-scope-remote/search-local.tsx
b/config-ui/src/plugins/components/data-scope-remote/search-local.tsx
index aff5210d9..de090b3ca 100644
--- a/config-ui/src/plugins/components/data-scope-remote/search-local.tsx
+++ b/config-ui/src/plugins/components/data-scope-remote/search-local.tsx
@@ -17,14 +17,14 @@
*/
import { useState, useEffect, useMemo } from 'react';
-import { Modal } from 'antd';
-import { Button, InputGroup, Icon, Intent } from '@blueprintjs/core';
+import { CheckCircleFilled } from '@ant-design/icons';
+import { Form, Select, Button, Input, Modal, message } from 'antd';
import type { McsID, McsItem, McsColumn } from 'miller-columns-select';
import { MillerColumnsSelect } from 'miller-columns-select';
import { useDebounce } from 'ahooks';
import API from '@/api';
-import { FormItem, MultiSelector, Loading, Message } from '@/components';
+import { Loading, Message } from '@/components';
import { IPluginConfig } from '@/types';
import * as T from './types';
@@ -46,6 +46,7 @@ export const SearchLocal = ({ plugin, connectionId, config,
disabledScope, selec
items: McsItem<T.ResItem>[];
loadedIds: ID[];
expandedIds: ID[];
+ errorId?: ID | null;
nextTokenMap: Record<ID, string>;
}>({
items: [],
@@ -60,6 +61,11 @@ export const SearchLocal = ({ plugin, connectionId, config,
disabledScope, selec
const [query, setQuery] = useState('');
const search = useDebounce(query, { wait: 500 });
+ const [selectedIds, selectedOptions] = useMemo(
+ () => [selectedScope.map((sc) => sc.id), selectedScope.map((sc) => ({
label: sc.fullName, value: sc.id }))],
+ [selectedScope],
+ );
+
const scopes = useMemo(
() =>
search
@@ -89,29 +95,40 @@ export const SearchLocal = ({ plugin, connectionId, config,
disabledScope, selec
return;
}
- const res = await API.scope.remote(plugin, connectionId, {
- groupId,
- pageToken: currentPageToken,
- });
+ let newItems: McsItem<T.ResItem>[] = [];
+ let nextPageToken = '';
+ let errorId: ID | null;
- const newItems = (res.children ?? []).map((it) => ({
- ...it,
- title: it.name,
- }));
+ try {
+ const res = await API.scope.remote(plugin, connectionId, {
+ groupId,
+ pageToken: currentPageToken,
+ });
+
+ newItems = (res.children ?? []).map((it) => ({
+ ...it,
+ title: it.name,
+ }));
- if (res.nextPageToken) {
+ nextPageToken = res.nextPageToken;
+ } catch (err: any) {
+ errorId = groupId;
+ message.error(err.response.data.message);
+ }
+
+ if (nextPageToken) {
setMiller((m) => ({
...m,
items: [...m.items, ...newItems],
expandedIds: [...m.expandedIds, groupId ?? 'root'],
nextTokenMap: {
...m.nextTokenMap,
- [`${groupId ? groupId : 'root'}`]: res.nextPageToken,
+ [`${groupId ? groupId : 'root'}`]: nextPageToken,
},
}));
if (loadAll) {
- await getItems({ groupId, currentPageToken: res.nextPageToken, loadAll
});
+ await getItems({ groupId, currentPageToken: nextPageToken, loadAll });
}
} else {
setMiller((m) => ({
@@ -119,6 +136,7 @@ export const SearchLocal = ({ plugin, connectionId, config,
disabledScope, selec
items: [...m.items, ...newItems],
expandedIds: [...m.expandedIds, groupId ?? 'root'],
loadedIds: [...m.loadedIds, groupId ?? 'root'],
+ errorId,
}));
const groupItems = newItems.filter((it) => it.type === 'group');
@@ -172,59 +190,52 @@ export const SearchLocal = ({ plugin, connectionId,
config, disabledScope, selec
};
return (
- <S.Wrapper>
- <FormItem label={config.title} required>
- <MultiSelector
+ <Form layout="vertical">
+ <Form.Item label={config.title} required>
+ <Select
+ style={{ width: '100%' }}
disabled
- items={selectedScope}
- getKey={(it) => it.id}
- getName={(it) => it.fullName ?? it.name}
- selectedItems={selectedScope}
+ suffixIcon={null}
+ mode="tags"
+ value={selectedIds}
+ options={selectedOptions}
/>
- </FormItem>
- <FormItem>
+ </Form.Item>
+ <Form.Item>
{(status === 'loading' || status === 'cancel') && (
<S.JobLoad>
<Loading style={{ marginRight: 8 }} size={20} />
Loading: <span className="count">{miller.items.length}</span>
scopes found
- <Button
- style={{ marginLeft: 8 }}
- loading={status === 'cancel'}
- small
- text="Cancel"
- onClick={handleCancelLoadAllScopes}
- />
+ <Button style={{ marginLeft: 8 }} loading={status === 'cancel'}
onClick={handleCancelLoadAllScopes}>
+ Cancel
+ </Button>
</S.JobLoad>
)}
{status === 'loaded' && (
<S.JobLoad>
- <Icon icon="endorsed" style={{ color: '#4DB764' }} />
+ <CheckCircleFilled style={{ color: '#4DB764' }} rev={undefined} />
<span className="count">{miller.items.length}</span> scopes found
</S.JobLoad>
)}
{status === 'init' && (
<S.JobLoad>
- <Button
- disabled={!miller.items.length}
- intent={Intent.PRIMARY}
- text="Load all scopes to search by keywords"
- onClick={() => setOpen(true)}
- />
+ <Button type="primary" disabled={!miller.items.length} onClick={()
=> setOpen(true)}>
+ Load all scopes to search by keywords
+ </Button>
</S.JobLoad>
)}
- </FormItem>
- <FormItem>
- {status === 'loaded' && (
- <InputGroup leftIcon="search" value={query} onChange={(e) =>
setQuery(e.target.value)} />
- )}
+ </Form.Item>
+ <Form.Item>
+ {status === 'loaded' && <Input prefix="search" value={query}
onChange={(e) => setQuery(e.target.value)} />}
<MillerColumnsSelect
items={scopes}
columnCount={search ? 1 : config.millerColumn?.columnCount ?? 1}
columnHeight={300}
getCanExpand={(it) => it.type === 'group'}
getHasMore={(id) => !miller.loadedIds.includes(id ?? 'root')}
+ getHasError={(id) => id === miller.errorId}
onExpand={(id: McsID) => getItems({ groupId: id })}
onScroll={(id: McsID | null) =>
getItems({ groupId: id, currentPageToken: miller.nextTokenMap[id
?? 'root'] })
@@ -236,15 +247,16 @@ export const SearchLocal = ({ plugin, connectionId,
config, disabledScope, selec
)
}
renderLoading={() => <Loading size={20} style={{ padding: '4px 12px'
}} />}
+ renderError={() => <span style={{ color: 'red' }}>Something
Error</span>}
disabledIds={(disabledScope ?? []).map((it) => it.id)}
selectedIds={selectedScope.map((it) => it.id)}
onSelectItemIds={(selectedIds: ID[]) =>
onChange(miller.items.filter((it) => selectedIds.includes(it.id)))}
expandedIds={miller.expandedIds}
/>
- </FormItem>
- <Modal open={open} okText="Load" onCancel={() => setOpen(false)}
onOk={handleLoadAllScopes}>
+ </Form.Item>
+ <Modal open={open} centered onOk={handleLoadAllScopes} onCancel={() =>
setOpen(false)}>
<Message content={`This operation may take a long time, as it iterates
through all the ${config.title}.`} />
</Modal>
- </S.Wrapper>
+ </Form>
);
};
diff --git
a/config-ui/src/plugins/components/data-scope-remote/search-remote.tsx
b/config-ui/src/plugins/components/data-scope-remote/search-remote.tsx
index a543abafd..399d64182 100644
--- a/config-ui/src/plugins/components/data-scope-remote/search-remote.tsx
+++ b/config-ui/src/plugins/components/data-scope-remote/search-remote.tsx
@@ -16,15 +16,16 @@
*
*/
-import { useEffect, useMemo, useState } from 'react';
-import { InputGroup } from '@blueprintjs/core';
+import { useState, useEffect, useMemo } from 'react';
+import { SearchOutlined } from '@ant-design/icons';
+import { Form, Select, Input, message } from 'antd';
import type { McsID, McsItem, McsColumn } from 'miller-columns-select';
import MillerColumnsSelect from 'miller-columns-select';
import { useDebounce } from 'ahooks';
import { uniqBy } from 'lodash';
import API from '@/api';
-import { FormItem, MultiSelector, Loading } from '@/components';
+import { Loading } from '@/components';
import { IPluginConfig } from '@/types';
import * as T from './types';
@@ -43,6 +44,7 @@ export const SearchRemote = ({ plugin, connectionId, config,
disabledScope, sele
const [miller, setMiller] = useState<{
items: McsItem<T.ResItem>[];
loadedIds: ID[];
+ errorId?: ID | null;
nextTokenMap: Record<ID, string>;
}>({
items: [],
@@ -64,26 +66,42 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
const searchDebounce = useDebounce(search.query, { wait: 500 });
+ const [selectedIds, selectedOptions] = useMemo(
+ () => [selectedScope.map((sc) => sc.id), selectedScope.map((sc) => ({
label: sc.fullName, value: sc.id }))],
+ [selectedScope],
+ );
+
const allItems = useMemo(() => uniqBy([...miller.items, ...search.items],
'id'), [miller.items, search.items]);
const getItems = async (groupId: ID | null, currentPageToken?: string) => {
- const res = await API.scope.remote(plugin, connectionId, {
- groupId,
- pageToken: currentPageToken,
- });
+ let newItems: McsItem<T.ResItem>[] = [];
+ let nextPageToken = '';
+ let errorId: ID | null;
+
+ try {
+ const res = await API.scope.remote(plugin, connectionId, {
+ groupId,
+ pageToken: currentPageToken,
+ });
+
+ newItems = (res.children ?? []).map((it) => ({
+ ...it,
+ title: it.name,
+ }));
- const newItems = (res.children ?? []).map((it) => ({
- ...it,
- title: it.name,
- }));
+ nextPageToken = res.nextPageToken;
+ } catch (err: any) {
+ errorId = groupId;
+ message.error(err.response.data.message);
+ }
- if (res.nextPageToken) {
+ if (nextPageToken && newItems.length) {
setMiller((m) => ({
...m,
items: [...m.items, ...newItems],
nextTokenMap: {
...m.nextTokenMap,
- [`${groupId ? groupId : 'root'}`]: res.nextPageToken,
+ [`${groupId ? groupId : 'root'}`]: nextPageToken,
},
}));
} else {
@@ -91,6 +109,7 @@ export const SearchRemote = ({ plugin, connectionId, config,
disabledScope, sele
...m,
items: [...m.items, ...newItems],
loadedIds: [...m.loadedIds, groupId ?? 'root'],
+ errorId,
}));
}
};
@@ -105,7 +124,7 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
const res = await API.scope.searchRemote(plugin, connectionId, {
search: searchDebounce,
page: search.page,
- pageSize: 50,
+ pageSize: 20,
});
const items = (res.children ?? []).map((it) => ({
@@ -125,20 +144,21 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
}, [searchDebounce, search.page]);
return (
- <S.Wrapper>
- <FormItem label={config.title} required>
- <MultiSelector
+ <Form layout="vertical">
+ <Form.Item label={config.title} required>
+ <Select
+ style={{ width: '100%' }}
disabled
- items={selectedScope}
- getKey={(it) => it.id}
- getName={(it) => it.fullName ?? it.name}
- selectedItems={selectedScope}
+ suffixIcon={null}
+ mode="tags"
+ value={selectedIds}
+ options={selectedOptions}
/>
- </FormItem>
- <FormItem>
- <InputGroup
- leftIcon="search"
- placeholder={config.searchPlaceholder}
+ </Form.Item>
+ <Form.Item>
+ <Input
+ prefix={<SearchOutlined rev={undefined} />}
+ placeholder={config.searchPlaceholder ?? 'Search'}
value={search.query}
onChange={(e) => setSearch({ ...search, query: e.target.value })}
/>
@@ -149,6 +169,7 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
columnHeight={300}
getCanExpand={(it) => it.type === 'group'}
getHasMore={(id) => !miller.loadedIds.includes(id ?? 'root')}
+ getHasError={(id) => id === miller.errorId}
onExpand={(id: McsID) => getItems(id, miller.nextTokenMap[id])}
onScroll={(id: McsID | null) => getItems(id,
miller.nextTokenMap[id ?? 'root'])}
renderTitle={(column: McsColumn) =>
@@ -158,6 +179,7 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
)
}
renderLoading={() => <Loading size={20} style={{ padding: '4px
12px' }} />}
+ renderError={() => <span style={{ color: 'red' }}>Something
Error</span>}
disabledIds={(disabledScope ?? []).map((it) => it.id)}
selectedIds={selectedScope.map((it) => it.id)}
onSelectItemIds={(selectedIds: ID[]) =>
onChange(allItems.filter((it) => selectedIds.includes(it.id)))}
@@ -176,7 +198,7 @@ export const SearchRemote = ({ plugin, connectionId,
config, disabledScope, sele
onSelectItemIds={(selectedIds: ID[]) =>
onChange(allItems.filter((it) => selectedIds.includes(it.id)))}
/>
)}
- </FormItem>
- </S.Wrapper>
+ </Form.Item>
+ </Form>
);
};