
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A React component library for Data Center Infrastructure Management (DCIM) visualization
一个基于 React 和 React Flow 的数据中心基础设施管理 (DCIM) 组件库,用于可视化和管理机房设备、机架和网络连接。
npm install react-dcim
# 或
pnpm add react-dcim
# 或
yarn add react-dcim
React DCIM 需要以下 peer dependencies:
npm install react react-dom reactflow
import React from 'react';
import DCIMCanvas, { ItemType } from 'react-dcim';
const App = () => {
// 定义初始节点
const initialNodes = [
{
id: 'zone-1',
type: ItemType.ZONE,
position: { x: 100, y: 100 },
data: { label: 'Primary Zone', width: 800, height: 600 },
},
{
id: 'rack-1',
type: ItemType.RACK,
position: { x: 200, y: 200 },
data: { label: 'Rack A1', totalU: 42 },
parentId: 'zone-1',
},
{
id: 'server-1',
type: ItemType.SERVER,
position: { x: 20, y: 20 },
data: {
label: 'Web Server 01',
uHeight: 2,
status: 'active',
model: 'Dell R740',
ip: '192.168.1.10'
},
parentId: 'rack-1',
},
];
// 定义初始连接
const initialEdges = [
{
id: 'edge-1',
source: 'server-1',
target: 'server-2',
type: 'portConnection',
data: { sourcePort: 'eth0', targetPort: 'eth0' },
},
];
return (
<div style={{ width: '100vw', height: '100vh' }}>
<DCIMCanvas
initialNodes={initialNodes}
initialEdges={initialEdges}
onNodeClick={(event, node) => console.log('Node clicked:', node)}
onEdgeClick={(event, edge) => console.log('Edge clicked:', edge)}
theme="dark"
showMiniMap={true}
showControls={true}
showBackground={true}
/>
</div>
);
};
export default App;
主要的 DCIM 画布组件,用于渲染数据中心布局。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| initialNodes | Node[] | [] | 初始节点数据 |
| initialEdges | Edge[] | [] | 初始连接数据 |
| onNodeClick | (event: MouseEvent, node: Node) => void | - | 节点点击事件处理函数 |
| onEdgeClick | (event: MouseEvent, edge: Edge) => void | - | 连接点击事件处理函数 |
| onNodeDragStop | (event: MouseEvent, node: Node) => void | - | 节点拖拽结束事件处理函数 |
| theme | 'light' | 'dark' | 'light' | 主题设置 |
| showMiniMap | boolean | true | 是否显示小地图 |
| showControls | boolean | true | 是否显示控制按钮 |
| showBackground | boolean | true | 是否显示背景网格 |
枚举类型,定义了支持的节点类型:
ZONE - 数据中心区域RACK - 机架SERVER - 服务器NETWORK - 网络设备STORAGE - 存储设备PDU - 电源分配单元UPS - 不间断电源interface NodeData {
label: string; // 节点标签
description?: string; // 节点描述
status?: string; // 节点状态
model?: string; // 设备型号
ip?: string; // IP 地址
assetId?: string; // 资产 ID
// 其他设备特定属性...
}
interface ZoneData extends NodeData {
width: number; // 区域宽度
height: number; // 区域高度
}
interface RackData extends NodeData {
totalU: number; // 机架总 U 数
}
interface ServerData extends NodeData {
uHeight: number; // 设备高度 (U)
type: ItemType; // 设备类型
}
用于表示设备间网络连接的边组件。
interface EdgeData {
sourcePort: string; // 源端口
targetPort: string; // 目标端口
color?: string; // 连接线颜色
}
提供 AI 功能的服务类,用于数据中心分析和布局生成。
import { analyzeDataCenter, generateLayout } from 'react-dcim';
// 分析数据中心
const analysis = await analyzeDataCenter(nodes, edges, apiKey);
// 生成布局
const layout = await generateLayout(description, apiKey);
您可以通过注册自定义节点来扩展 DCIM 组件:
import { ReactFlow, NodeTypes } from 'reactflow';
const customNodeTypes: NodeTypes = {
customServer: CustomServerNode,
};
<DCIMCanvas
nodeTypes={customNodeTypes}
initialNodes={nodes}
initialEdges={edges}
/>
您可以通过 CSS 变量自定义主题:
:root {
--dcim-bg-color: #f8f9fa;
--dcim-text-color: #333;
--dcim-border-color: #ddd;
--dcim-node-bg: #fff;
--dcim-selected-color: #007bff;
}
[data-theme="dark"] {
--dcim-bg-color: #1a1a1a;
--dcim-text-color: #f8f9fa;
--dcim-border-color: #444;
--dcim-node-bg: #2d2d2d;
--dcim-selected-color: #0d6efd;
}
查看 example 目录中的完整示例项目,了解如何使用 React DCIM 组件库。
# 克隆仓库
git clone https://github.com/your-username/react-dcim.git
cd react-dcim
# 安装依赖
pnpm install
# 启动开发服务器
pnpm dev
# 构建库
pnpm build:lib
# 运行示例
pnpm example
pnpm dev - 启动开发服务器pnpm build - 构建应用程序pnpm build:lib - 构建库pnpm example - 运行示例项目pnpm lint - 运行 ESLintpnpm type-check - 运行类型检查欢迎贡献代码!请提交 Pull Request 或创建 Issue。
MIT License
FAQs
A React component library for Data Center Infrastructure Management (DCIM) visualization
We found that react-dcim demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.