Skip to content

Commit

Permalink
♻️ refactor: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 17, 2021
1 parent 1e3cacf commit 4e28bd6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/mindflow/src/components/CollapseIcon/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
position: absolute;
top: 10px;
right: -10px;
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
Expand Down
1 change: 1 addition & 0 deletions packages/mindflow/src/components/EvidencePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const EvidencePanel: FC<EvidencePanelProps> = ({ edge }) => {

const isEmpty = !data || data.references.length === 0;

console.log(data);
return (
<div className="mind-edge-container">
<Popover content={'123'}>
Expand Down
11 changes: 3 additions & 8 deletions packages/mindflow/src/components/MindNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FC } from 'react';
import React, { useEffect, useRef } from 'react';
import React, { memo, useRef } from 'react';
import {
CaretUpOutlined,
CaretDownOutlined,
Expand All @@ -22,7 +22,7 @@ interface BaseNodeProps {
node?: ReactShape;
}

const MindNode: FC<BaseNodeProps> = ({ node }) => {
const MindNode: FC<BaseNodeProps> = memo(({ node }) => {
const data = node.getData<NodeData>();
const ref = useRef();

Expand All @@ -41,11 +41,6 @@ const MindNode: FC<BaseNodeProps> = ({ node }) => {

const backgroundColor = rgba2hex(baseColor.alpha(0.1).rgba());

useEffect(() => {
// 展开的节点在前面显示
node.setZIndex(unfolded ? 1000 : 0);
}, [unfolded]);

return (
<div
ref={ref}
Expand Down Expand Up @@ -121,6 +116,6 @@ const MindNode: FC<BaseNodeProps> = ({ node }) => {
)}
</div>
);
};
});

export default MindNode;
11 changes: 8 additions & 3 deletions packages/mindflow/src/components/MindNode/useFolded.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { useMindflowService } from '../../store/useMindflowContext';
import type { ReactShape } from '@antv/x6-react-shape';
import { NodeData } from '@arvinxu/mindflow';
import type { NodeData } from '../../types';

export const useFolded = (node: ReactShape) => {
const { isNodeUnfolded, toggleNodeUnfold } = useMindflowService();
Expand All @@ -13,8 +13,13 @@ export const useFolded = (node: ReactShape) => {

useEffect(() => {
// 展开的节点在前面显示
node.setZIndex(unfolded ? 1000 : 0);
}, [unfolded]);

if (unfolded) {
node.setZIndex(100);
} else {
node.removeZIndex();
}
}, [unfolded, node]);

return { unfolded, cantFold, toggleNodeUnfold };
};
1 change: 1 addition & 0 deletions packages/mindflow/src/definition/graphOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const graphOpts = (container, minimapCtn): Partial<Options.Manual> => ({
background: {
color: '#fafafa',
},
grid: 1,
interacting: {
// nodeMovable: false,
edgeLabelMovable: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/mindflow/src/utils/dataMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mindFlowColors } from '../themes/nodeColor';
import type { GraphData, MindflowNodeData, NodeData } from '../types';
import type { GraphData, MindflowData, NodeData } from '../types';
import type { BaseNode } from '../types';

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ export const mapTypeToColor = (type: string) => {
* @param collapseList
*/
export const getUncollapsedNode = (
data: GraphData<MindflowNodeData>,
data: MindflowData,
collapseList: string[],
): BaseNode<NodeData>[] => {
const targetList = collapseList
Expand All @@ -74,7 +74,7 @@ export const getUncollapsedNode = (
* @param collapseList
*/
export const preprocessData = (
data: GraphData<MindflowNodeData>,
data: MindflowData,
collapseList: string[],
): GraphData<NodeData> => {
const displayNodes = getUncollapsedNode(data, collapseList);
Expand Down

0 comments on commit 4e28bd6

Please sign in to comment.