@talend/react-components
Version:
Set of react components.
118 lines (117 loc) • 4.64 kB
JavaScript
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 { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import Skeleton from '../../../Skeleton';
import { LengthBadge } from '../../Badges';
import { TreeBranchIcon } from '../../Icons';
import theme from '../RecordsViewer.module.scss';
/**
* Used with the lazy loading to allow the render of the skeleton.
* @param {object} value
*/
import { get } from "lodash";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export function isLoaded(value) {
return get(value, 'loaded') !== false;
}
export class RecordsViewerBranch extends Component {
constructor(...args) {
super(...args);
_defineProperty(this, "onKeyDown", event => {
switch (event.key) {
case 'Enter':
case ' ':
case 'Space':
event.preventDefault(); // prevent scroll with space
event.stopPropagation();
this.onClickRecordsBranch(event);
break;
default:
break;
}
});
_defineProperty(this, "onClickRecordsBranch", event => {
this.props.onToggle(event, {
jsonpath: this.props.jsonpath,
opened: this.props.opened,
value: this.props.value
}, this.props.index);
});
}
render() {
const {
className,
dataKey,
nodeHighlighted,
opened,
level,
type,
value
} = this.props;
if (!isLoaded(value)) {
return /*#__PURE__*/_jsx("div", {
className: classNames(theme['tc-records-viewer-skeleton'], 'tc-records-viewer-skeleton', className),
children: /*#__PURE__*/_jsx(Skeleton, {})
});
}
return /*#__PURE__*/_jsxs("div", {
className: classNames(theme['tc-records-viewer-branch'], 'tc-records-viewer-branch', className),
children: [/*#__PURE__*/_jsxs("span", {
className: classNames(theme['tc-records-viewer-branch-content'], 'tc-records-viewer-branch-content', {
[theme['tc-records-viewer-branch-highlighted']]: nodeHighlighted,
'tc-records-viewer-branch-highlighted': nodeHighlighted
}),
onKeyDown: this.onKeyDown,
"data-testid": "records-branch",
onClick: this.onClickRecordsBranch,
tabIndex: "0",
role: "button",
children: [/*#__PURE__*/_jsx(TreeBranchIcon, {
dataKey: dataKey,
getIcon: this.props.getIcon,
index: this.props.index,
jsonpath: this.props.jsonpath,
onToggle: this.props.onToggle,
opened: opened,
useCustomIcon: type === 'object',
value: value
}), /*#__PURE__*/_jsx("span", {
className: classNames(theme['tc-records-viewer-branch-text'], 'tc-records-viewer-branch-text'),
children: this.props.getObjectBranchDatakey(dataKey, value)
}, "datakey"), level !== 0 && /*#__PURE__*/_jsx(LengthBadge, {
lengthValue: this.props.getChildsCount(value)
}), this.props.renderBranchAdditionalValue && this.props.renderBranchAdditionalValue({
value,
opened
})]
}), opened && this.props.recursive({
type,
value: this.props.getChilds(value, get(value, 'schema', this.props.sample.schema), type)
})]
});
}
}
_defineProperty(RecordsViewerBranch, "propTypes", {
className: PropTypes.string,
dataKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
getChilds: PropTypes.func,
getChildsCount: PropTypes.func,
getIcon: PropTypes.func,
getObjectBranchDatakey: PropTypes.func.isRequired,
index: PropTypes.number,
jsonpath: PropTypes.string,
level: PropTypes.number.isRequired,
nodeHighlighted: PropTypes.bool,
onToggle: PropTypes.func.isRequired,
opened: PropTypes.bool,
recursive: PropTypes.func,
renderBranchAdditionalValue: PropTypes.func,
sample: PropTypes.object,
type: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
value: PropTypes.object
});
export default RecordsViewerBranch;
//# sourceMappingURL=RecordsViewerBranch.component.js.map