Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
feat: add domain model for react nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed May 17, 2022
1 parent bf31693 commit 0922089
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 234 deletions.
1 change: 1 addition & 0 deletions examples/simple-react/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import SystemView from './SystemView';
import reportWebVitals from './reportWebVitals';

Expand Down
32 changes: 32 additions & 0 deletions library/src/components/nodes/Application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { ApplicationNodeData, InternalProps } from '../../types';

type ApplicationProps = ApplicationNodeData & InternalProps;

/**
* The Application component is a single instance of grouped outgoing and incoming channels.
*
* What you define as an instance can be application, grouped or single server less function, etc.
*/
export const Application: React.FunctionComponent<ApplicationProps> = props => {
const nodeData = {
...props,
};
delete nodeData.children;
delete nodeData.internal;
const applicationNodeData: ApplicationNodeData = nodeData;

props.internal?.addApplicationCallback(applicationNodeData);

const childrenWithProps = React.Children.map(props.children, child => {
if (React.isValidElement(child)) {
return React.cloneElement(child, {
forApplication: applicationNodeData.id,
internal: props.internal,
});
}
return child;
});

return <div key={applicationNodeData.id}>{childrenWithProps}</div>;
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import React from 'react';
import {
ApplicationLicenseData,
ApplicationNodeData,
ApplicationServerData,
InternalProps,
MessageData,
} from '../../../types';
} from '../../types';
import { Application } from './Application';
import { Outgoing } from './Outgoing';
import { AsyncAPIDocument } from '@asyncapi/parser';
import { Incoming } from './Incoming';
type InternalApplicationProps = {
internal?: {
addElementCallback?: any;
};
type AsyncapiApplicationProps = {
document: AsyncAPIDocument;
};

type ApplicationProps = ApplicationNodeData & InternalApplicationProps;
type ApplicationProps = AsyncapiApplicationProps & InternalProps;

/**
* The Application component is a single instance of grouped outgoing and incoming channels.
Expand Down Expand Up @@ -88,7 +85,7 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
});
return (
<Application
internal={{ addElementCallback: props.internal?.addElementCallback }}
internal={props.internal}
defaultContentType={props.document.defaultContentType() || 'Undefined'}
description={props.document.info().description() || 'No description'}
id={props.document.info().title()}
Expand Down
13 changes: 13 additions & 0 deletions library/src/components/nodes/Incoming.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { IncomingNodeData, InternalProps } from '../../types';

type IncomingProps = IncomingNodeData & InternalProps;
export const Incoming: React.FunctionComponent<IncomingProps> = props => {
const nodeData = { ...props };
delete nodeData.children;
delete nodeData.internal;
const incomingNodeData: IncomingNodeData = nodeData;

props.internal?.addIncomingCallback(incomingNodeData);
return null;
};
12 changes: 12 additions & 0 deletions library/src/components/nodes/Outgoing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { InternalProps, OutgoingNodeData } from '../../types';

type OutgoingProps = OutgoingNodeData & InternalProps;
export const Outgoing: React.FunctionComponent<OutgoingProps> = props => {
const nodeData = { ...props };
delete nodeData.children;
delete nodeData.internal;
const outgoingNodeData: OutgoingNodeData = nodeData;
props.internal?.addOutgoingCallback(outgoingNodeData);
return null;
};
61 changes: 0 additions & 61 deletions library/src/components/nodes/factories/Application.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions library/src/components/nodes/factories/Incoming.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions library/src/components/nodes/factories/Outgoing.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions library/src/components/nodes/factories/index.tsx

This file was deleted.

15 changes: 4 additions & 11 deletions library/src/components/nodes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import OutgoingNode from './OutgoingNode';
import IncomingNode from './IncomingNode';
import ApplicationNode from './ApplicationNode';

const nodeTypes = {
outgoingNode: OutgoingNode,
incomingNode: IncomingNode,
applicationNode: ApplicationNode,
};

export default nodeTypes;
export * from './AsyncAPIApplication';
export * from './Application';
export * from './Incoming';
export * from './Outgoing';
11 changes: 11 additions & 0 deletions library/src/components/react-flow-renderer-nodes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import OutgoingNode from './OutgoingNode';
import IncomingNode from './IncomingNode';
import ApplicationNode from './ApplicationNode';

const nodeTypes = {
outgoingNode: OutgoingNode,
incomingNode: IncomingNode,
applicationNode: ApplicationNode,
};

export default nodeTypes;
12 changes: 6 additions & 6 deletions library/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './visualiser/ApplicationView';
export * from './visualiser/SystemView';
export * from './components/nodes/factories/Application';
export * from './components/nodes/factories/Incoming';
export * from './components/nodes/factories/Outgoing';
export * from './components/nodes/factories/AsyncAPIApplication';
export * from './visualiser/react-flow-renderer/ApplicationView';
export * from './visualiser/react-flow-renderer/SystemView';
export * from './components/nodes/Application';
export * from './components/nodes/Incoming';
export * from './components/nodes/Outgoing';
export * from './components/nodes/AsyncAPIApplication';
export * from './components/layouts';
14 changes: 10 additions & 4 deletions library/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { FlowElement } from 'react-flow-renderer';
export const FLOW_TYPES = {
APPLICATION: 'application',
INCOMING: 'incomingNode',
OUTGOING: 'outgoingNode',

export type InternalProps = {
internal?: {
addApplicationCallback: (node: ApplicationNodeData) => void;
addIncomingCallback: (node: IncomingNodeData) => void;
addOutgoingCallback: (node: OutgoingNodeData) => void;
};
};

export interface ApplicationLicenseData {
name: string;
url: string;
Expand Down Expand Up @@ -37,6 +41,7 @@ export interface IncomingNodeData {
description?: string;
channel: string;
messages?: MessageData[];
forApplication?: string;
}
export interface IncomingNodeProps {
data: IncomingNodeData;
Expand All @@ -46,6 +51,7 @@ export interface OutgoingNodeData {
description?: string;
channel: string;
messages: MessageData[];
forApplication?: string;
}
export interface OutgoingNodeProps {
data: OutgoingNodeData;
Expand Down
87 changes: 0 additions & 87 deletions library/src/visualiser/SystemView.tsx

This file was deleted.

Loading

0 comments on commit 0922089

Please sign in to comment.