UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

49 lines 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertiesTable = exports.MAX_LENGTH_WIDE = exports.MAX_LENGTH_NARROW = exports.WIDE_VIEW_THRESHOLD = exports.ELLIPSIS = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ const react_1 = require("@neo4j-ndl/react"); const react_2 = require("react"); const clickable_urls_1 = require("./clickable-urls"); exports.ELLIPSIS = '\u2026'; exports.WIDE_VIEW_THRESHOLD = 900; exports.MAX_LENGTH_NARROW = 150; exports.MAX_LENGTH_WIDE = 300; const ExpandableValue = ({ value, width, type }) => { const [isExpanded, setIsExpanded] = (0, react_2.useState)(false); const maxLength = width > exports.WIDE_VIEW_THRESHOLD ? exports.MAX_LENGTH_WIDE : exports.MAX_LENGTH_NARROW; const handleExpandClick = () => { setIsExpanded(true); }; let valueShown = isExpanded ? value : value.slice(0, maxLength); const isValueTrimmed = valueShown.length !== value.length; valueShown += isValueTrimmed ? exports.ELLIPSIS : ''; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [type.startsWith('Array') && '[', (0, jsx_runtime_1.jsx)(clickable_urls_1.ClickableUrls, { text: valueShown }), isValueTrimmed && ((0, jsx_runtime_1.jsx)("button", { onClick: handleExpandClick, className: "ndl-properties-show-all-button", children: ' Show all' })), type.startsWith('Array') && ']'] })); }; const PropertiesTable = ({ properties, paneWidth, }) => { return ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-graph-visualization-properties-table", children: [(0, jsx_runtime_1.jsxs)("div", { className: "ndl-properties-header", children: [(0, jsx_runtime_1.jsx)(react_1.Typography, { variant: "body-small", className: "ndl-properties-header-key", children: "Key" }), (0, jsx_runtime_1.jsx)(react_1.Typography, { variant: "body-small", children: "Value" })] }), Object.entries(properties).map(([key, { stringified, type }]) => { return ((0, jsx_runtime_1.jsxs)("div", { className: "ndl-properties-row", children: [(0, jsx_runtime_1.jsx)(react_1.Typography, { variant: "body-small", className: "ndl-properties-key", children: key }), (0, jsx_runtime_1.jsx)("div", { className: "ndl-properties-value", children: (0, jsx_runtime_1.jsx)(ExpandableValue, { value: stringified, width: paneWidth, type: type }) }), (0, jsx_runtime_1.jsx)("div", { className: "ndl-properties-clipboard-button", children: (0, jsx_runtime_1.jsx)(react_1.ClipboardButton, { textToCopy: `${key}: ${stringified}`, size: "small", tooltipProps: { placement: 'left', type: 'simple' } }) })] }, key)); })] })); }; exports.PropertiesTable = PropertiesTable; //# sourceMappingURL=properties-table.js.map