Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions render/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type View,
} from './api';
import { emptyStore, mergePayload, removeNode, toNvl, type GraphStore } from './graph';
import { useTouchZoomPan } from './touch';
import { Toolbar } from './components/Toolbar';
import { DetailsPanel } from './components/DetailsPanel';
import { CypherPanel } from './components/CypherPanel';
Expand All @@ -40,6 +41,8 @@ const errorMessage = (err: unknown): string => {

export function App() {
const nvlRef = useRef<NVL>(null);
const [canvasEl, setCanvasEl] = useState<HTMLDivElement | null>(null);
useTouchZoomPan(canvasEl, nvlRef);
const [store, setStore] = useState<GraphStore>(emptyStore);
const [selectedId, setSelectedId] = useState<string | null>(null);
const [options, setOptions] = useState<CrateLoadOptions>(DEFAULT_OPTIONS);
Expand Down Expand Up @@ -367,7 +370,7 @@ export function App() {
/>
) : (
<>
<div className="canvas">
<div className="canvas" ref={setCanvasEl}>
{nodes.length === 0 && view === 'deps' ? (
<div className="empty">
<h1>crate dependency chain</h1>
Expand Down Expand Up @@ -405,7 +408,12 @@ export function App() {
style={{ width: '100%', height: '100%' }}
/>
</div>
<aside className="sidebar">
<aside className={`sidebar${selected ? ' has-selection' : ''}`}>
{selected && (
<button type="button" className="sheet-close" aria-label="Close details" onClick={() => setSelectedId(null)}>
×
</button>
)}
<DetailsPanel
view={view}
onExpandDeps={(name, dir) => void loadDeps(name, dir)}
Expand Down
16 changes: 14 additions & 2 deletions render/src/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Node as NvlNode, Relationship as NvlRel, NvlOptions } from '@neo4j
import { InteractiveNvlWrapper, type MouseEventCallbacks } from '@neo4j-nvl/react';
import { api, ApiError, type GraphNode, type LodStatus, type LodViewport } from '../api';
import { communityColor } from '../graph';
import { useTouchZoomPan } from '../touch';

const MAP_PX = 6000;
const FETCH_DEBOUNCE_MS = 180;
Expand Down Expand Up @@ -37,6 +38,12 @@ interface Calibration {
export function MapView({ target, budget, onError, onBusy, onOpenInDeps, onMeta }: Props) {
const nvlRef = useRef<NVL>(null);
const containerRef = useRef<HTMLDivElement>(null);
const [canvasEl, setCanvasEl] = useState<HTMLDivElement | null>(null);
const canvasRef = useCallback((el: HTMLDivElement | null) => {
containerRef.current = el;
setCanvasEl(el);
}, []);
useTouchZoomPan(canvasEl, nvlRef);
const [status, setStatus] = useState<LodStatus | null>(null);
const [payload, setPayload] = useState<LodViewport | null>(null);
const [selected, setSelected] = useState<GraphNode | null>(null);
Expand Down Expand Up @@ -363,7 +370,7 @@ export function MapView({ target, budget, onError, onBusy, onOpenInDeps, onMeta

return (
<>
<div className="canvas" ref={containerRef}>
<div className="canvas" ref={canvasRef}>
{!status?.index && (
<div className="empty">
<h1>ecosystem map</h1>
Expand Down Expand Up @@ -392,7 +399,12 @@ export function MapView({ target, budget, onError, onBusy, onOpenInDeps, onMeta
style={{ width: '100%', height: '100%' }}
/>
</div>
<aside className="sidebar">
<aside className={`sidebar${selected ? ' has-selection' : ''}`}>
{selected && (
<button type="button" className="sheet-close" aria-label="Close details" onClick={() => setSelected(null)}>
×
</button>
)}
<div className="details">
{selected ? (
<>
Expand Down
22 changes: 21 additions & 1 deletion render/src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from 'react';
import { api, isTableView, VIEWS, type CrateLoadOptions, type View } from '../api';
import { useIsMobile } from '../touch';

interface Props {
view: View;
Expand Down Expand Up @@ -28,6 +29,14 @@ export function Toolbar(props: Props) {
const MIN_PARTIAL = 3;
const { options, onOptionsChange, onLoad, loadedName, onClear, onFit, layout, onLayoutChange, busy } = props;
const [query, setQuery] = useState('');
const isMobile = useIsMobile();
const [optsOpen, setOptsOpen] = useState(false);
const activeTab = useRef<HTMLButtonElement>(null);

// On a phone the view buttons are a scrolling strip; keep the current one visible.
useEffect(() => {
activeTab.current?.scrollIntoView({ block: 'nearest', inline: 'center' });
}, [view]);

useEffect(() => {
if (loadedName) setQuery(loadedName);
Expand Down Expand Up @@ -71,6 +80,7 @@ export function Toolbar(props: Props) {
{VIEWS.map((v) => (
<button
key={v.id}
ref={v.id === view ? activeTab : undefined}
type="button"
className={v.id === view ? 'active' : ''}
title={v.title}
Expand Down Expand Up @@ -115,7 +125,8 @@ export function Toolbar(props: Props) {
}
}}
spellCheck={false}
autoFocus
// Focusing on load pops the on-screen keyboard over the page.
autoFocus={!isMobile}
/>
{open && suggestions.length > 0 && (
<ul className="suggestions">
Expand All @@ -138,6 +149,14 @@ export function Toolbar(props: Props) {
</>
)}

{!isTableView(view) && (
<button type="button" className={`opts-toggle${optsOpen ? ' active' : ''}`} aria-expanded={optsOpen} onClick={() => setOptsOpen((o) => !o)}>
Options
</button>
)}

{/* `display: contents` on desktop, a collapsible row on phones. */}
<div className={`toolbar-opts${optsOpen ? ' open' : ''}`}>
{view === 'map' && (
<label className="opt" title="Maximum clusters or crates drawn for one viewport">
max visible
Expand Down Expand Up @@ -232,6 +251,7 @@ export function Toolbar(props: Props) {
</button>
</>
)}
</div>
</div>
);
}
168 changes: 168 additions & 0 deletions render/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ body,
display: flex;
flex-direction: column;
height: 100vh;
/* Mobile browser chrome shrinks the visible area below 100vh. */
height: 100dvh;
}

.toolbar {
Expand Down Expand Up @@ -193,6 +195,8 @@ label.opt {
position: relative;
flex: 1;
min-width: 0;
/* Touch gestures go to useTouchZoomPan instead of scrolling or zooming the page. */
touch-action: none;
background: radial-gradient(circle at 50% 50%, #151924 0%, var(--bg) 70%);
}

Expand Down Expand Up @@ -1227,3 +1231,167 @@ table.diff-files-table td.path {
.tile a:hover {
text-decoration: underline;
}

.toolbar-opts {
display: contents;
}

.opts-toggle,
.sheet-close {
display: none;
}

/* Phones. Keep the width in sync with MOBILE_QUERY in touch.ts. */
@media (max-width: 768px) {
.toolbar {
gap: 6px;
padding: 6px 8px;
}

.toolbar > .views {
order: -1;
width: 100%;
overflow-x: auto;
scrollbar-width: none;
}

.toolbar > .views::-webkit-scrollbar {
display: none;
}

.views button {
flex: 0 0 auto;
padding: 8px 12px;
}

.search {
flex: 1;
min-width: 0;
}

/* iOS zooms the page when focusing an input below 16px. */
input,
select,
textarea {
font-size: 16px;
}

.opts-toggle {
display: inline-block;
}

.opts-toggle.active {
background: var(--panel-2);
border-color: var(--accent);
}

.toolbar-opts {
display: none;
}

.toolbar-opts.open {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px 12px;
width: 100%;
}

.toolbar-opts .spacer {
display: none;
}

.main {
position: relative;
}

.empty,
.callers-empty {
padding: 0 16px;
}

/* Details become a bottom sheet over the canvas, shown only for a selection. */
.sidebar {
position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
width: auto;
max-height: 55%;
border-left: 0;
border-top: 1px solid var(--border);
border-radius: 10px 10px 0 0;
box-shadow: 0 -6px 20px rgb(0 0 0 / 45%);
}

.sidebar:not(.has-selection) {
display: none;
}

.sheet-close {
display: block;
position: sticky;
top: 6px;
float: right;
margin: 6px 8px 0 0;
padding: 2px 10px;
font-size: 18px;
line-height: 1.2;
z-index: 1;
}

.cypher {
display: none;
}

/* Only the connection dot and errors; the rest does not fit. */
.statusbar > :not(.dot):not(.error) {
display: none;
}

.statusbar .error {
max-width: none;
flex: 1;
}

/* Table views scroll as a whole page so wrapped tiles do not squeeze the table to nothing. */
.callers,
.unsafe {
overflow-y: auto;
}

.callers-table,
.unsafe-table {
flex: none;
min-height: auto;
overflow: visible;
overflow-x: auto;
}

.unsafe-tiles,
.unsafe-controls,
.callers-form,
.callers-summary {
padding: 8px;
}

.tile,
.tile.wide {
min-width: 0;
flex: 1 1 140px;
}

.callers-form .search.crate,
.callers-form .search.fn,
.unsafe-controls .search,
.unsafe-controls input.q {
min-width: 0;
flex: 1 1 100%;
}

.unsafe-history,
.diff-files {
min-width: 0;
}
}
Loading
Loading