@formant/ava-react
Version:
React components of AVA.
42 lines • 3.09 kB
JavaScript
import React from 'react';
import { uniq } from 'lodash';
import { Toolbar } from "../Toolbar";
import { ALGORITHM_NAME_MAP, ALGORITHM_NAME_MAP_ZH, INSIGHT_CARD_PREFIX_CLS } from "../constants";
import { Badge, Card, CardDescription, CardHeader, CardTitle, Highlight, HeaderContainer, TitleContainer, TooltipContainer, TooltipContent, TooltipIcon } from "./customStyled";
export var Title = function Title(_ref) {
var _patterns$map, _insightTypes$map$joi;
var title = _ref.title,
patterns = _ref.patterns,
measures = _ref.measures,
headerTools = _ref.headerTools,
visualizationOptions = _ref.visualizationOptions,
dimensions = _ref.dimensions,
period = _ref.period,
subspace = _ref.subspace;
var prefixCls = INSIGHT_CARD_PREFIX_CLS;
var insightTypes = uniq((_patterns$map = patterns === null || patterns === void 0 ? void 0 : patterns.map(function (pattern) {
return pattern.type;
})) !== null && _patterns$map !== void 0 ? _patterns$map : []);
var measureNames = uniq(measures === null || measures === void 0 ? void 0 : measures.map(function (measure) {
return measure.fieldName;
})).join(',');
var algorithmNameMap = (visualizationOptions === null || visualizationOptions === void 0 ? void 0 : visualizationOptions.lang) === 'zh-CN' ? ALGORITHM_NAME_MAP_ZH : ALGORITHM_NAME_MAP;
var capitalize = function capitalize(s) {
return s && String(s[0]).toUpperCase() + String(s).slice(1);
};
var analysisName = (_insightTypes$map$joi = insightTypes.map(function (algorithm) {
return capitalize(algorithmNameMap[algorithm]);
}).join(',')) !== null && _insightTypes$map$joi !== void 0 ? _insightTypes$map$joi : '';
var newTitle = /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(CardHeader, null, /*#__PURE__*/React.createElement(HeaderContainer, null, /*#__PURE__*/React.createElement(TitleContainer, null, /*#__PURE__*/React.createElement(CardTitle, null, title ? "".concat(title, "- ").concat(measureNames) : {
measureNames: measureNames
}, /*#__PURE__*/React.createElement(Badge, null, " ", analysisName)), /*#__PURE__*/React.createElement(CardDescription, null, subspace && subspace.length > 0 && subspace.map(function (_) {
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Highlight, null, " ", _.dimension, ": "), " ", /*#__PURE__*/React.createElement(Highlight, null, " ", _.value, " "));
}))), /*#__PURE__*/React.createElement(TooltipContainer, null, /*#__PURE__*/React.createElement(TooltipIcon, null), /*#__PURE__*/React.createElement(TooltipContent, null, /*#__PURE__*/React.createElement("p", null, "This chart displays that ", analysisName, " was detected."))))));
return /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-title")
}, newTitle, !!(headerTools !== null && headerTools !== void 0 && headerTools.length) && /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-title-tools")
}, /*#__PURE__*/React.createElement(Toolbar, {
tools: headerTools
})));
};