UNPKG

hrw-certificate-editor

Version:

Design Editor Tools with React.js + ant.design + fabric.js

89 lines 4.27 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const React = __importStar(require("react")); const PropTypes = __importStar(require("prop-types")); const antd_1 = require("antd"); const i18next_1 = __importDefault(require("i18next")); const constants_1 = require("../constant/constants"); const flex_1 = require("../../../components/flex"); const common_1 = require("../../../components/common"); const Icon_1 = __importDefault(require("../../../components/icon/Icon")); class NodeDescriptor extends React.Component { constructor() { super(...arguments); this.state = { loading: false, }; this.handlers = { onTrigger: async () => { const { selectedItem, workflow } = this.props; this.setState({ loading: true, }); try { this.setState({ loading: false, }); antd_1.message.success(i18next_1.default.t('workflow.virtual-button-execute-success', { name: selectedItem.name })); } catch (error) { this.setState({ loading: false, }); console.error(`[ERROR] ${this.constructor.name} triggerVirtualButton()`, error); antd_1.message.error(`${i18next_1.default.t('workflow.virtual-button-execute-failed', { name: selectedItem.name })}, ${error.message}`); } }, }; } shouldComponentUpdate(nextProps, nextState) { if (nextProps.selectedItem.id !== this.props.selectedItem.id) { return true; } else if (nextState.loading !== this.state.loading) { return true; } return false; } render() { const { selectedItem, workflow } = this.props; const { loading } = this.state; const { onTrigger } = this.handlers; const virtualButton = selectedItem.type === 'VirtualButtonNode' ? (React.createElement(flex_1.Flex, { justifyContent: "center", alignItems: "center", flex: "1", style: { marginTop: 24 } }, React.createElement(common_1.CommonButton, { icon: "play", onClick: onTrigger, loading: loading, disabled: !workflow.enabled || loading }, i18next_1.default.t('action.execute')))) : null; return (React.createElement(flex_1.Flex, { flexDirection: "column", style: { margin: '8px 16px' } }, React.createElement("h2", { style: { color: constants_1.NODE_COLORS[selectedItem.descriptor.type].fill } }, React.createElement(Icon_1.default, { name: selectedItem.descriptor.icon.length ? selectedItem.descriptor.icon : 'image', style: { marginRight: 8 } }), React.createElement("span", null, selectedItem.descriptor.name)), React.createElement("div", null, selectedItem.descriptor.description), virtualButton)); } } NodeDescriptor.propTypes = { selectedItem: PropTypes.object, workflow: PropTypes.object, }; exports.default = NodeDescriptor; //# sourceMappingURL=NodeDescriptor.js.map