UNPKG

@grafana/flamegraph

Version:

Grafana flamegraph visualization component

85 lines (80 loc) 3.25 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); var ui = require('@grafana/ui'); var types = require('../types.cjs'); "use strict"; const ActionsCell = react.memo(function ActionsCell2({ nodeId, label, itemIndexes, levelItem, hasChildren, depth, parentId, onFocus, onShowCallers, onSearch, focusedNodeId, callersNodeLabel, isSearchMatch, actionsCellClass, getExtraContextMenuButtons, data, viewMode, paneView, search }) { const isTheFocusedNode = nodeId === focusedNodeId || (focusedNodeId == null ? void 0 : focusedNodeId.startsWith("label:")) && focusedNodeId.substring(6) === label; const isTheCallersTarget = label === callersNodeLabel; const inCallersMode = callersNodeLabel !== void 0; const inFocusMode = focusedNodeId !== void 0; const isRootNode = depth === 0 && !parentId; const shouldShowFocusItem = hasChildren && !isTheFocusedNode && !(isRootNode && !inFocusMode); const shouldShowCallersItem = !isTheCallersTarget && !isRootNode; const shouldShowSearchItem = onSearch && !isSearchMatch; const extraButtons = react.useMemo(() => { if (!getExtraContextMenuButtons) { return []; } const clickedItemData = { label, item: levelItem, posX: 0, posY: 0 }; return getExtraContextMenuButtons(clickedItemData, data.data, { viewMode: viewMode != null ? viewMode : types.ViewMode.Single, paneView: paneView != null ? paneView : types.PaneView.CallTree, isDiff: data.isDiffFlamegraph(), search }); }, [getExtraContextMenuButtons, label, levelItem, data, viewMode, paneView, search]); const hasAnyAction = shouldShowFocusItem || shouldShowCallersItem || shouldShowSearchItem || extraButtons.length > 0; if (!hasAnyAction) { return /* @__PURE__ */ jsxRuntime.jsx("div", { className: actionsCellClass }); } const menu = /* @__PURE__ */ jsxRuntime.jsxs(ui.Menu, { children: [ shouldShowFocusItem && /* @__PURE__ */ jsxRuntime.jsx( ui.Menu.Item, { label: "Focus on callees", icon: "compress-arrows", onClick: () => { if (inCallersMode) { onFocus(label, true, itemIndexes); } else { onFocus(nodeId, false, itemIndexes); } } } ), shouldShowCallersItem && /* @__PURE__ */ jsxRuntime.jsx(ui.Menu.Item, { label: "Show callers", icon: "expand-arrows-alt", onClick: () => onShowCallers(label) }), shouldShowSearchItem && /* @__PURE__ */ jsxRuntime.jsx(ui.Menu.Item, { label: "Search", icon: "search", onClick: () => onSearch(label) }), extraButtons.map(({ label: btnLabel, icon, onClick }) => /* @__PURE__ */ jsxRuntime.jsx(ui.Menu.Item, { label: btnLabel, icon, onClick }, btnLabel)) ] }); return /* @__PURE__ */ jsxRuntime.jsx("div", { className: actionsCellClass, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Dropdown, { overlay: menu, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { name: "ellipsis-v", "aria-label": "Actions", size: "sm", onClick: (e) => e.stopPropagation() }) }) }); }); exports.ActionsCell = ActionsCell; //# sourceMappingURL=ActionsCell.cjs.map