feat(editor): board 01 annotation card, side column from 1 024 px
Annotations of the view move from under the drawing to the overview card (grouped by category, name filter, all rows); side column from lg. Properties panel gains « Toutes les annotations ». E2E mapping (R-24): after a creation the card is hidden (the new annotation is selected), so list(...).getByText(name) became selectionTag toContainText (annotations, geometry, journey); row clicks go through pickAnnotation (annotations, geometry, journey, structures); geometry's list count 0 while a creation is pending became selectionTag count 0.
This commit is contained in:
1 parent
51fd3db608
commit
6131225288
16 files changed
+404
-94
No files matched your search
@@ -1,11 +1,10 @@
|
||||
import type { Annotation, SheetView } from '@faunosteo/core-wasm/types'
|
||||
import type { AnnotationGroup } from '@/editor/annotations/overview'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import ReviewBadge from './ReviewBadge'
|
||||
|
||||
const LIST =
|
||||
'max-h-64 divide-y divide-[var(--color-border)] overflow-y-auto rounded-lg ' +
|
||||
'border border-[var(--color-border)]'
|
||||
const LIST = 'max-h-96 space-y-2 overflow-y-auto'
|
||||
|
||||
const ROW =
|
||||
'flex w-full items-center justify-between gap-2 px-3 py-2 text-left text-sm ' +
|
||||
@@ -24,52 +23,91 @@ export function annotationName(
|
||||
return opened?.name[locale] ?? annotation.id
|
||||
}
|
||||
|
||||
/**
|
||||
* The annotations of the view: name, kind, review badge; each row a button, reachable
|
||||
* from the keyboard. Selection works in every mode, so a read-only draft is browsable.
|
||||
*/
|
||||
export default function AnnotationList({
|
||||
annotations,
|
||||
function Row({
|
||||
annotation,
|
||||
views,
|
||||
selectedId,
|
||||
onSelect,
|
||||
}: {
|
||||
annotations: readonly Annotation[]
|
||||
annotation: Annotation
|
||||
views: readonly SheetView[]
|
||||
selectedId: string | null
|
||||
onSelect: (id: string) => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (annotations.length === 0) {
|
||||
return (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.annotations.list_empty')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
data-focus-key={JSON.stringify({
|
||||
kind: 'annotation',
|
||||
id: annotation.id,
|
||||
})}
|
||||
onClick={() => onSelect(annotation.id)}
|
||||
className={ROW}
|
||||
>
|
||||
<span className="min-w-0 truncate">
|
||||
<span className="text-[var(--color-ink-muted)]">
|
||||
{t(`editor.annotations.kind.${annotation.kind}`)}
|
||||
</span>{' '}
|
||||
{annotationName(annotation, views, locale)}
|
||||
</span>
|
||||
<ReviewBadge status={annotation.review_status} />
|
||||
</button>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
/** « Sans catégorie » or the category: swatch, name and the count of rows shown. */
|
||||
function GroupTitle({ group }: { group: AnnotationGroup }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { category } = group
|
||||
return (
|
||||
<p className="flex items-center gap-2 px-3 text-sm font-semibold">
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="size-3 rounded-full border border-[var(--color-border)]"
|
||||
style={{ backgroundColor: category?.color ?? undefined }}
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{category ? category.name[locale] : t('editor.overview.uncategorised')}
|
||||
</span>
|
||||
<span className="font-normal text-[var(--color-ink-muted)]">
|
||||
{group.annotations.length}
|
||||
</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The annotations of the view by category, each row a button reachable from the keyboard.
|
||||
* Selection works in every mode, so a read-only draft is browsable.
|
||||
*/
|
||||
export default function AnnotationList({
|
||||
groups,
|
||||
views,
|
||||
onSelect,
|
||||
}: {
|
||||
groups: readonly AnnotationGroup[]
|
||||
views: readonly SheetView[]
|
||||
onSelect: (id: string) => void
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<ul aria-label={t('editor.annotations.list')} className={LIST}>
|
||||
{annotations.map((annotation) => (
|
||||
<li key={annotation.id}>
|
||||
<button
|
||||
type="button"
|
||||
aria-current={annotation.id === selectedId}
|
||||
onClick={() => onSelect(annotation.id)}
|
||||
className={`${ROW} ${
|
||||
annotation.id === selectedId
|
||||
? 'bg-[var(--color-surface-strong)]'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
<span className="min-w-0 truncate">
|
||||
<span className="text-[var(--color-ink-muted)]">
|
||||
{t(`editor.annotations.kind.${annotation.kind}`)}
|
||||
</span>{' '}
|
||||
{annotationName(annotation, views, locale)}
|
||||
</span>
|
||||
<ReviewBadge status={annotation.review_status} />
|
||||
</button>
|
||||
{groups.map((group) => (
|
||||
<li key={group.category?.id ?? 'none'}>
|
||||
<GroupTitle group={group} />
|
||||
<ul>
|
||||
{group.annotations.map((annotation) => (
|
||||
<Row
|
||||
key={annotation.id}
|
||||
annotation={annotation}
|
||||
views={views}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -28,7 +28,7 @@ import type { EditorPlaceProps } from '@/editor/tabs'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import AnnotationCanvas from './AnnotationCanvas'
|
||||
import AnnotationList, { annotationName } from './AnnotationList'
|
||||
import { annotationName } from './AnnotationList'
|
||||
import CreationPanel from './CreationPanel'
|
||||
import KeyboardAdd from './KeyboardAdd'
|
||||
import OverviewPanel from './OverviewPanel'
|
||||
@@ -131,7 +131,7 @@ export default function EditableAnnotations(props: Props) {
|
||||
const context = useCommitContext()
|
||||
const placement = usePlacement({ ...scene, context })
|
||||
return (
|
||||
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<CanvasColumn scene={scene} placement={placement} />
|
||||
<aside>
|
||||
<SidePanel scene={scene} context={context} />
|
||||
@@ -180,12 +180,6 @@ function CanvasColumn({
|
||||
linkDisabled={model.children.length === 0}
|
||||
onAdd={(kind) => addAtCentre(kind, scene.frame, dispatch)}
|
||||
/>
|
||||
<AnnotationList
|
||||
annotations={model.annotations}
|
||||
views={doc.views}
|
||||
selectedId={ui.selectedId}
|
||||
onSelect={(id) => dispatch({ type: 'select', id })}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -281,6 +275,7 @@ function SidePanel({
|
||||
viewId={scene.viewId}
|
||||
readOnly={false}
|
||||
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
|
||||
onSelectAnnotation={(id) => dispatch({ type: 'select', id })}
|
||||
onOpenSection={scene.onOpenSection}
|
||||
/>
|
||||
)
|
||||
@@ -295,6 +290,7 @@ function SidePanel({
|
||||
dispatch={dispatch}
|
||||
context={context}
|
||||
navigate={scene.navigate}
|
||||
onShowAll={() => dispatch({ type: 'select', id: null })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { useMemo, useState } from 'react'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
SheetView,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { useOverviewCounts } from '@/editor/annotations/overview'
|
||||
import Input from '@/components/ui/Input'
|
||||
import {
|
||||
groupAnnotations,
|
||||
useOverviewCounts,
|
||||
} from '@/editor/annotations/overview'
|
||||
import type { AnnotationSection } from '@/editor/navigation'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import AnnotationList, { annotationName } from './AnnotationList'
|
||||
|
||||
const CARD = 'space-y-2 rounded-xl border border-[var(--color-border)] p-4'
|
||||
const TITLE = 'text-sm font-semibold'
|
||||
@@ -24,6 +30,7 @@ export interface OverviewPanelProps {
|
||||
/** Put before every id (the read-only twin beside the kept edit panel). */
|
||||
idPrefix?: string
|
||||
onSelectView: (viewId: string) => void
|
||||
onSelectAnnotation: (annotationId: string) => void
|
||||
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
@@ -183,7 +190,59 @@ function CategoriesCard(props: OverviewPanelProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** Board 01's overview: the views and the categories, with the entries to their sections. */
|
||||
function AnnotationsCard(props: OverviewPanelProps) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { doc, viewId, onSelectAnnotation } = props
|
||||
const [term, setTerm] = useState('')
|
||||
const prefix = props.idPrefix ?? ''
|
||||
const total = useOverviewCounts(doc).annotationsByView.get(viewId) ?? 0
|
||||
const groups = useMemo(
|
||||
() =>
|
||||
groupAnnotations(doc, viewId, term, (a) =>
|
||||
annotationName(a, doc.views, locale),
|
||||
),
|
||||
[doc, viewId, term, locale],
|
||||
)
|
||||
return (
|
||||
<section aria-labelledby={`${prefix}overview-annotations`} className={CARD}>
|
||||
<h3
|
||||
id={`${prefix}overview-annotations`}
|
||||
className={`${TITLE} flex items-center justify-between`}
|
||||
>
|
||||
{t('editor.annotations.list')}
|
||||
<span className="font-normal text-[var(--color-ink-muted)]">
|
||||
{total}
|
||||
</span>
|
||||
</h3>
|
||||
<Input
|
||||
type="search"
|
||||
id={`${prefix}overview-filter`}
|
||||
aria-label={t('editor.overview.filter')}
|
||||
placeholder={t('editor.overview.filter')}
|
||||
value={term}
|
||||
onChange={(event) => setTerm(event.target.value)}
|
||||
/>
|
||||
{groups.length > 0 ? (
|
||||
<AnnotationList
|
||||
groups={groups}
|
||||
views={doc.views}
|
||||
onSelect={onSelectAnnotation}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t(
|
||||
total === 0
|
||||
? 'editor.annotations.list_empty'
|
||||
: 'editor.overview.no_match',
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** Board 01's overview: the views, the categories, then the annotations of the shown view. */
|
||||
export default function OverviewPanel(props: OverviewPanelProps) {
|
||||
const t = useT()
|
||||
return (
|
||||
@@ -195,6 +254,7 @@ export default function OverviewPanel(props: OverviewPanelProps) {
|
||||
>
|
||||
<ViewsCard {...props} />
|
||||
<CategoriesCard {...props} />
|
||||
<AnnotationsCard {...props} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, type Dispatch } from 'react'
|
||||
import { flushSync } from 'react-dom'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
Annotation,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
import { isEditable } from '@/editor/annotations/geometryEdit'
|
||||
import type { UiAction } from '@/editor/annotations/uiState'
|
||||
import { geometryErrorsById } from '@/editor/issues'
|
||||
import { focusRow } from '@/editor/focusRequest'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
@@ -37,6 +39,8 @@ export interface PropertiesPanelProps {
|
||||
dispatch: Dispatch<UiAction>
|
||||
context: CommitContext
|
||||
navigate: EditorPlaceProps['navigate']
|
||||
/** Clears the selection: the overview shows again. */
|
||||
onShowAll: () => void
|
||||
/** Put before every id, for a twin of the panel that lives beside another one. */
|
||||
idPrefix?: string
|
||||
}
|
||||
@@ -60,6 +64,7 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
|
||||
data-testid="annotation-properties"
|
||||
className="space-y-4 rounded-xl border border-[var(--color-border)] p-4"
|
||||
>
|
||||
<ShowAll id={annotation.id} onShowAll={props.onShowAll} />
|
||||
<header className="flex items-start justify-between gap-2">
|
||||
<h3
|
||||
tabIndex={-1}
|
||||
@@ -84,6 +89,24 @@ export default function PropertiesPanel(props: PropertiesPanelProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** Back to the overview, focus on the row of the annotation that was open. */
|
||||
function ShowAll({ id, onShowAll }: { id: string; onShowAll: () => void }) {
|
||||
const t = useT()
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
flushSync(onShowAll)
|
||||
focusRow({ kind: 'annotation', id })
|
||||
}}
|
||||
>
|
||||
{t('editor.annotations.show_all')}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function GeometrySection(props: PropertiesPanelProps) {
|
||||
const t = useT()
|
||||
const { annotation, readOnly, geometryLocked } = props
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import CatalogueCanvas from '@/components/catalogue/CatalogueCanvas'
|
||||
import AnnotationList, {
|
||||
annotationName,
|
||||
} from '@/components/editor/annotations/AnnotationList'
|
||||
import { annotationName } from '@/components/editor/annotations/AnnotationList'
|
||||
import EditableAnnotations from '@/components/editor/annotations/EditableAnnotations'
|
||||
import OverviewPanel from '@/components/editor/annotations/OverviewPanel'
|
||||
import PropertiesPanel from '@/components/editor/annotations/PropertiesPanel'
|
||||
@@ -166,7 +164,7 @@ function ReadOnlyAnnotations({
|
||||
const selected = model.annotations.find((a) => a.id === selectedId)
|
||||
if (!preview || !view) return null
|
||||
return (
|
||||
<div className="grid gap-4 xl:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||
<div className="min-w-0 space-y-3">
|
||||
<ViewSwitcher
|
||||
views={doc.views}
|
||||
@@ -190,12 +188,6 @@ function ReadOnlyAnnotations({
|
||||
selectedId={selectedId}
|
||||
onAnnotation={setSelectedId}
|
||||
/>
|
||||
<AnnotationList
|
||||
annotations={model.annotations}
|
||||
views={doc.views}
|
||||
selectedId={selectedId}
|
||||
onSelect={setSelectedId}
|
||||
/>
|
||||
</div>
|
||||
{selected ? (
|
||||
<PropertiesPanel
|
||||
@@ -208,6 +200,7 @@ function ReadOnlyAnnotations({
|
||||
dispatch={() => undefined}
|
||||
context={{ t: (key) => key, locale }}
|
||||
navigate={navigate}
|
||||
onShowAll={() => setSelectedId(null)}
|
||||
/>
|
||||
) : (
|
||||
<OverviewPanel
|
||||
@@ -219,6 +212,7 @@ function ReadOnlyAnnotations({
|
||||
setViewId(id)
|
||||
setSelectedId(null)
|
||||
}}
|
||||
onSelectAnnotation={setSelectedId}
|
||||
onOpenSection={onOpenSection}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user