diff --git a/library/src/config/config.ts b/library/src/config/config.ts index e5c061d19..f5fb2e47a 100644 --- a/library/src/config/config.ts +++ b/library/src/config/config.ts @@ -6,6 +6,8 @@ export interface ConfigInterface { parserOptions?: any; publishLabel?: string; subscribeLabel?: string; + requestLabel?: string; + replyLabel?: string; } export interface ShowConfig { diff --git a/library/src/constants.ts b/library/src/constants.ts index e21c3bd4a..d846aa7c8 100644 --- a/library/src/constants.ts +++ b/library/src/constants.ts @@ -38,6 +38,10 @@ export const PUBLISH_TEXT = 'Publish'; export const PUBLISH_LABEL_DEFAULT_TEXT = 'PUB'; export const SUBSCRIBE_TEXT = 'Subscribe'; export const SUBSCRIBE_LABEL_DEFAULT_TEXT = 'SUB'; +export const REQUEST_TEXT = 'Request'; +export const REQUEST_LABEL_DEFAULT_TEXT = 'REQUEST'; +export const REPLIER_TEXT = 'Reply'; +export const REPLIER_LABEL_DEFAULT_TEXT = 'REPLY'; export const REQUIRED_TEXT = 'Required'; export const GENERATED_TEXT = 'Generated'; diff --git a/library/src/containers/Operations/Operation.tsx b/library/src/containers/Operations/Operation.tsx index 97e2682f9..5e383aca7 100644 --- a/library/src/containers/Operations/Operation.tsx +++ b/library/src/containers/Operations/Operation.tsx @@ -17,6 +17,8 @@ import { CommonHelpers, SchemaHelpers } from '../../helpers'; import { EXTERAL_DOCUMENTATION_TEXT, PUBLISH_LABEL_DEFAULT_TEXT, + REPLIER_LABEL_DEFAULT_TEXT, + REQUEST_LABEL_DEFAULT_TEXT, SUBSCRIBE_LABEL_DEFAULT_TEXT, } from '../../constants'; import { PayloadType } from '../../types'; @@ -168,6 +170,8 @@ export const Operation: React.FunctionComponent = props => { )} + + ); }; @@ -185,6 +189,18 @@ function getTypeInformation({ typeLabel: config.subscribeLabel ?? SUBSCRIBE_LABEL_DEFAULT_TEXT, }; } + if (type === PayloadType.REPLY) { + return { + borderColor: 'border-orange-600 text-orange-600', + typeLabel: config.publishLabel || REPLIER_LABEL_DEFAULT_TEXT, + }; + } + if (type === PayloadType.REQUEST) { + return { + borderColor: 'border-red-600 text-red-600', + typeLabel: config.publishLabel || REQUEST_LABEL_DEFAULT_TEXT, + }; + } // type === PayloadType.PUBLISH return { borderColor: 'border-blue-600 text-blue-500', @@ -256,3 +272,115 @@ export const OperationInfo: React.FunctionComponent = props => { ); }; + +export const OperationReplyInfo: React.FunctionComponent = props => { + const { type = PayloadType.PUBLISH, operation } = props; + if (type !== PayloadType.REPLY && type !== PayloadType.REQUEST) return <>; + const reply = operation.reply(); + if (reply === undefined) return <>; + const config = useConfig(); + const { typeLabel } = getTypeInformation({ type, config }); + const replyMessages = reply.messages(); + const explicitChannel = reply.channel(); + + return ( + <> +
+

+ + {typeLabel} information + +

+
+ + {explicitChannel && ( +
+
+ {typeLabel} should be done on channel + + {explicitChannel.id()} + +
+
+ )} + +
+ {replyMessages.length > 1 ? ( +
+

+ The reply should be with one of the following + messages: +

+
    + {replyMessages.all().map((msg, idx) => ( +
  • + +
  • + ))} +
+
+ ) : ( +
+

Reply should be with the following message:

+
+ +
+
+ )} +
+ + + + + ); +}; + +export const OperationReplyAddressInfo: React.FunctionComponent = ({ + type = PayloadType.PUBLISH, + operation, +}) => { + if (type !== PayloadType.REPLY && type !== PayloadType.REQUEST) return <>; + const reply = operation.reply(); + if (reply === undefined || !reply.hasAddress()) return <>; + const config = useConfig(); + const { typeLabel } = getTypeInformation({ type, config }); + const replyAddress = reply.address()!; + const replyAddressLocation = replyAddress.location(); + + return ( + <> +
+

+ + Operation {typeLabel} address information + +

+
+ + {replyAddress.hasDescription() && ( +
+ {replyAddress.description()} +
+ )} + + {replyAddressLocation && ( +
+
+ Operation {typeLabel} address location + + {replyAddressLocation} + +
+
+ )} + + + + ); +}; diff --git a/library/src/containers/Operations/Operations.tsx b/library/src/containers/Operations/Operations.tsx index d9f43ad27..25b973bcd 100644 --- a/library/src/containers/Operations/Operations.tsx +++ b/library/src/containers/Operations/Operations.tsx @@ -21,42 +21,82 @@ export const Operations: React.FunctionComponent = () => { const channel = operation.channels().all()[0]; const channelAddress = channel?.address() ?? ''; if (operation.isSend()) { - operationsList.push( -
  • - -
  • , - ); + if (operation.reply() !== undefined) { + operationsList.push( +
  • + +
  • , + ); + } else { + operationsList.push( +
  • + +
  • , + ); + } } if (operation.isReceive()) { - operationsList.push( -
  • - -
  • , - ); + if (operation.reply() !== undefined) { + operationsList.push( +
  • + +
  • , + ); + } else { + operationsList.push( +
  • + +
  • , + ); + } } }); diff --git a/library/src/types.ts b/library/src/types.ts index 08103e594..104653b30 100644 --- a/library/src/types.ts +++ b/library/src/types.ts @@ -32,6 +32,8 @@ export interface ParserReturn { export enum PayloadType { PUBLISH = 'publish', SUBSCRIBE = 'subscribe', + REQUEST = 'request', + REPLY = 'reply', } export interface MessageExample { diff --git a/web-component/package.json b/web-component/package.json index a5686422e..cab930079 100644 --- a/web-component/package.json +++ b/web-component/package.json @@ -51,8 +51,8 @@ "web-react-components": "^1.4.2" }, "devDependencies": { - "@types/react": "^16.9.2", "ts-loader": "9.4.4", + "@types/react": "^16.9.2", "webpack": "5.88.2", "webpack-cli": "5.1.4" },