diff --git a/gui/app/src/components/onboarding/BodyPartAssignment.tsx b/gui/app/src/components/onboarding/BodyPartAssignment.tsx
index f2d78cf52..d81e08e9d 100644
--- a/gui/app/src/components/onboarding/BodyPartAssignment.tsx
+++ b/gui/app/src/components/onboarding/BodyPartAssignment.tsx
@@ -1,5 +1,11 @@
import classNames from 'classnames';
-import { HTMLAttributes, ReactNode, useCallback, useMemo } from 'react';
+import {
+ Fragment,
+ HTMLAttributes,
+ ReactNode,
+ useCallback,
+ useMemo,
+} from 'react';
import { useAtomValue } from 'jotai';
import { BodyPart } from 'solarxr-protocol';
import {
@@ -227,14 +233,16 @@ function BodyAssignmentView({
>
{groups.map((group, index) => (
- {group.filter(hasBodyPart).map((role) =>
- card({
- role,
- direction,
- td: trackerByPart[role],
- roleError: rolesWithErrors[role]?.label,
- })
- )}
+ {group.filter(hasBodyPart).map((role) => (
+
+ {card({
+ role,
+ direction,
+ td: trackerByPart[role],
+ roleError: rolesWithErrors[role]?.label,
+ })}
+
+ ))}
))}
diff --git a/gui/app/src/components/onboarding/ExtremityAssignment.tsx b/gui/app/src/components/onboarding/ExtremityAssignment.tsx
index a6e984c40..3f3769378 100644
--- a/gui/app/src/components/onboarding/ExtremityAssignment.tsx
+++ b/gui/app/src/components/onboarding/ExtremityAssignment.tsx
@@ -1,202 +1,27 @@
-import { HTMLAttributes, ReactNode, useCallback, useMemo } from 'react';
-import { useAtomValue } from 'jotai';
-import { BodyPart } from 'solarxr-protocol';
-import { ExtremityFigure } from '@/components/commons/ExtremityFigure';
+import { ExtremityDescriptor } from '@/utils/extremities';
import {
- DigitFlow,
- ExtremityLayoutProvider,
- ExtremityLayoutValue,
- ExtremitySlot,
-} from './extremities/ExtremityLayout';
-import { ExtremityDescriptor, ExtremitySide } from '@/utils/extremities';
-import { BodyPartError } from '@/hooks/tracker-picker';
-import {
- assignedRolesAtom,
- FlatDeviceTracker,
- trackerByBodyPartAtom,
-} from '@/store/app-store';
+ BodyPartAssignment,
+ ExtremityAssignmentViewProps,
+} from './BodyPartAssignment';
-export type ExtremityRow = {
- role: BodyPart;
- td: FlatDeviceTracker | undefined;
- roleError: string | undefined;
- labelId?: string;
- number?: number;
- /** Whether this row draws a line to its dot */
- connector: boolean;
-};
-
-export type ExtremityGroupRenderer = (args: {
- id: string;
- labelId?: string;
- direction: 'left' | 'right';
- rows: ExtremityRow[];
- edge?: 'side' | 'cap';
- flow?: DigitFlow;
-}) => ReactNode;
+export type {
+ ExtremityGroupRenderer,
+ ExtremityRow,
+} from './BodyPartAssignment';
export function ExtremityAssignment({
descriptor,
- side,
- dotSize,
- fillHeight,
- compact = false,
- highlightedRoles = [],
- rolesWithErrors = {},
- onRoleSelected,
- renderGroup,
- dotClass,
- dotProps,
- activeParts,
-}: {
+ ...props
+}: Omit & {
descriptor: ExtremityDescriptor;
- side: ExtremitySide;
- dotSize?: number;
- fillHeight?: boolean;
- compact?: boolean;
- highlightedRoles?: BodyPart[];
- rolesWithErrors?: Partial>;
- onRoleSelected: (role: BodyPart) => void;
- renderGroup: ExtremityGroupRenderer;
- dotClass?: (part: BodyPart) => string | undefined;
- dotProps?: (part: BodyPart) => HTMLAttributes;
- activeParts?: BodyPart[];
}) {
- const assignedRoles = useAtomValue(assignedRolesAtom);
- const trackerByPart = useAtomValue(trackerByBodyPartAtom);
- const { digits, root } = descriptor.sides[side];
-
- const sideNames = useMemo(() => {
- const names = new Set(
- [...Object.values(digits).flat(), root].map((part) => BodyPart[part])
- );
- return {
- left: side === 'left' ? names : new Set(),
- right: side === 'right' ? names : new Set(),
- };
- }, [side, digits, root]);
-
- /** Parts of a digit share one line, so their dots go by number */
- const partNumbers = useMemo(() => {
- const numbers = new Map();
- descriptor.digits.forEach((digit) => {
- if (digits[digit].length < 2) return;
- digits[digit].forEach((part, i) => numbers.set(part, i + 1));
- });
- return numbers;
- }, [descriptor, digits]);
-
- const dotContent = useCallback(
- (part: BodyPart) => {
- const number = partNumbers.get(part);
- return (
- number && (
-
- {number}
-
- )
- );
- },
- [partNumbers]
- );
-
- const cell = useCallback(
- (role: BodyPart) => ({
- role,
- td: trackerByPart[role],
- roleError: rolesWithErrors[role]?.label,
- }),
- [trackerByPart, rolesWithErrors]
- );
-
- const mirrored = side === 'left';
-
- const digit = useCallback(
- (name: string, { direction, edge }: ExtremitySlot, flow: DigitFlow) => {
- if (name === 'root')
- return renderGroup({
- id: name,
- direction,
- edge,
- rows: [{ ...cell(root), connector: true }],
- });
-
- const parts = digits[name];
- const main = descriptor.mainPart(parts);
- const rows = parts.map((part, i) => ({
- ...cell(part),
- labelId: descriptor.partLabelId(part),
- number: parts.length > 1 ? i + 1 : undefined,
- connector: part === main,
- }));
-
- return renderGroup({
- id: name,
- // rows of a single part carry their own name already
- labelId: parts.length > 1 ? descriptor.digitLabelId(name) : undefined,
- direction,
- edge,
- flow,
- // spread across the figure, so they follow the mirrored dots
- rows: flow === 'columns' && mirrored ? [...rows].reverse() : rows,
- });
- },
- [descriptor, digits, root, cell, renderGroup, mirrored]
- );
-
- const figure = useCallback(
- (height?: number) => (
-
- ),
- [descriptor, side, fillHeight]
- );
-
- const layout = useMemo(
- () => ({
- compact,
- mirrored,
- digit,
- figure,
- interactions: {
- dotsSize: dotSize,
- dotClass,
- dotContent,
- dotProps,
- activeParts,
- sideNames,
- assignedRoles,
- highlightedRoles,
- onSelectRole: onRoleSelected,
- },
- }),
- [
- compact,
- mirrored,
- digit,
- figure,
- dotSize,
- dotClass,
- dotContent,
- dotProps,
- activeParts,
- sideNames,
- assignedRoles,
- highlightedRoles,
- onRoleSelected,
- ]
- );
-
- const { Layout } = descriptor;
-
return (
-
-
-
+
);
}
diff --git a/gui/app/src/components/onboarding/pages/trackers-assign/BodyAssignmentPanel.tsx b/gui/app/src/components/onboarding/pages/trackers-assign/BodyAssignmentPanel.tsx
index 62e1423aa..0c41d2fd5 100644
--- a/gui/app/src/components/onboarding/pages/trackers-assign/BodyAssignmentPanel.tsx
+++ b/gui/app/src/components/onboarding/pages/trackers-assign/BodyAssignmentPanel.tsx
@@ -7,14 +7,11 @@ import {
useMemo,
} from 'react';
import { BodyPart } from 'solarxr-protocol';
+import { MirrorLegend } from '@/components/onboarding/BodyAssignment';
import {
- BodyAssignment,
- MirrorLegend,
-} from '@/components/onboarding/BodyAssignment';
-import {
- ExtremityAssignment,
+ BodyPartAssignment,
ExtremityGroupRenderer,
-} from '@/components/onboarding/ExtremityAssignment';
+} from '@/components/onboarding/BodyPartAssignment';
import {
AssignedTrackerLabel,
ExtremityGroupCard,
@@ -131,8 +128,8 @@ export function PickerPanel({
)}
>
{extremity ? (
-
) : (
-