@netdata/charts
Version:
Netdata frontend SDK and chart utilities
136 lines • 6.54 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { memo, useRef } from "react";
import styled, { keyframes } from "styled-components";
import { Box, Flex, TextMicro } from "@netdata/netdata-ui";
import { useLoadingColor, useAttributeValue, useColor } from "../provider";
import Details from "../details";
import GroupBox from "./groupBox";
import useGroupBox from "./useGroupBox";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var frames = keyframes(["from{opacity:0.2;}to{opacity:0.6;}"]);
var Skeleton = styled(Flex).attrs(function (props) {
return _objectSpread({
background: "borderSecondary",
flex: true,
height: 50
}, props);
}).withConfig({
displayName: "groupBoxes__Skeleton",
componentId: "sc-1m75n17-0"
})(["animation:", " 1.6s ease-in infinite;"], frames);
export var SkeletonIcon = function SkeletonIcon() {
var color = useLoadingColor();
return /*#__PURE__*/_jsx(Skeleton, {
background: color
});
};
var _GroupBoxWrapper = function GroupBoxWrapper(_ref) {
var uiName = _ref.uiName,
subTree = _ref.subTree,
data = _ref.data,
label = _ref.label,
groupedBy = _ref.groupedBy,
hasMore = _ref.hasMore;
var dimensions = Object.values(subTree);
var _groupedBy = _toArray(groupedBy),
first = _groupedBy[0],
rest = _groupedBy.slice(1);
var bg = useColor("themeBackground");
return /*#__PURE__*/_jsxs(Flex, {
"data-testid": "groupBoxWrapper",
column: true,
alignItems: "start",
gap: 1,
margin: [0, 3, 3, 0],
border: hasMore ? {
color: "borderSecondary",
side: "all"
} : false,
round: hasMore,
padding: hasMore ? [2] : [0],
position: "relative",
children: [/*#__PURE__*/_jsx(Box, _objectSpread(_objectSpread({}, hasMore && {
position: "absolute",
top: "-12px",
left: 1,
background: bg,
padding: [0, 1]
}), {}, {
children: /*#__PURE__*/_jsxs(TextMicro, {
strong: hasMore,
"data-testid": "groupBoxWrapper-title",
whiteSpace: "nowrap",
children: [label, data.length > 3 && /*#__PURE__*/_jsxs("span", {
children: ["(", dimensions.length, ")"]
})]
})
})), rest.length ? Object.keys(subTree).map(function (key) {
return /*#__PURE__*/_jsx(_GroupBoxWrapper, {
label: key,
subTree: subTree[key],
data: data,
uiName: uiName,
groupedBy: rest,
hasMore: rest.length > 1
}, key);
}) : /*#__PURE__*/_jsx(GroupBox, {
dimensions: dimensions,
groupLabel: label,
uiName: uiName,
groupKey: first
})]
});
};
var GroupBoxes = function GroupBoxes(_ref2) {
var uiName = _ref2.uiName;
var _useGroupBox = useGroupBox(uiName),
data = _useGroupBox.data,
tree = _useGroupBox.tree;
var ref = useRef();
var loaded = useAttributeValue("loaded");
var showingInfo = useAttributeValue("showingInfo");
var viewDimensions = useAttributeValue("viewDimensions");
var _ref3 = viewDimensions.grouped || [],
_ref4 = _toArray(_ref3),
first = _ref4[0],
rest = _ref4.slice(1);
if (!loaded) return /*#__PURE__*/_jsx(SkeletonIcon, {});
return /*#__PURE__*/_jsx(Flex, {
"data-testid": "groupBoxes",
flexWrap: true,
flex: true,
position: "relative",
height: {
min: "150px"
},
ref: ref,
children: showingInfo ? /*#__PURE__*/_jsx(Details, {}) : rest.length ? Object.keys(tree).map(function (key) {
return /*#__PURE__*/_jsx(_GroupBoxWrapper, {
label: key,
subTree: tree[key],
data: data,
uiName: uiName,
groupedBy: rest,
hasMore: rest.length > 1
}, key);
}) : /*#__PURE__*/_jsx(_GroupBoxWrapper, {
label: first,
subTree: tree,
data: data,
uiName: uiName,
groupedBy: rest
}, first)
});
};
export default /*#__PURE__*/memo(GroupBoxes);