Skip to content

Commit c5b5d73

Browse files
committed
Trying high-level tasks
1 parent 9047d80 commit c5b5d73

17 files changed

+205
-18
lines changed

create-network/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@cytoscape-web/create-network",
3+
"description": "An example app to create a network in workspace",
4+
"version": "1.0.0",
5+
"private": "true",
6+
"type": "module",
7+
"scripts": {
8+
"build": "webpack --config webpack.config.js",
9+
"dev": "webpack serve --open /remoteEntry.js --mode development"
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ComponentType, CyApp } from '@cytoscape-web/types'
2+
3+
export const CreateNetworkApp: CyApp = {
4+
id: 'createNetwork',
5+
name: 'Create Network App',
6+
url: '',
7+
components: [
8+
{
9+
id: 'SimplePanel',
10+
type: ComponentType.Panel,
11+
},
12+
],
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useEffect } from 'react'
2+
3+
// Dynamic import from the host app
4+
import { useWorkspaceStore } from 'cyweb/WorkspaceStore'
5+
6+
import { IdType } from '@cytoscape-web/types'
7+
8+
const CreateNetworkPanel = (): JSX.Element => {
9+
const workspace = useWorkspaceStore((state: any) => state.workspace)
10+
11+
const ids: IdType[] = workspace.networkIds
12+
13+
useEffect(() => {
14+
console.log('Create Network Panel initialized', workspace)
15+
}, [])
16+
17+
return (
18+
<div>
19+
<h4>Create a network</h4>
20+
<p>Current Network ID: {workspace.currentNetworkId}</p>
21+
<h5>Networks:</h5>
22+
</div>
23+
)
24+
}
25+
26+
export default CreateNetworkPanel

create-network/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CreateNetworkApp as default } from './CreateNetworkApp'

create-network/src/remotes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'cyweb/WorkspaceStore'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const useNetworkBuilder = (): any => {
2+
3+
}

create-network/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"include": ["src/**/*"],
3+
"compilerOptions": {
4+
"allowSyntheticDefaultImports": true,
5+
"outDir": "./dist/",
6+
"noImplicitAny": true,
7+
"module": "ESNext",
8+
"target": "ESNext",
9+
"jsx": "react-jsx",
10+
"allowJs": true,
11+
"esModuleInterop": true,
12+
"moduleResolution": "node",
13+
"sourceMap": true,
14+
"strictNullChecks": true,
15+
"resolveJsonModule": true,
16+
"baseUrl": "."
17+
}
18+
}

create-network/webpack.config.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import path from 'path'
2+
import url from 'url'
3+
import webpack from 'webpack'
4+
import packageJson from '../package.json' assert { type: 'json' }
5+
6+
const { ModuleFederationPlugin } = webpack.container
7+
8+
// Extract some properties from the package.json file to avoid duplication
9+
const deps = packageJson.peerDependencies
10+
11+
const __filename = url.fileURLToPath(import.meta.url)
12+
const __dirname = path.dirname(__filename)
13+
14+
const DEV_SERVER_PORT = 4001
15+
16+
export default {
17+
mode: 'development',
18+
devtool: false,
19+
target: 'web',
20+
optimization: {
21+
minimize: false,
22+
runtimeChunk: false,
23+
splitChunks: {
24+
chunks: 'async',
25+
name: false,
26+
},
27+
},
28+
entry: './src/index.ts',
29+
output: {
30+
clean: true,
31+
path: path.resolve(__dirname, 'dist'),
32+
publicPath: 'auto',
33+
},
34+
resolve: {
35+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
36+
},
37+
plugins: [
38+
new ModuleFederationPlugin({
39+
name: 'createNetwork',
40+
filename: 'remoteEntry.js',
41+
remotes: {
42+
// Import some data providers from the host application
43+
cyweb: 'cyweb@http://localhost:5500/remoteEntry.js',
44+
},
45+
exposes: {
46+
'./CreateNetworkApp': './src/CreateNetworkApp',
47+
'./CreateNetworkPanel': './src/components/CreateNetworkPanel.tsx',
48+
},
49+
shared: {
50+
react: { singleton: true, requiredVersion: deps.react },
51+
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
52+
},
53+
}),
54+
],
55+
module: {
56+
rules: [
57+
{
58+
test: /\.tsx?$/,
59+
use: 'ts-loader',
60+
exclude: /node_modules/,
61+
},
62+
],
63+
},
64+
devServer: {
65+
hot: true,
66+
port: DEV_SERVER_PORT,
67+
headers: {
68+
'Access-Control-Allow-Origin': '*', // allow access from any origin
69+
},
70+
},
71+
}

