@netdata/netdata-ui
Version:
netdata UI kit
141 lines (140 loc) • 5.91 kB
JavaScript
;
exports.__esModule = true;
exports.supportedRowActions = exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _flex = _interopRequireDefault(require("../../templates/flex"));
var _action = _interopRequireDefault(require("../components/action"));
var _excluded = ["id", "handleAction", "isDisabled", "isVisible", "dataGa", "disabledTooltipText", "tooltipText"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
var supportedRowActions = exports.supportedRowActions = {
"delete": {
icon: "trashcan",
confirmation: true,
tooltipText: "Delete",
confirmationTitle: "Delete Row",
confirmationMessage: "You are about to delete a row, are you sure?",
confirmLabel: "Yes",
declineLabel: "No",
actionButtonDirection: "reverse",
disabledTooltipText: "Delete is disabled"
},
edit: {
icon: "pencilOutline",
confirmation: false,
tooltipText: "Edit"
},
replace: {
icon: "refresh",
confirmation: true,
tooltipText: "Replace",
confirmationTitle: "Replace Row",
confirmationMessage: "You are about to replace a row, are you sure you want to continue?",
confirmLabel: "Yes",
declineLabel: "No",
actionButtonDirection: "reverse"
},
info: {
icon: "information",
confirmation: false,
tooltipText: "Information"
},
toggleAlarm: {
icon: "alarm_off",
confirmation: false,
tooltipText: "Turn of Alarms"
},
userSettings: {
icon: "user",
confirmation: false,
tooltipText: "User Settings"
},
remove: {
icon: "removeNode",
confirmation: true,
actionButtonDirection: "reverse",
confirmLabel: "Yes",
declineLabel: "No"
},
"goto": {
icon: "nav_arrow_goto",
confirmation: false,
tooltipText: "Go to"
}
};
var MIN_ACTIONS_COLUMN_WIDTH = 70;
var _default = exports["default"] = function _default(rowActions, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
testPrefix = _ref.testPrefix,
tableMeta = _ref.tableMeta;
var availableRowActions = (0, _react.useMemo)(function () {
return Object.keys(rowActions).reduce(function (acc, key) {
var defaultAction = supportedRowActions[key] || supportedRowActions["delete"];
var currentAction = rowActions[key];
acc.push(_extends({
id: key
}, defaultAction, currentAction));
return acc;
}, []);
}, [rowActions]);
if (availableRowActions.length < 1) return null;
return (0, _react.useMemo)(function () {
return {
id: "actions",
enableResizing: false,
header: "Actions",
headerString: "Actions",
cell: function cell(_ref2) {
var row = _ref2.row,
table = _ref2.table;
return /*#__PURE__*/_react["default"].createElement(_flex["default"], {
"data-testid": "action-cell",
height: "100%",
gap: 2,
flex: false,
onClick: function onClick(e) {
return e.stopPropagation();
}
}, availableRowActions.map(function (_ref3) {
var id = _ref3.id,
_handleAction = _ref3.handleAction,
isDisabled = _ref3.isDisabled,
_ref3$isVisible = _ref3.isVisible,
isVisible = _ref3$isVisible === void 0 ? true : _ref3$isVisible,
dataGa = _ref3.dataGa,
disabledTooltipText = _ref3.disabledTooltipText,
tooltipText = _ref3.tooltipText,
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
return /*#__PURE__*/_react["default"].createElement(_action["default"], _extends({}, rest, {
disabled: typeof isDisabled === "function" ? isDisabled(row.original) : isDisabled,
visible: typeof isVisible === "function" ? isVisible(row.original) : isVisible,
dataGa: typeof dataGa === "function" ? dataGa(row.original) : dataGa,
disabledTooltipText: typeof disabledTooltipText === "function" ? disabledTooltipText(row.original) : disabledTooltipText,
tooltipText: typeof tooltipText === "function" ? tooltipText(row.original) : tooltipText,
key: id,
id: id,
handleAction: function handleAction() {
return _handleAction(row.original, table);
},
testPrefix: testPrefix,
currentRow: row
}));
}));
},
enableColumnFilter: false,
enableSorting: false,
enableReordering: false,
tableMeta: tableMeta,
size: Math.max(MIN_ACTIONS_COLUMN_WIDTH, availableRowActions.length * 35),
align: "end",
notFlex: true,
meta: {
cellStyles: {
justifyContent: "end"
}
}
};
}, [availableRowActions]);
};