UNPKG

plot-plan-designer

Version:

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

74 lines (73 loc) 3.57 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { message } from 'antd'; import i18n from 'i18next'; import Icon from '../../icon/Icon'; import CommonButton from '../../common/CommonButton'; import { Flex } from '../../flex'; import { NODE_COLORS } from '../constant/constants'; class NodeDescriptor extends Component { constructor() { super(...arguments); this.state = { loading: false, }; this.handlers = { onTrigger: () => __awaiter(this, void 0, void 0, function* () { const { selectedItem } = this.props; this.setState({ loading: true, }); try { this.setState({ loading: false, }); message.success(i18n.t('workflow.virtual-button-execute-success', { name: selectedItem.name })); } catch (error) { this.setState({ loading: false, }); console.error(`[ERROR] ${this.constructor.name} triggerVirtualButton()`, error); message.error(`${i18n.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, { justifyContent: "center", alignItems: "center", flex: "1", style: { marginTop: 24 } }, React.createElement(CommonButton, { icon: "play", onClick: onTrigger, loading: loading, disabled: !workflow.enabled || loading }, i18n.t('action.execute')))) : null; return (React.createElement(Flex, { flexDirection: "column", style: { margin: '8px 16px' } }, React.createElement("h2", { style: { color: NODE_COLORS[selectedItem.descriptor.type].fill } }, React.createElement(Icon, { 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, }; export default NodeDescriptor;