generated from ensaremirerol/nextjs-fastapi-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
236ce4e
commit 123b85c
Showing
19 changed files
with
419 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { OverlayToaster } from '@blueprintjs/core'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
const toast = OverlayToaster.create({ | ||
position: 'top', | ||
}); | ||
const toast = await OverlayToaster.createAsync( | ||
{ | ||
position: 'top', | ||
}, | ||
{ | ||
domRenderer: (toaster, containerElement) => | ||
createRoot(containerElement).render(toaster), | ||
}, | ||
); | ||
|
||
export default toast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,39 @@ | ||
export enum MappingNodeType { | ||
ENTITY = 'entity', | ||
LITERAL = 'literal', | ||
URIRef = 'uri_ref', | ||
} | ||
export type MappingNodeType = 'entity' | 'literal' | 'uri_ref'; | ||
|
||
export interface MappingNode { | ||
export type MappingNode = { | ||
id: string; | ||
type: MappingNodeType.ENTITY; | ||
type: 'entity'; | ||
label: string; | ||
uri_pattern: string; | ||
rdf_type: string[]; | ||
} | ||
}; | ||
|
||
export interface MappingLiteral { | ||
export type MappingLiteral = { | ||
id: string; | ||
type: MappingNodeType.LITERAL; | ||
type: 'literal'; | ||
label: string; | ||
value: string; | ||
literal_type: string; | ||
} | ||
}; | ||
|
||
export interface MappingURIRef { | ||
export type MappingURIRef = { | ||
id: string; | ||
type: MappingNodeType.URIRef; | ||
type: 'uri_ref'; | ||
uri_pattern: string; | ||
} | ||
}; | ||
|
||
export interface MappingEdge { | ||
export type MappingEdge = { | ||
id: string; | ||
source: string; | ||
target: string; | ||
predicate_uri: string; | ||
} | ||
}; | ||
|
||
export interface MappingGraph { | ||
export type MappingGraph = { | ||
uuid: string; | ||
name: string; | ||
description: string; | ||
source_id: string; | ||
nodes: (MappingNode | MappingLiteral | MappingURIRef)[]; | ||
edges: MappingEdge[]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
35 changes: 35 additions & 0 deletions
35
app/src/pages/mapping_page/components/MainPanel/components/EntityNode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Card, H3 } from '@blueprintjs/core'; | ||
import { Handle, NodeProps, NodeResizer, Position } from '@xyflow/react'; | ||
import { EntityNodeType } from '../types'; | ||
|
||
const EntityNode: React.FC<NodeProps<EntityNodeType>> = node => { | ||
return ( | ||
<> | ||
<NodeResizer | ||
color='blue' | ||
isVisible={node.selected} | ||
nodeId={node.id} | ||
minWidth={200} | ||
minHeight={100} | ||
/> | ||
<Handle type='source' position={Position.Top} id='top' /> | ||
<Handle type='target' position={Position.Bottom} id='bottom' /> | ||
<Card | ||
style={{ | ||
width: node.width, | ||
height: node.height, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<H3>{node.data.label}</H3> | ||
</Card> | ||
<Handle type='source' position={Position.Left} id='left' /> | ||
<Handle type='target' position={Position.Right} id='right' /> | ||
</> | ||
); | ||
}; | ||
|
||
export default EntityNode; |
100 changes: 96 additions & 4 deletions
100
app/src/pages/mapping_page/components/MainPanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,102 @@ | ||
const MainPanel = () => { | ||
import { Menu, MenuItem, showContextMenu } from '@blueprintjs/core'; | ||
|
||
import { | ||
addEdge, | ||
Background, | ||
Connection, | ||
Controls, | ||
NodeTypes, | ||
ReactFlow, | ||
useEdgesState, | ||
useNodesState, | ||
useReactFlow, | ||
} from '@xyflow/react'; | ||
|
||
import '@xyflow/react/dist/style.css'; | ||
import { useCallback } from 'react'; | ||
import { MappingGraph } from '../../../../lib/api/mapping_service/types'; | ||
import EntityNode from './components/EntityNode'; | ||
import { XYEdgeType, XYNodeTypes } from './types'; | ||
|
||
type MainPanelProps = { | ||
initialGraph: MappingGraph | null; | ||
}; | ||
const nodeTypes: NodeTypes = { | ||
entity: EntityNode, | ||
}; | ||
|
||
const MainPanel = ({ initialGraph }: MainPanelProps) => { | ||
const reactflow = useReactFlow(); | ||
|
||
const [nodes, setNodes, onNodesChange] = useNodesState<XYNodeTypes>([]); | ||
const [edges, setEdges, onEdgesChange] = useEdgesState<XYEdgeType>([]); | ||
|
||
const onConnect = useCallback( | ||
(params: Connection) => { | ||
setEdges(edges => addEdge(params, edges)); | ||
}, | ||
[setEdges], | ||
); | ||
|
||
const handleAddEntityNode = useCallback( | ||
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => { | ||
setNodes(nodes => [ | ||
...nodes, | ||
{ | ||
id: `node-${nodes.length}`, | ||
data: { | ||
id: `node-${nodes.length}`, | ||
label: 'New Entity', | ||
rdf_type: [''], | ||
uri_pattern: '', | ||
type: 'entity', | ||
}, | ||
width: 200, | ||
height: 100, | ||
position: reactflow.screenToFlowPosition({ | ||
x: e.clientX, | ||
y: e.clientY, | ||
}), | ||
type: 'entity', | ||
}, | ||
]); | ||
}, | ||
[setNodes, reactflow], | ||
); | ||
|
||
const openMenu = (e: React.MouseEvent) => { | ||
e.preventDefault(); | ||
showContextMenu({ | ||
content: ( | ||
<Menu> | ||
<MenuItem text='Create Node' onClick={handleAddEntityNode} /> | ||
<MenuItem text='Create URI Reference' /> | ||
<MenuItem text='Create Literal' /> | ||
</Menu> | ||
), | ||
targetOffset: { left: e.clientX, top: e.clientY }, | ||
isDarkTheme: true, | ||
}); | ||
}; | ||
|
||
return ( | ||
// disable default right click menu | ||
<div className='main-panel'> | ||
<h2>Main Panel</h2> | ||
<p>This area expands fully when the side panel is collapsed.</p> | ||
<ReactFlow | ||
nodes={nodes} | ||
edges={edges} | ||
nodeTypes={nodeTypes} | ||
onConnect={onConnect} | ||
onNodesChange={onNodesChange} | ||
onEdgesChange={onEdgesChange} | ||
colorMode='dark' | ||
onContextMenu={openMenu} | ||
> | ||
<Background bgColor='#1C2127' gap={16} size={1} /> | ||
<Controls /> | ||
</ReactFlow> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MainPanel; | ||
export default MainPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Edge, Node } from '@xyflow/react'; | ||
import { | ||
MappingEdge, | ||
MappingNode, | ||
} from '../../../../lib/api/mapping_service/types'; | ||
|
||
export type EntityNodeType = Node<MappingNode, 'entity'>; | ||
export type LiteralNodeType = Node<MappingNode, 'literal'>; | ||
export type URIRefNodeType = Node<MappingNode, 'uri_ref'>; | ||
|
||
export type XYNodeTypes = EntityNodeType | LiteralNodeType | URIRefNodeType; | ||
|
||
export type XYEdgeType = Edge<MappingEdge, 'edge'>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.