Skip to content

Commit

Permalink
✨ feat: ProFlow基础版本,才用BloodNode组件完成血缘图展示
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangchu committed Sep 15, 2023
1 parent cc4ea9b commit d60fb21
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 146 deletions.
135 changes: 41 additions & 94 deletions src/BloodNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
import { NODE_DANGER, NODE_SELECT, NODE_WARNING, NodeSelect } from '@/ProFlow/constants';
import { ConfigProvider } from 'antd';
import { createStyles } from 'antd-style';
import { CSSProperties, ReactNode, memo, useRef } from 'react';

const useStyles = createStyles(({ css }) => ({
nodeWrap: css`
width: 320px;
height: 85px;
display: flex;
z-index: 10 !important;
position: absolute;
border-radius: 12px;
padding: 16px 12px;
box-sizing: border-box;
border: 3px solid white;
flex: 1;
background-color: white;
.img {
width: 48px;
height: 48px;
}
.content {
width: 230px;
margin-left: 13px;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
.title {
width: 100%;
display: flex;
flex: 1;
span {
font-size: 16px;
color: rgba(0, 0, 0, 85%);
line-height: 22px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.dangerLogo {
width: 28px;
height: 16px;
background: #ffeef1;
border-radius: 7px;
margin-left: 8px;
margin-top: 3px;
img {
width: 8px;
height: 9px;
}
}
}
.des {
font-size: 14px;
color: rgba(0, 0, 0, 45%);
line-height: 20px;
white-space: nowrap;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
}
`,
}));
import { useStyles } from './styles';

interface BloodNodeProps {
logo: string;
Expand All @@ -80,6 +11,20 @@ interface BloodNodeProps {
showIcon?: boolean;
icon?: string;
className?: string;
selectType?: NodeSelect;
}

function getClsFromSelectType(select: NodeSelect) {
switch (select) {
case NodeSelect.SELECT:
return NODE_SELECT;
case NodeSelect.DANGER:
return NODE_DANGER;
case NodeSelect.WARNING:
return NODE_WARNING;
default:
return 'nodeDefault';
}
}

export interface BloodNodePreviewProps extends BloodNodeProps {
Expand All @@ -97,34 +42,36 @@ export interface BloodNodePreviewProps extends BloodNodeProps {
onClick?: () => void;
}

const Preview = memo<Partial<BloodNodePreviewProps>>(({ title, logo, description, className }) => {
const { styles, cx } = useStyles();
const cardRef = useRef<HTMLDivElement>(null);

return (
<ConfigProvider
// 不这样做会导致 select 的下拉菜单被遮挡,并且不会正常放大缩小
getPopupContainer={() => {
return cardRef.current || document.body;
}}
>
{/* <Card ref={cardRef} title={title} className={} style={style}>
const Preview = memo<Partial<BloodNodePreviewProps>>(
({ title, logo, description, className, selectType = NodeSelect.SELECT }) => {
const { styles, cx } = useStyles();
const cardRef = useRef<HTMLDivElement>(null);

return (
<ConfigProvider
// 不这样做会导致 select 的下拉菜单被遮挡,并且不会正常放大缩小
getPopupContainer={() => {
return cardRef.current || document.body;
}}
>
{/* <Card ref={cardRef} title={title} className={} style={style}>
{children}
</Card> */}
<div className={cx(styles.nodeWrap, className)}>
<img className={'img'} src={logo} alt="" />
<div className={'content'}>
<div className={'title'}>
<span>{title}</span>
{/* {mainDanger && <DangerLogo />}
<div className={cx(styles.nodeWrap, styles[getClsFromSelectType(selectType)], className)}>
<img className={'img'} src={logo} alt="" />
<div className={'content'}>
<div className={'title'}>
<span>{title}</span>
{/* {mainDanger && <DangerLogo />}
{qualityScore && <ApiScore score={parseFloat(qualityScore)} />} */}
</div>
<div className={'des'}>{description}</div>
</div>
<div className={'des'}>{description}</div>
</div>
</div>
</ConfigProvider>
);
});
</ConfigProvider>
);
},
);

