UNPKG

ze-react-component-library

Version:
254 lines (221 loc) 9.78 kB
import "antd/es/checkbox/style"; import _Checkbox from "antd/es/checkbox"; import "antd/es/button/style"; import _Button from "antd/es/button"; import "antd/es/tooltip/style"; import _Tooltip from "antd/es/tooltip"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var __assign = this && this.__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } } return t; }; return __assign.apply(this, arguments); }; var __spreadArray = this && this.__spreadArray || function (to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) { to[j] = from[i]; } return to; }; import { getNameProperty, getIDProperty } from "zeroetp-api-sdk"; import React from "react"; import { DataCell, ColCell, RowCell } from "@antv/s2"; import { ProfileOutlined, QuestionCircleOutlined } from "@ant-design/icons"; import Entity from "../components/Entity"; import { findProperty, getPropertyQueryKey } from "../util"; export var getObjectExpandProperties = function getObjectExpandProperties(name, data) { var _a, _b; var property = findProperty(__assign(__assign({}, data === null || data === void 0 ? void 0 : data.schema), { properties: data === null || data === void 0 ? void 0 : data.columnProperties }), name); if ((property === null || property === void 0 ? void 0 : property.type) === "object") { var showProperties = ((_b = (_a = property === null || property === void 0 ? void 0 : property.schema) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.filter(function (d) { return !d.is_name; })) || []; return showProperties; } return []; }; export var getDefaultS2ConfigFields = function getDefaultS2ConfigFields(result) { if (!result) return {}; var logicform = result.logicform; if (!logicform) throw new Error("需要有normed logicform"); if (!logicform.groupby) throw new Error("ZESheet仅支持groupby格式"); if (!logicform.preds) throw new Error("ZESheet仅支持groupby格式"); var columnProperties = result.columnProperties; var s2Config = { fields: { rows: columnProperties.slice(0, logicform.groupby.length).map(function (prop) { return prop.name; }), values: columnProperties.slice(logicform.groupby.length).map(function (prop) { return prop.name; }) } }; return s2Config; }; var renderTooltipItemList = function renderTooltipItemList(arr, isSummary, nameStyle) { return arr.map(function (d, i) { return /*#__PURE__*/React.createElement("div", { key: i, style: { display: "flex", justifyContent: "space-between" } }, /*#__PURE__*/React.createElement("span", { style: __assign(__assign({}, nameStyle), { margin: 0 }) }, d.name, isSummary ? "(总和)" : ""), /*#__PURE__*/React.createElement("span", null, d.value)); }); }; export var renderTooltipContent = function renderTooltipContent(cell, options, schema, logicform, setLogicform, entityTooltipCardProps, showGoToDetail, showRefDetail, percentageProps) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; var nameStyle = { color: "rgba(0,0,0,0.5)", margin: "0 0 8px 0" }; if (cell instanceof DataCell) { var _l = options.data, details = _l.details, _m = _l.headInfo, rows = _m.rows, cols = _m.cols, isTotals = options.options.isTotals; var title = rows.map(function (d) { return d.value; }).join("/"); var query_1 = __assign({}, logicform.query); var oldKeys_1 = Object.keys(query_1); __spreadArray(__spreadArray([], cols), rows).filter(function (f) { return f.name; }).forEach(function (d) { var queryKey = getPropertyQueryKey(d.name, schema); oldKeys_1.forEach(function (o) { if (o.includes(queryKey.split("_")[0])) { delete query_1[o]; } }); query_1[queryKey] = { $contains: d.value }; }); return /*#__PURE__*/React.createElement("div", { style: { padding: 12 } }, /*#__PURE__*/React.createElement("div", { style: __assign(__assign({}, nameStyle), { display: "flex", alignItems: "center", justifyContent: "space-between" }) }, title, showGoToDetail && setLogicform && !isTotals && /*#__PURE__*/React.createElement(_Tooltip, { title: "\u663E\u793A\u6570\u636E\u660E\u7EC6", placement: "left", getPopupContainer: function getPopupContainer() { return document.querySelector(".antv-s2-tooltip-container"); } }, /*#__PURE__*/React.createElement(_Button, { icon: /*#__PURE__*/React.createElement(ProfileOutlined, null), type: "text", onClick: function onClick(e) { e.stopPropagation(); e.preventDefault(); setLogicform({ schema: logicform.schema, query: query_1, sort: logicform.sort }); } }))), renderTooltipItemList(details)); } if (cell instanceof RowCell || cell instanceof ColCell || cell === null) { var meta = (cell === null || cell === void 0 ? void 0 : cell.getMeta()) || {}; var field = cell ? meta.field : undefined; if (field === "$$extra$$") { field = meta.value; } var property_1 = field ? findProperty(schema, field) : undefined; var selectedData = field ? (_f = (_e = (_d = (_c = (_b = (_a = options.data) === null || _a === void 0 ? void 0 : _a.summaries) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.selectedData) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e["@rawData"]) === null || _f === void 0 ? void 0 : _f[field] : undefined; if ((property_1 === null || property_1 === void 0 ? void 0 : property_1.primal_type) === "object" && !meta.isTotals && selectedData) { var entity = __assign({}, selectedData); var nameProp = getNameProperty(property_1.schema); var idProp = getIDProperty(property_1.schema); var entityProps = { property: property_1, entityNameProperty: nameProp, entityIDProperty: idProp, entityTooltipCardProps: entityTooltipCardProps, entity: entity, showRefDetail: showRefDetail }; return /*#__PURE__*/React.createElement(Entity, __assign({ key: entity._id, open: true }, entityProps)); } var title = cell === null ? null : cell.getActualText(); var summaries = options.data.summaries; if (!summaries) { return null; } var count = summaries.map(function (d) { return d.selectedData.length; }).reduce(function (p, c) { return p + c; }, 0); var pred_1 = (_g = logicform.preds) === null || _g === void 0 ? void 0 : _g.find(function (d) { return _typeof(d) === "object" && d.name === (property_1 === null || property_1 === void 0 ? void 0 : property_1.name); }); var showPercentageInGroup = false; if (pred_1) { showPercentageInGroup = pred_1.operator === "$percentage" && ((_h = logicform.groupby) === null || _h === void 0 ? void 0 : _h.length) === 2 && ((_j = logicform.preds) === null || _j === void 0 ? void 0 : _j.some(function (s) { return _typeof(s) === "object" && s.pred === pred_1.pred && s.operator === "$sum"; })); } return /*#__PURE__*/React.createElement("div", { style: { padding: 12, maxWidth: 200 } }, /*#__PURE__*/React.createElement("div", { style: __assign(__assign({}, nameStyle), { display: "flex", justifyContent: "space-between" }) }, /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", { style: { marginRight: 4 } }, title), (property_1 === null || property_1 === void 0 ? void 0 : property_1.description) && /*#__PURE__*/React.createElement(_Tooltip, { title: property_1 === null || property_1 === void 0 ? void 0 : property_1.description, placement: "right" }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, null))), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", { style: { color: "black", marginRight: 4 } }, count, " \u9879"), "\u5DF2\u9009\u62E9")), showPercentageInGroup && /*#__PURE__*/React.createElement(_Checkbox, { checked: (_k = percentageProps === null || percentageProps === void 0 ? void 0 : percentageProps.percentageConfig) === null || _k === void 0 ? void 0 : _k[property_1.name], onChange: function onChange(e) { var _a; e.stopPropagation(); e.preventDefault(); (_a = percentageProps === null || percentageProps === void 0 ? void 0 : percentageProps.setPercentageConfig) === null || _a === void 0 ? void 0 : _a.call(percentageProps, function (prev) { var _a; return __assign(__assign({}, prev), (_a = {}, _a[property_1.name] = e.target.checked, _a)); }); // 取消选中状态 document.body.click(); } }, "\u663E\u793A\u7EC4\u5185\u5360\u6BD4"), !(cell instanceof ColCell) && renderTooltipItemList(summaries, true, nameStyle)); } return null; };