forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
41 lines (37 loc) · 1.16 KB
/
Copy pathApp.tsx
File metadata and controls
41 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React, { useEffect, useRef } from 'react';
import Diagram, { CustomShape, Group, Toolbox } from 'devextreme-react/diagram';
import type { DiagramRef } from 'devextreme-react/diagram';
import service from './data.ts';
import 'whatwg-fetch';
const employees = service.getEmployees();
export default function App() {
const diagramRef = useRef<DiagramRef>(null);
useEffect(() => {
const diagram = diagramRef?.current?.instance();
fetch('../../../../data/diagram-employees.json')
.then((response) => response.json())
.then((json) => {
diagram?.import(JSON.stringify(json));
})
.catch(() => {
throw new Error('Data Loading Error');
});
}, []);
return (
<Diagram id="diagram" ref={diagramRef}>
{employees.map((employee, index) => (
<CustomShape
category="employees"
type={`employee${employee.ID}`}
baseType="rectangle"
defaultText={employee.Full_Name}
allowEditText={false}
key={index}
/>
))}
<Toolbox>
<Group category={'employees' as any} title="Employees" displayMode="texts" />
</Toolbox>
</Diagram>
);
}