@eventcatalog/core 2.5.3 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/components/MDX/Flow/Flow.astro +1 -1
- package/src/components/MDX/NodeGraph/NodeGraph.astro +11 -1
- package/src/components/MDX/NodeGraph/NodeGraph.tsx +30 -8
- package/src/components/MDX/SchemaViewer/SchemaViewer.astro +1 -1
- package/src/utils/url-builder-client.ts +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @eventcatalog/core
|
|
2
2
|
|
|
3
|
+
## 2.5.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b84b47: fix(core): moved node graphs to only load on client fixing the invalid hook call warning
|
|
8
|
+
|
|
9
|
+
## 2.5.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b6052d9: fix(core): added client side url builder
|
|
14
|
+
|
|
3
15
|
## 2.5.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -5,6 +5,8 @@ import { getNodesAndEdges as getNodesAndEdgesForEvent } from '@utils/events/node
|
|
|
5
5
|
import { getNodesAndEdges as getNodesAndEdgesForCommand } from '@utils/commands/node-graph';
|
|
6
6
|
import { getNodesAndEdges as getNodesAndEdgesForDomain } from '@utils/domains/node-graph';
|
|
7
7
|
import { getNodesAndEdges as getNodesAndEdgesForFlows } from '@utils/flows/node-graph';
|
|
8
|
+
import { buildUrl } from '@utils/url-builder';
|
|
9
|
+
import config from '@eventcatalog';
|
|
8
10
|
|
|
9
11
|
interface Props {
|
|
10
12
|
id: string;
|
|
@@ -77,6 +79,13 @@ if (collection === 'flows') {
|
|
|
77
79
|
nodes = eventNodes;
|
|
78
80
|
edges = eventEdges;
|
|
79
81
|
}
|
|
82
|
+
|
|
83
|
+
const getDocUrlForCollection = () => {
|
|
84
|
+
return buildUrl(`/docs/${collection}/${id}/${version}`);
|
|
85
|
+
};
|
|
86
|
+
const getVisualiserUrlForCollection = () => {
|
|
87
|
+
return buildUrl(`/visualiser/${collection}/${id}/${version}`);
|
|
88
|
+
};
|
|
80
89
|
---
|
|
81
90
|
|
|
82
91
|
<div>
|
|
@@ -88,7 +97,8 @@ if (collection === 'flows') {
|
|
|
88
97
|
hrefLabel={href.label}
|
|
89
98
|
href={href.url}
|
|
90
99
|
linkTo={linkTo}
|
|
91
|
-
client:
|
|
100
|
+
client:only="react"
|
|
101
|
+
urlHasTrailingSlash={config.trailingSlash}
|
|
92
102
|
/>
|
|
93
103
|
</div>
|
|
94
104
|
|
|
@@ -21,7 +21,7 @@ import type { CollectionEntry } from 'astro:content';
|
|
|
21
21
|
import { navigate } from 'astro:transitions/client';
|
|
22
22
|
import type { CollectionTypes } from '@types';
|
|
23
23
|
import DownloadButton from './DownloadButton';
|
|
24
|
-
import { buildUrl } from '@utils/url-builder';
|
|
24
|
+
import { buildUrl } from '@utils/url-builder-client';
|
|
25
25
|
|
|
26
26
|
interface Props {
|
|
27
27
|
nodes: any;
|
|
@@ -32,13 +32,17 @@ interface Props {
|
|
|
32
32
|
includeControls?: boolean;
|
|
33
33
|
linkTo: 'docs' | 'visualiser';
|
|
34
34
|
includeKey?: boolean;
|
|
35
|
+
urlHasTrailingSlash?: boolean;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
const getDocUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes
|
|
38
|
-
return buildUrl(`/docs/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}
|
|
38
|
+
const getDocUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes>, trailingSlash?: boolean) => {
|
|
39
|
+
return buildUrl(`/docs/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`, trailingSlash);
|
|
39
40
|
};
|
|
40
|
-
const getVisualiserUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes
|
|
41
|
-
return buildUrl(
|
|
41
|
+
const getVisualiserUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes>, trailingSlash?: boolean) => {
|
|
42
|
+
return buildUrl(
|
|
43
|
+
`/visualiser/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`,
|
|
44
|
+
trailingSlash
|
|
45
|
+
);
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
// const NodeGraphBuilder = ({ title, subtitle, includeBackground = true, includeControls = true }: Props) => {
|
|
@@ -49,6 +53,7 @@ const NodeGraphBuilder = ({
|
|
|
49
53
|
includeBackground = true,
|
|
50
54
|
linkTo = 'docs',
|
|
51
55
|
includeKey = true,
|
|
56
|
+
urlHasTrailingSlash,
|
|
52
57
|
}: Props) => {
|
|
53
58
|
const nodeTypes = useMemo(
|
|
54
59
|
() => ({
|
|
@@ -67,10 +72,18 @@ const NodeGraphBuilder = ({
|
|
|
67
72
|
|
|
68
73
|
const handleNodeClick = (_: any, node: Node) => {
|
|
69
74
|
if (node.type === 'events' || node.type === 'commands') {
|
|
70
|
-
navigate(
|
|
75
|
+
navigate(
|
|
76
|
+
linkTo === 'docs'
|
|
77
|
+
? getDocUrlForCollection(node.data.message, urlHasTrailingSlash)
|
|
78
|
+
: getVisualiserUrlForCollection(node.data.message, urlHasTrailingSlash)
|
|
79
|
+
);
|
|
71
80
|
}
|
|
72
81
|
if (node.type === 'services') {
|
|
73
|
-
navigate(
|
|
82
|
+
navigate(
|
|
83
|
+
linkTo === 'docs'
|
|
84
|
+
? getDocUrlForCollection(node.data.service, urlHasTrailingSlash)
|
|
85
|
+
: getVisualiserUrlForCollection(node.data.service, urlHasTrailingSlash)
|
|
86
|
+
);
|
|
74
87
|
}
|
|
75
88
|
};
|
|
76
89
|
|
|
@@ -132,6 +145,7 @@ interface NodeGraphProps {
|
|
|
132
145
|
linkTo: 'docs' | 'visualiser';
|
|
133
146
|
includeKey?: boolean;
|
|
134
147
|
footerLabel?: string;
|
|
148
|
+
urlHasTrailingSlash?: boolean;
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
const NodeGraph = ({
|
|
@@ -144,6 +158,7 @@ const NodeGraph = ({
|
|
|
144
158
|
hrefLabel = 'Open in visualizer',
|
|
145
159
|
includeKey = true,
|
|
146
160
|
footerLabel,
|
|
161
|
+
urlHasTrailingSlash,
|
|
147
162
|
}: NodeGraphProps) => {
|
|
148
163
|
const [elem, setElem] = useState(null);
|
|
149
164
|
|
|
@@ -158,7 +173,14 @@ const NodeGraph = ({
|
|
|
158
173
|
<div>
|
|
159
174
|
{createPortal(
|
|
160
175
|
<ReactFlowProvider>
|
|
161
|
-
<NodeGraphBuilder
|
|
176
|
+
<NodeGraphBuilder
|
|
177
|
+
edges={edges}
|
|
178
|
+
nodes={nodes}
|
|
179
|
+
title={title}
|
|
180
|
+
linkTo={linkTo}
|
|
181
|
+
includeKey={includeKey}
|
|
182
|
+
urlHasTrailingSlash={urlHasTrailingSlash}
|
|
183
|
+
/>
|
|
162
184
|
|
|
163
185
|
<div className="flex justify-between">
|
|
164
186
|
{footerLabel && (
|
|
@@ -72,7 +72,7 @@ try {
|
|
|
72
72
|
schemas.length > 0 &&
|
|
73
73
|
schemas.map((schema) => (
|
|
74
74
|
<div>
|
|
75
|
-
{schema.exists && <SchemaViewerClient {...schema} client:
|
|
75
|
+
{schema.exists && <SchemaViewerClient {...schema} client:only="react" />}
|
|
76
76
|
|
|
77
77
|
{/* User has tried to load the schema, but it was not found on file system */}
|
|
78
78
|
{!schema.exists && (
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const cleanUrl = (url: string) => {
|
|
2
|
+
return url.replace(/\/+/g, '/');
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
// Custom URL builder as Astro does not support this stuff out the box.
|
|
6
|
+
// Used on client components to build URLs
|
|
7
|
+
export const buildUrl = (url: string, trailingSlash = false, ignoreTrailingSlash = false) => {
|
|
8
|
+
let newUrl = url;
|
|
9
|
+
|
|
10
|
+
// If the base URL is not the root, we need to append it
|
|
11
|
+
if (import.meta.env.BASE_URL !== '/') {
|
|
12
|
+
newUrl = `${import.meta.env.BASE_URL}${url}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Should we add a trailing slash to the url?
|
|
16
|
+
if (trailingSlash && !ignoreTrailingSlash) {
|
|
17
|
+
if (url.endsWith('/')) return newUrl;
|
|
18
|
+
return cleanUrl(`${newUrl}/`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return cleanUrl(newUrl);
|
|
22
|
+
};
|