const Default = memo<BloodNodeProps>(({ ...props }) => {
return <Preview {...props} />;
Expand Down
84 changes: 84 additions & 0 deletions src/BloodNode/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ css, cx, prefixCls }) => ({
nodeWrap: cx(
`${prefixCls}-xx`,
css`
width: 320px;
height: 85px;
display: flex;
z-index: 10 !important;
position: absolute;
border-radius: 12px;
padding: 16px 12px;
box-sizing: border-box;
border: 3px solid white;
flex: 1;
background-color: white;
.img {
width: 48px;
height: 48px;
}
.content {
width: 230px;
margin-left: 13px;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
.title {
width: 100%;
display: flex;
flex: 1;
span {
font-size: 16px;
color: rgba(0, 0, 0, 85%);
line-height: 22px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
.dangerLogo {
width: 28px;
height: 16px;
background: #ffeef1;
border-radius: 7px;
margin-left: 8px;
margin-top: 3px;
img {
width: 8px;
height: 9px;
}
}
}
.des {
font-size: 14px;
color: rgba(0, 0, 0, 45%);
line-height: 20px;
white-space: nowrap;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
}
`,
),
nodeSelected: css`
box-shadow: 0 0 0 3px #1677ff, 0 1px 4px 1px rgba(0, 0, 0, 8%) !important;
`,
nodeDanger: css`
box-shadow: 0 0 0 3px #f7636e, 0 1px 4px 1px rgba(0, 0, 0, 8%);
`,
nodeWarning: css`
box-shadow: 0 0 0 3px #ef9d3b, 0 1px 4px 1px rgba(0, 0, 0, 8%) !important;
`,
nodeDefault: css``,
}));
18 changes: 17 additions & 1 deletion src/ProFlow/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Node } from 'reactflow';

export enum NodeSelect {
SELECT = 'SELECT',
DANGER = 'DANGER',
WARNING = 'WARNING',
DEFAULT = 'DEFAULT',
}
export interface ProFlowNode {
id: string;
type: string;
select?: NodeSelect;
data: ProFlowNodeData;
}

Expand Down Expand Up @@ -35,7 +42,7 @@ export interface NodeMapItem {
dangerCount?: number;
type?: 'input' | 'output' | 'default';
className?: string;
selected?: boolean;
select?: NodeSelect;
isGroup?: boolean;
childrenNeedFold?: boolean;
haveAlert?: boolean;
Expand All @@ -51,3 +58,12 @@ export interface NodeMapItem {
}

export type NodeMapping = Record<string, NodeMapItem>;

export const NODE_SELECT = 'nodeSelected';
export const NODE_DANGER = 'nodeDanger';
export const NODE_WARNING = 'nodeWarning';
export const INIT_NODE = 'initialNode';
export const NODE_WRAP = 'nodeWrap';
export const EDGE_SELECT = 'edgeSelected';
export const EDGE_DANGER = 'edgeDanger';
export const EDGE_WARNING = 'edgeWarning';
5 changes: 4 additions & 1 deletion src/ProFlow/demos/ProFlowDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createStyles } from 'antd-style';
import { memo } from 'react';
import ProFlow from '..';
import { ProFlowNode } from '../constants';
import { NodeSelect, ProFlowNode } from '../constants';

const useStyles = createStyles(({ css }) => ({
container: css`
Expand All @@ -14,6 +14,7 @@ const nodes: ProFlowNode[] = [
{
id: 'a1',
type: 'BloodNode',
select: NodeSelect.SELECT,
data: {
title: 'XXX数据源',
describe: 'cksadjfnf',
Expand All @@ -23,6 +24,7 @@ const nodes: ProFlowNode[] = [
{
id: 'a2',
type: 'BloodNode',
select: NodeSelect.DANGER,
data: {
title: 'XXX_API',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*kgyiRKi04eUAAAAAAAAAAAAADvuvAQ/original',
Expand All @@ -32,6 +34,7 @@ const nodes: ProFlowNode[] = [
{
id: 'a3',
type: 'BloodNode',
select: NodeSelect.WARNING,
data: {
title: 'XXXX产品',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*ezaYT4wYRBwAAAAAAAAAAAAADvuvAQ/original',
Expand Down
Loading

0 comments on commit d60fb21

Please sign in to comment.