hello-world/src/HelloApp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentType, CyApp } from '@cytoscape-web/types'
33
export const HelloApp: CyApp = {
44
id: 'hello',
55
name: 'Hello Cy World App',
6+
description: 'Hello-world example app for Cytoscape Web',
67
url: '',
78
components: [
89
{
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
import { Network, NetworkWithView } from '@cytoscape-web/types'
12
import { MenuItem } from '@mui/material'
3+
import {
4+
createEmptyNetwork,
5+
useCreateNetworkWithView,
6+
} from 'cyweb/CreateNetwork'
27

38
const MenuExample = (): JSX.Element => {
9+
// Get the function to create a network with a view
10+
const createNetworkWithView = useCreateNetworkWithView()
11+
412
const handleClick = (): void => {
5-
alert('Hello from the external app!')
13+
// const newNet: Network = createEmptyNetwork()
14+
const newNetwork: NetworkWithView = createNetworkWithView({
15+
name: 'Empty Network1',
16+
})
17+
console.log('Empty network created', newNetwork)
18+
const network: Network = newNetwork.network
19+
alert(`Network Created: ${network.id}`)
620
}
721

8-
return <MenuItem onClick={handleClick}>Example Menu from App</MenuItem>
22+
return <MenuItem onClick={handleClick}>Create empty network</MenuItem>
923
}
1024

1125
export default MenuExample

hello-world/src/remotes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ declare module 'cyweb/useDataStore'
22
declare module 'cyweb/WorkspaceStore'
33
declare module 'cyweb/NetworkStore'
44
declare module 'cyweb/Network'
5+
declare module 'cyweb/CreateNetwork'

hello-world/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export default {
5454
shared: {
5555
react: { singleton: true, requiredVersion: deps.react },
5656
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
57+
'@mui/material': {
58+
singleton: true,
59+
requiredVersion: deps['@mui/material'],
60+
},
5761
},
5862
}),
5963
],

package-lock.json

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simple-menu/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export default {
5050
shared: {
5151
react: { singleton: true, requiredVersion: deps.react },
5252
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
53+
'@mui/material': {
54+
singleton: true,
55+
requiredVersion: deps['@mui/material'],
56+
},
5357
},
5458
}),
5559
],

simple-panel/src/components/SimplePanel.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ import { useEffect } from 'react'
22

33
// Dynamic import from the host app
44
import { useWorkspaceStore } from 'cyweb/WorkspaceStore'
5+
import { useNetworkStore } from 'cyweb/NetworkStore'
56

6-
import { Network, IdType } from '@cytoscape-web/types'
7+
import { IdType, Network, Workspace, Node, Edge } from '@cytoscape-web/types'
78

89
interface HelloPanelProps {
910
message: string
1011
}
1112

1213
const SimplePanel = ({ message }: HelloPanelProps): JSX.Element => {
13-
const workspace = useWorkspaceStore((state: any) => state.workspace)
14+
const workspace: Workspace = useWorkspaceStore(
15+
(state: any) => state.workspace,
16+
)
17+
18+
const { currentNetworkId } = workspace
19+
20+
const networks: Map<IdType, Network> = useNetworkStore(
21+
(state: any) => state.networks,
22+
)
23+
const curNetwork: Network | undefined = networks.get(currentNetworkId)
24+
const nodes: Node[] = curNetwork?.nodes ?? []
25+
const edges: Edge[] = curNetwork?.edges ?? []
1426

1527
const ids: IdType[] = workspace.networkIds
1628

@@ -22,12 +34,8 @@ const SimplePanel = ({ message }: HelloPanelProps): JSX.Element => {
2234
<div>
2335
<h4>Simple panel example {message}</h4>
2436
<p>Current Network ID: {workspace.currentNetworkId}</p>
25-
<h5>Networks:</h5>
26-
<ul>
27-
{ids.map((id: IdType) => (
28-
<li key={id}>{id}</li>
29-
))}
30-
</ul>
37+
<h5>Num. nodes: {nodes.length}</h5>
38+
<h5>Num. edges: {edges.length}</h5>
3139
</div>
3240
)
3341
}

simple-panel/src/remotes.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
declare module 'cyweb/useDataStore'
21
declare module 'cyweb/WorkspaceStore'
32
declare module 'cyweb/NetworkStore'
4-
declare module 'cyweb/Network'

simple-panel/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export default {
4949
shared: {
5050
react: { singleton: true, requiredVersion: deps.react },
5151
'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
52+
'@mui/material': {
53+
singleton: true,
54+
requiredVersion: deps['@mui/material'],
55+
},
5256
},
5357
}),
5458
],

0 commit comments

Comments
 (0)