Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create RouteVisualization component for external applications usage. #1319

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"import": "./lib/esm/public-api.js",
"require": "./lib/cjs/public-api.js"
},
"./components": {
"import": "./lib/esm/components-api.js",
"require": "./lib/cjs/components-api.js"
},
"./models": {
"import": "./lib/esm/models-api.js",
"require": "./lib/cjs/models-api.js"
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './external/RouteVisualisation/RouteVisualization';
40 changes: 40 additions & 0 deletions packages/ui/src/external/RouteVisualisation/RouteVisualization.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useContext, useEffect, useLayoutEffect } from 'react';
import { EntitiesContext, EntitiesProvider, RuntimeProvider, VisibleFlowsProvider } from '../../providers';
import { Visualization } from '../../components/Visualization/Visualization';
import { EventNotifier } from '../../utils';

const Viz: React.FC<{ catalogUrl: string }> = ({ catalogUrl }) => {
const entitiesContext = useContext(EntitiesContext);
const visualEntities = entitiesContext?.visualEntities ?? [];
return (
<RuntimeProvider catalogUrl={catalogUrl}>
<VisibleFlowsProvider>
<Visualization className={'canvas-page'} entities={visualEntities} />
</VisibleFlowsProvider>
</RuntimeProvider>
);
};

export const RouteVisualization: React.FC<{ catalogUrl: string; code: string; codeChange: (code: string) => void }> = ({
lordrip marked this conversation as resolved.
Show resolved Hide resolved
catalogUrl,
code,
codeChange,
}) => {
const eventNotifier = EventNotifier.getInstance();
//
useLayoutEffect(() => {
return eventNotifier.subscribe('entities:updated', (code: string) => {
codeChange(code);
});
}, [eventNotifier, codeChange]);

useEffect(() => {
eventNotifier.next('code:updated', code);
}, [code, eventNotifier]);

return (
<EntitiesProvider>
<Viz catalogUrl={catalogUrl} />
</EntitiesProvider>
);
};
1 change: 1 addition & 0 deletions packages/ui/src/external/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './RouteVisualisation/RouteVisualization';
2 changes: 1 addition & 1 deletion packages/ui/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@testing-library/jest-dom",
]
},
"include": ["src/public-api.ts", "src/models-api.ts", "src/testing-api.ts", "src/global.d.ts"],
"include": ["src/public-api.ts", "src/models-api.ts", "src/testing-api.ts","src/components-api.ts", "src/global.d.ts"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this on the other tsconfig.json as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that implicitly inherited by "extends": "./tsconfig.esm.json", ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. Here's the extension

"exclude": ["src/**/*.test.tsx", "src/**/*.test.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
Loading