Skip to content

Commit

Permalink
Fix bug 0329 (#650)
Browse files Browse the repository at this point in the history
* fix: filter nodePath

* fix: reset loadedKeys and expandedKeys when getCollectionItemTree

* fix: collection search deps search value

* fix: delete button style

* chore: update arex version

* chore: update arex-core version

---------

Co-authored-by: onePone <[email protected]>
  • Loading branch information
1pone and Xremn authored Mar 29, 2024
1 parent 506e9e2 commit 495f33a
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 107 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arex",
"private": true,
"version": "0.6.19",
"version": "0.6.20",
"description": "",
"homepage": "https://github.com/arextest/arex",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/arex-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arextest/arex-core",
"version": "0.4.5",
"version": "0.4.6",
"homepage": "https://github.com/arextest/arex",
"main": "dist/arex-core.js",
"module": "dist/arex-core.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/arex/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "arex",
"private": true,
"version": "0.6.19",
"version": "0.6.20",
"author": "arextest",
"main": "dist-electron/main",
"files": [
Expand Down
214 changes: 115 additions & 99 deletions packages/arex/src/components/CollectionSelect/CollectionSearchedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { useRequest } from 'ahooks';
import { Menu, MenuProps, theme } from 'antd';
import { DirectoryTreeProps } from 'antd/lib/tree';
import React from 'react';
import React, { forwardRef, useImperativeHandle } from 'react';

import { CollectionTreeType } from '@/components/CollectionSelect/index';
import { CollectionNodeType } from '@/constant';
Expand All @@ -24,108 +24,124 @@ export type CollectionSearchedListProps = {
onSelect?: DirectoryTreeProps<CollectionTreeType>['onSelect'];
};

const CollectionSearchedList = (props: CollectionSearchedListProps) => {
const { token } = theme.useToken();
export type CollectionSearchedListRef = {
search: () => void;
};

const CollectionSearchedList = forwardRef<CollectionSearchedListRef, CollectionSearchedListProps>(
(props, ref) => {
const { token } = theme.useToken();

const {
data,
loading,
run: search,
} = useRequest(
() =>
FileSystemService.searchCollectionItems({
workspaceId: props.workspaceId,
pageSize: 10,
keywords: props.searchValue?.keyword?.trim(),
labels: props.searchValue?.structuredValue?.map((item) => ({
key: item.category!,
operator: item.operator as OperatorType,
value: item.value!,
})),
}),
{
debounceWait: 300,
ready: !!props.searchValue,
refreshDeps: [props.searchValue],
},
);

const {
data,
loading,
run: search,
} = useRequest(
() =>
FileSystemService.searchCollectionItems({
workspaceId: props.workspaceId,
pageSize: 10,
keywords: props.searchValue?.keyword?.trim(),
labels: props.searchValue?.structuredValue?.map((item) => ({
key: item.category!,
operator: item.operator as OperatorType,
value: item.value!,
})),
useImperativeHandle(
ref,
() => ({
search,
}),
{
debounceWait: 300,
ready: !!props.searchValue,
},
);
const handleSelect: MenuProps['onClick'] = ({ key }) => {
const [nodeType, id] = key.split('-');
[],
);

let nodes: CollectionType[] | undefined = [];
if (parseInt(nodeType) === CollectionNodeType.folder) {
nodes = data?.folderNodes;
} else if (parseInt(nodeType) === CollectionNodeType.interface) {
nodes = data?.interfaceNodes;
} else if (parseInt(nodeType) === CollectionNodeType.case) {
nodes = data?.caseNodes;
}
const node = nodes?.find((item) => item.infoId === id);
const handleSelect: MenuProps['onClick'] = ({ key }) => {
const [nodeType, id] = key.split('-');

// @ts-ignore
node && props.onSelect?.([id], { node });
};
let nodes: CollectionType[] | undefined = [];
if (parseInt(nodeType) === CollectionNodeType.folder) {
nodes = data?.folderNodes;
} else if (parseInt(nodeType) === CollectionNodeType.interface) {
nodes = data?.interfaceNodes;
} else if (parseInt(nodeType) === CollectionNodeType.case) {
nodes = data?.caseNodes;
}
const node = nodes?.find((item) => item.infoId === id);

return (
<EmptyWrapper
loading={loading}
empty={!data?.folderNodes.length && !data?.interfaceNodes.length && !data?.caseNodes.length}
>
<Menu
items={([] as Required<MenuProps>['items'])
.concat(data?.folderNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.folderNodes.map((item) => ({
key: `${CollectionNodeType.folder}-${item.infoId}`,
label: (
<>
{<FolderOutlined style={{ marginRight: token.marginXS }} />}
{item.nodeName}
</>
),
})) || [],
)
.concat(data?.interfaceNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.interfaceNodes.map((item) => ({
key: `${CollectionNodeType.interface}-${item.infoId}`,
label: (
<>
{React.createElement(RequestMethodIcon[item.method || ''] || 'div')}
{item.nodeName}
</>
),
})) || [],
)
.concat(data?.caseNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.caseNodes.map((item) => ({
key: `${CollectionNodeType.case}-${item.infoId}`,
label: (
<>
{React.createElement(
RequestMethodIcon[
item.caseSourceType === CaseSourceType.AREX ? 'arex' : 'case'
] || 'div',
)}
{item.nodeName}
</>
),
})) || [],
)}
onClick={handleSelect}
css={css`
height: ${props.height ? `${props.height}px` : '100%'};
overflow-y: auto;
background-color: transparent;
border-inline-end: none !important;
.ant-menu-item {
height: 21px;
line-height: 21px;
}
`}
/>
</EmptyWrapper>
);
};
// @ts-ignore
node && props.onSelect?.([id], { node });
};

return (
<EmptyWrapper
loading={loading}
empty={!data?.folderNodes.length && !data?.interfaceNodes.length && !data?.caseNodes.length}
>
<Menu
items={([] as Required<MenuProps>['items'])
.concat(data?.folderNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.folderNodes.map((item) => ({
key: `${CollectionNodeType.folder}-${item.infoId}`,
label: (
<>
{<FolderOutlined style={{ marginRight: token.marginXS }} />}
{item.nodeName}
</>
),
})) || [],
)
.concat(data?.interfaceNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.interfaceNodes.map((item) => ({
key: `${CollectionNodeType.interface}-${item.infoId}`,
label: (
<>
{React.createElement(RequestMethodIcon[item.method || ''] || 'div')}
{item.nodeName}
</>
),
})) || [],
)
.concat(data?.caseNodes.length ? [{ type: 'divider' }] : [])
.concat(
data?.caseNodes.map((item) => ({
key: `${CollectionNodeType.case}-${item.infoId}`,
label: (
<>
{React.createElement(
RequestMethodIcon[
item.caseSourceType === CaseSourceType.AREX ? 'arex' : 'case'
] || 'div',
)}
{item.nodeName}
</>
),
})) || [],
)}
onClick={handleSelect}
css={css`
height: ${props.height ? `${props.height}px` : '100%'};
overflow-y: auto;
background-color: transparent;
border-inline-end: none !important;
.ant-menu-item {
height: 21px;
line-height: 21px;
}
`}
/>
</EmptyWrapper>
);
},
);

export default CollectionSearchedList;
9 changes: 7 additions & 2 deletions packages/arex/src/components/CollectionSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import type { DataNode, DirectoryTreeProps } from 'antd/lib/tree';
import { cloneDeep } from 'lodash';
import React, { FC, useCallback, useMemo, useRef, useState } from 'react';

import CollectionSearchedList from '@/components/CollectionSelect/CollectionSearchedList';
import CollectionSearchedList, {
CollectionSearchedListRef,
} from '@/components/CollectionSelect/CollectionSearchedList';
import { CollectionNodeType, EMAIL_KEY } from '@/constant';
import { FileSystemService, ReportService } from '@/services';
import { CollectionType } from '@/services/FileSystemService';
Expand Down Expand Up @@ -68,6 +70,7 @@ const CollectionSelect: FC<CollectionSelectProps> = (props) => {
} = useCollections();

const searchRef = useRef<StructuredFilterRef>(null);
const collectionSearchedListRef = useRef<CollectionSearchedListRef>(null);
const treeRef = useRef<{
scrollTo: (params: {
key: string | number;
Expand Down Expand Up @@ -292,8 +295,9 @@ const CollectionSelect: FC<CollectionSelectProps> = (props) => {
color: item.color,
}))}
options={options}
// placeholder={'Search for Name'}
placeholder={'Search for Name'}
onChange={handleChange}
onSearch={collectionSearchedListRef.current?.search}
onCancel={() => {
setSearchValue(undefined);
setShowSearchInput(false);
Expand All @@ -316,6 +320,7 @@ const CollectionSelect: FC<CollectionSelectProps> = (props) => {
<ConfigProvider theme={{ token: { motion: false } }}>
{searching ? (
<CollectionSearchedList
ref={collectionSearchedListRef}
height={props.height}
workspaceId={activeWorkspaceId}
searchValue={searchValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ const NodesTransform: FC<NodesTransformProps> = (props) => {
icon={<Icon name='Crosshair' />}
onClick={() => {
setTransformData((draft) => {
draft[openIndex].transformDetail!.nodePath = nodePath?.split('/') || [];
draft[openIndex].transformDetail!.nodePath =
nodePath?.split('/').filter(Boolean) || [];
});
setOpenIndex(-1);
setNodePath(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const EnvironmentRecordSetting: FC<EnvironmentRecordSettingProps> = (props) => {
{
key: 'environment',
extra: (
<SmallTextButton onClick={() => onDelete()} danger>
<Button type='text' size='small' onClick={() => onDelete()} danger>
{t('delete', { ns: 'common' })}
</SmallTextButton>
</Button>
),
label: (
<>
Expand Down
5 changes: 5 additions & 0 deletions packages/arex/src/store/useCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,18 @@ const useCollections = create(

if (merge) {
if (infoId) {
const path = getPathInFlatArray(infoId, treeToMap(generateRootNode(mergedData))).map(
(item) => item.id,
);
// mergedData = mergeTreeData(
// treeData,
// mergedData,
// getPathInFlatArray(infoId, treeToMap(generateRootNode(mergedData))).map(
// (item) => item.id,
// ),
// );
get().setLoadedKeys(path);
get().setExpandedKeys(path);
} else if (parentIds?.length) {
const parentId = parentIds[parentIds.length - 1];
mergedData = appendChildrenByParent(
Expand Down

0 comments on commit 495f33a

Please sign in to comment.