Skip to content

Commit 729249a

Browse files
committed
Added flexible sidebar
1 parent 13c59e6 commit 729249a

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

eventcatalog/src/components/SchemaExplorer/FHIRSchemaViewer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path';
12
import React, { useMemo } from 'react';
23

34
interface FHIRSchemaViewerProps {
@@ -39,13 +40,14 @@ function buildElementTree(elements: any[]): FhirElementNode[] {
3940
const stack: { depth: number; node: FhirElementNode }[] = [];
4041

4142
elements.forEach((el: any, index: number) => {
42-
const depth = el.path.split('.').length;
43+
const pathParts = el.path.split('.');
44+
const depth = pathParts.length;
4345

4446
const node: FhirElementNode = {
4547
key: `${index}`,
4648
id: el.id,
4749
path: el.path,
48-
name: el.name,
50+
name: el.sliceName ?? pathParts[pathParts.length - 1],
4951
min: el.min ?? 0,
5052
max: el.max ?? '1',
5153
types: Array.isArray(el.type) ? el.type.map((t: any) => t.code) : [],
@@ -200,7 +202,7 @@ function ElementNodeView({ node, depth }: { node: FhirElementNode; depth: number
200202
<span style={{ width: 14 }} />
201203
)}
202204

203-
<span style={{ fontWeight: depth === 0 ? 'bold' : 'normal' }}>{node.path}</span>
205+
<span style={{ fontWeight: depth === 0 ? 'bold' : 'normal' }}>{node.name}</span>
204206

205207
<span style={{ opacity: 0.6, marginLeft: 6 }}>
206208
({node.min}..{node.max})

eventcatalog/src/components/SideNav/SideNav.astro

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,38 @@ const props = await getNestedSideBarData();
2525
setSidebarData(data);
2626
}
2727
</script>
28+
29+
<script>
30+
const sidebar = document.getElementById('sidebar');
31+
const resizer = document.getElementById('sidebar-resizer');
32+
33+
if (sidebar && resizer) {
34+
let isResizing = false;
35+
36+
resizer.addEventListener('mousedown', () => {
37+
isResizing = true;
38+
document.body.style.cursor = 'col-resize';
39+
document.body.style.userSelect = 'none';
40+
});
41+
42+
document.addEventListener('mousemove', (e) => {
43+
if (!isResizing) return;
44+
45+
const newWidth = Math.max(240, Math.min(600, e.clientX - 56));
46+
sidebar.style.setProperty('--sidebar-width', `${newWidth}px`);
47+
localStorage.setItem('eventcatalog-sidebar-width', newWidth);
48+
});
49+
50+
document.addEventListener('mouseup', () => {
51+
isResizing = false;
52+
document.body.style.cursor = '';
53+
document.body.style.userSelect = '';
54+
});
55+
56+
// Restore saved width
57+
const savedWidth = localStorage.getItem('eventcatalog-sidebar-width');
58+
if (savedWidth) {
59+
sidebar.style.setProperty('--sidebar-width', `${savedWidth}px`);
60+
}
61+
}
62+
</script>

eventcatalog/src/layouts/VerticalSideBarLayout.astro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,15 @@ const canPageBeEmbedded = isEmbedEnabled();
344344

345345
{
346346
showNestedSideBar && (
347-
<SideNav id="sidebar" class={`sidebar-transition h-content bg-white border-r border-gray-100 w-[320px] ml-14`} />
347+
<SideNav
348+
id="sidebar"
349+
class="sidebar-transition h-content bg-white border-r border-gray-100 ml-14"
350+
style="width: var(--sidebar-width, 320px);"
351+
/>
352+
<div
353+
id="sidebar-resizer"
354+
class="w-1 cursor-col-resize bg-transparent hover:bg-blue-200"
355+
style="position: relative; z-index: 30;"/>
348356
)
349357
}
350358
</aside>

0 commit comments

Comments
 (0)