UNPKG

@redocly/theme

Version:

Shared UI components lib

102 lines 5.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CatalogEntityRelationsGraph = CatalogEntityRelationsGraph; const react_1 = __importStar(require("react")); const react_2 = require("@xyflow/react"); const styled_components_1 = __importDefault(require("styled-components")); const hooks_1 = require("../../../../core/hooks"); const hooks_2 = require("../../../../core/hooks"); const CatalogEntityRelationsNode_1 = require("../../../../components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsNode"); const CatalogEntityRelationsEdge_1 = require("../../../../components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsEdge"); const styles_1 = require("../../../../core/styles"); const CatalogPageDescription_1 = require("../../../../components/Catalog/CatalogPageDescription"); const catalog_1 = require("../../../../core/constants/catalog"); const commonReactFlowConfig = { fitView: true, proOptions: { hideAttribution: true, }, style: { border: 'var(--catalog-card-border-width) var(--catalog-card-border-style) var(--catalog-card-border-color)', borderRadius: 'var(--catalog-card-border-radius, 8px)', }, }; function CatalogEntityRelationsGraph({ entity, }) { var _a; const { useFetchCatalogEntitiesRelations } = (0, hooks_1.useThemeHooks)(); const { activeColorMode } = (0, hooks_1.useColorSwitcher)(); const combinedFilter = (0, react_1.useMemo)(() => { if (entity.version && entity.revision) { const versionFilter = `version:"${entity.version}"`; const revisionFilter = `revision:"${entity.revision}"`; return `${versionFilter} AND ${revisionFilter}`; } return undefined; }, [entity.version, entity.revision]); const { items: allRelations } = useFetchCatalogEntitiesRelations({ entityKey: entity.key, filter: combinedFilter, }); const { nodes, edges, onNodesChange, onEdgesChange, onConnect } = (0, hooks_2.useGraph)({ entity, relations: allRelations !== null && allRelations !== void 0 ? allRelations : [], }); const nodeTypes = (0, react_1.useMemo)(() => ({ [catalog_1.GraphCustomNodeType.CatalogEntity]: CatalogEntityRelationsNode_1.CatalogEntityRelationsNode }), []); const edgeTypes = (0, react_1.useMemo)(() => ({ [catalog_1.GraphCustomEdgeType.CatalogEdge]: CatalogEntityRelationsEdge_1.CatalogEntityRelationsEdge }), []); const reactFlowConfig = allRelations.length ? Object.assign({ key: entity.id, nodes, edges, nodeTypes, edgeTypes, onNodesChange, onEdgesChange, onConnect, colorMode: activeColorMode }, commonReactFlowConfig) : Object.assign({}, commonReactFlowConfig); return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(CatalogPageDescription_1.CatalogPageDescription, { title: entity.title, description: (_a = entity.summary) !== null && _a !== void 0 ? _a : '', tag: entity.key }), react_1.default.createElement(GraphWrapper, null, react_1.default.createElement(react_2.ReactFlow, Object.assign({}, reactFlowConfig), react_1.default.createElement(react_2.Background, { bgColor: "var(--catalog-card-bg-color)" }), react_1.default.createElement(react_2.Controls, null))))); } const GraphWrapper = styled_components_1.default.div ` height: 700px; width: 100%; ${styles_1.xyflow} `; //# sourceMappingURL=CatalogEntityRelationsGraph.js.map