@asyncapi/react-component
Version:
A React component for AsyncAPI specification.
45 lines • 2.94 kB
JavaScript
import React from 'react';
import { Operation } from './Operation';
import { useConfig, useSpec } from '../../contexts';
import { CommonHelpers } from '../../helpers';
import { OPERATIONS_TEXT } from '../../constants';
import { PayloadType } from '../../types';
export var Operations = function () {
var operations = useSpec()
.operations()
.all();
var config = useConfig();
if (!Object.keys(operations).length) {
return null;
}
var operationsList = [];
operations.forEach(function (operation) {
var _a;
var channel = operation.channels().all()[0];
var channelAddress = (_a = channel === null || channel === void 0 ? void 0 : channel.address()) !== null && _a !== void 0 ? _a : '';
if (operation.isSend()) {
if (operation.reply() !== undefined) {
operationsList.push(React.createElement("li", { className: "mb-12", key: "req-".concat(operation.id()), id: CommonHelpers.getIdentifier("operation-".concat(PayloadType.REQUEST, "-").concat(operation.id()), config) },
React.createElement(Operation, { type: PayloadType.REQUEST, operation: operation, channelName: channelAddress, channel: channel })));
}
else {
operationsList.push(React.createElement("li", { className: "mb-12", key: "pub-".concat(operation.id()), id: CommonHelpers.getIdentifier("operation-".concat(PayloadType.SEND, "-").concat(operation.id()), config) },
React.createElement(Operation, { type: PayloadType.SEND, operation: operation, channelName: channelAddress, channel: channel })));
}
}
if (operation.isReceive()) {
if (operation.reply() !== undefined) {
operationsList.push(React.createElement("li", { className: "mb-12", key: "replier-".concat(operation.id()), id: CommonHelpers.getIdentifier("operation-".concat(PayloadType.REPLY, "-").concat(operation.id()), config) },
React.createElement(Operation, { type: PayloadType.REPLY, operation: operation, channelName: channelAddress, channel: channel })));
}
else {
operationsList.push(React.createElement("li", { className: "mb-12", key: "sub-".concat(operation.id()), id: CommonHelpers.getIdentifier("operation-".concat(PayloadType.RECEIVE, "-").concat(operation.id()), config) },
React.createElement(Operation, { type: PayloadType.RECEIVE, operation: operation, channelName: channelAddress, channel: channel })));
}
}
});
return (React.createElement("section", { id: "".concat(CommonHelpers.getIdentifier('operations', config)), className: "mt-16" },
React.createElement("h2", { className: "2xl:w-7/12 text-3xl font-light mb-4 px-8" }, OPERATIONS_TEXT),
React.createElement("ul", null, operationsList)));
};
//# sourceMappingURL=Operations.js.map