UNPKG

@skbkontur/db-viewer-ui

Version:

Database Viewer with custom configuration

29 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectLink = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_ui_1 = require("@skbkontur/react-ui"); const react_1 = tslib_1.__importDefault(require("react")); const react_router_1 = require("react-router"); const RouteUtils_1 = require("../../Domain/Utils/RouteUtils"); const RouterLink_1 = require("../RouterLink/RouterLink"); const ObjectTypes_styles_1 = require("./ObjectTypes.styles"); function ObjectLinkInternal({ identifier, keywords, theme }) { if (keywords.length === 0) { return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: identifier }); } const [first, ...rest] = keywords; if (identifier.includes(first)) { const splitByKeyword = identifier.split(first); return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: splitByKeyword.map((item, i) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(ObjectLinkInternal, { identifier: item, keywords: rest, theme: theme }), i < splitByKeyword.length - 1 && (0, jsx_runtime_1.jsx)("span", { className: ObjectTypes_styles_1.jsStyles.mutedKeyword(theme), children: first })] }, item))) })); } return (0, jsx_runtime_1.jsx)(ObjectLinkInternal, { identifier: identifier, keywords: rest, theme: theme }); } const ObjectLink = ({ identifier, keywords }) => { const theme = react_1.default.useContext(react_ui_1.ThemeContext); const { pathname } = (0, react_router_1.useLocation)(); return ((0, jsx_runtime_1.jsx)("div", { "data-tid": "ObjectItem", children: (0, jsx_runtime_1.jsx)(RouterLink_1.RouterLink, { to: RouteUtils_1.RouteUtils.goTo(pathname, identifier), "data-tid": "ObjectLink", children: (0, jsx_runtime_1.jsx)(ObjectLinkInternal, { identifier: identifier, keywords: keywords, theme: theme }) }) })); }; exports.ObjectLink = ObjectLink; //# sourceMappingURL=ObjectLink.js.map