feat(phase-b): school/timetable wizards, graph nav panel, UI updates
New components: - CCGraphNavPanel: Supabase-driven navigation tree (school/timetable/calendar/classes sections), role-aware setup buttons, lazy child loading, academic/generic calendar toggle - SchoolCalendarWizard: 3-step admin-only school setup (details → term dates → daily periods) - TeacherTimetableWizard: period grid with existing slot pre-loading, edit-mode title Updated: - CCNodeSnapshotPanel: saves via Supabase storage path + accessToken - BasePanel: nav panel tab wired to CCGraphNavPanel - CCFilesPanelEnhanced: auth context fixes - CCDocumentIntelligence suite: accessToken threading, Supabase storage integration Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
@@ -0,0 +1,586 @@
|
||||
import React, { useState, useEffect, useCallback, createContext, useContext } from 'react';
|
||||
import {
|
||||
Box, IconButton, CircularProgress, Collapse, Typography, Tooltip,
|
||||
ToggleButtonGroup, ToggleButton,
|
||||
} from '@mui/material';
|
||||
import {
|
||||
ExpandMore, ChevronRight as ChevronRightIcon,
|
||||
Home as HomeIcon,
|
||||
CalendarToday, DateRange, Event,
|
||||
Schedule as TimetableIcon,
|
||||
Class as ClassIcon,
|
||||
MenuBook as CurriculumIcon,
|
||||
Book as JournalIcon,
|
||||
EventNote as PlannerIcon,
|
||||
Business as SchoolIcon,
|
||||
LinkOff as UnlinkedIcon,
|
||||
HourglassEmpty as PendingIcon,
|
||||
School as AcademicIcon,
|
||||
GridOn as GridIcon,
|
||||
Settings as SetupIcon,
|
||||
Edit as EditIcon,
|
||||
} from '@mui/icons-material';
|
||||
import { useNavigationStore } from '../../../../../../stores/navigationStore';
|
||||
import { useAuth } from '../../../../../../contexts/AuthContext';
|
||||
import { NeoGraphNode } from '../../../../../../types/navigation';
|
||||
import { logger } from '../../../../../../debugConfig';
|
||||
import { SchoolCalendarWizard, SchoolInfo } from './SchoolCalendarWizard';
|
||||
import { TeacherTimetableWizard, PeriodTemplate } from './TeacherTimetableWizard';
|
||||
|
||||
type NodeStatus = 'populated' | 'empty' | 'no_school' | 'not_initialized';
|
||||
type CalendarMode = 'generic' | 'academic';
|
||||
|
||||
interface TreeNode extends NeoGraphNode {
|
||||
has_children?: boolean;
|
||||
children?: TreeNode[];
|
||||
is_section?: boolean;
|
||||
section_id?: string;
|
||||
status?: NodeStatus;
|
||||
neo4j_props?: Record<string, string>;
|
||||
}
|
||||
|
||||
interface SchoolStatus {
|
||||
status: string;
|
||||
user_role?: string;
|
||||
school_id?: string;
|
||||
school_has_calendar?: boolean;
|
||||
teacher_has_timetable?: boolean;
|
||||
timetable_id?: string | null;
|
||||
periods_template?: PeriodTemplate[] | null;
|
||||
school_info?: SchoolInfo;
|
||||
}
|
||||
|
||||
const NODE_ICONS: Record<string, React.ElementType> = {
|
||||
User: HomeIcon,
|
||||
CalendarYear: CalendarToday,
|
||||
CalendarMonth: DateRange,
|
||||
CalendarWeek: DateRange,
|
||||
CalendarDay: Event,
|
||||
AcademicYear: AcademicIcon,
|
||||
AcademicTerm: AcademicIcon,
|
||||
AcademicWeek: DateRange,
|
||||
TeacherTimetable: TimetableIcon,
|
||||
SubjectClass: ClassIcon,
|
||||
TimetableLesson: TimetableIcon,
|
||||
TimetableSlot: GridIcon,
|
||||
Journal: JournalIcon,
|
||||
Planner: PlannerIcon,
|
||||
School: SchoolIcon,
|
||||
Department: SchoolIcon,
|
||||
Section: HomeIcon,
|
||||
};
|
||||
|
||||
const SECTION_ICONS: Record<string, React.ElementType> = {
|
||||
calendar: CalendarToday,
|
||||
timetable: TimetableIcon,
|
||||
classes: ClassIcon,
|
||||
curriculum: CurriculumIcon,
|
||||
journal: JournalIcon,
|
||||
planner: PlannerIcon,
|
||||
school: SchoolIcon,
|
||||
};
|
||||
|
||||
const STATUS_MESSAGES: Record<NodeStatus, string> = {
|
||||
populated: '',
|
||||
empty: 'Not set up yet',
|
||||
no_school: 'Join a school to unlock',
|
||||
not_initialized: 'Setting up...',
|
||||
};
|
||||
|
||||
// ─── Panel context ─────────────────────────────────────────────────────────────
|
||||
|
||||
interface NavPanelContextValue {
|
||||
calendarMode: CalendarMode;
|
||||
setCalendarMode: (m: CalendarMode) => void;
|
||||
academicCalendarStatus: 'idle' | 'loading' | 'populated' | 'empty' | 'no_school' | 'error';
|
||||
academicTerms: TreeNode[];
|
||||
schoolStatus: SchoolStatus | null;
|
||||
onSetupSchoolCalendar: () => void;
|
||||
onSetupTimetable: () => void;
|
||||
activeNodeId?: string;
|
||||
}
|
||||
|
||||
const NavPanelContext = createContext<NavPanelContextValue>({
|
||||
calendarMode: 'generic',
|
||||
setCalendarMode: () => {},
|
||||
academicCalendarStatus: 'idle',
|
||||
academicTerms: [],
|
||||
schoolStatus: null,
|
||||
onSetupSchoolCalendar: () => {},
|
||||
onSetupTimetable: () => {},
|
||||
});
|
||||
|
||||
// ─── TreeItem ─────────────────────────────────────────────────────────────────
|
||||
|
||||
interface TreeItemProps {
|
||||
node: TreeNode;
|
||||
depth: number;
|
||||
onSelect: (node: TreeNode) => void;
|
||||
onExpand: (node: TreeNode) => Promise<TreeNode[]>;
|
||||
}
|
||||
|
||||
function TreeItem({ node, depth, onSelect, onExpand }: TreeItemProps) {
|
||||
const ctx = useContext(NavPanelContext);
|
||||
const [expanded, setExpanded] = useState(node.is_section && node.status === 'populated');
|
||||
const [children, setChildren] = useState<TreeNode[]>(node.children || []);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const isSection = !!node.is_section;
|
||||
const isCalendarSection = isSection && node.section_id === 'calendar';
|
||||
const isTimetableSection = isSection && node.section_id === 'timetable';
|
||||
const isSchoolSection = isSection && node.section_id === 'school';
|
||||
const SectionIcon = node.section_id ? SECTION_ICONS[node.section_id] : null;
|
||||
const Icon = SectionIcon || NODE_ICONS[node.node_type] || HomeIcon;
|
||||
|
||||
const canExpand = node.has_children !== false
|
||||
&& node.node_type !== 'CalendarDay'
|
||||
&& node.node_type !== 'AcademicWeek'
|
||||
&& node.status !== 'empty'
|
||||
&& node.status !== 'no_school'
|
||||
&& node.status !== 'not_initialized';
|
||||
|
||||
const isActive = !isSection && node.neo4j_node_id === ctx.activeNodeId;
|
||||
const isEmpty = node.status === 'empty' || node.status === 'no_school' || node.status === 'not_initialized';
|
||||
|
||||
const displayChildren = isCalendarSection && ctx.calendarMode === 'academic'
|
||||
? ctx.academicTerms
|
||||
: children;
|
||||
|
||||
const academicEmpty = isCalendarSection
|
||||
&& ctx.calendarMode === 'academic'
|
||||
&& (ctx.academicCalendarStatus === 'empty' || ctx.academicCalendarStatus === 'idle');
|
||||
|
||||
const handleToggle = async (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!expanded && displayChildren.length === 0 && canExpand && !isCalendarSection) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const loaded = await onExpand(node);
|
||||
setChildren(loaded);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
setExpanded(v => !v);
|
||||
};
|
||||
|
||||
const handleClick = () => {
|
||||
if (!isSection) {
|
||||
onSelect(node);
|
||||
} else if (canExpand || (isCalendarSection && ctx.calendarMode === 'academic')) {
|
||||
handleToggle({ stopPropagation: () => {} } as React.MouseEvent);
|
||||
}
|
||||
};
|
||||
|
||||
// Derive action buttons per section
|
||||
const ss = ctx.schoolStatus;
|
||||
// School section: calendar setup (admin) or pending notice (non-admin)
|
||||
const showCalendarSetup = isSchoolSection
|
||||
&& ss && ss.status !== 'no_school'
|
||||
&& !ss.school_has_calendar && ss.user_role === 'school_admin';
|
||||
const showCalendarPending = isSchoolSection
|
||||
&& ss && ss.status !== 'no_school'
|
||||
&& !ss.school_has_calendar && ss.user_role !== 'school_admin';
|
||||
// Timetable section: teacher timetable setup (requires school calendar first)
|
||||
const showTimetableSetup = isTimetableSection && node.status === 'empty'
|
||||
&& ss && ss.status !== 'no_school'
|
||||
&& ss.school_has_calendar && !ss.teacher_has_timetable;
|
||||
const showLegacySetup = isTimetableSection && node.status === 'empty' && !ss;
|
||||
const showTimetableEdit = isTimetableSection && node.status === 'populated'
|
||||
&& ss && ss.status !== 'no_school' && !!ss.teacher_has_timetable;
|
||||
|
||||
if (isSection) {
|
||||
return (
|
||||
<Box>
|
||||
<Box
|
||||
onClick={handleClick}
|
||||
sx={{
|
||||
display: 'flex', alignItems: 'center',
|
||||
px: 1, py: 0.6,
|
||||
cursor: (canExpand || isCalendarSection) ? 'pointer' : 'default',
|
||||
mt: depth === 0 ? 0.5 : 0,
|
||||
borderRadius: 1,
|
||||
'&:hover': (canExpand || isCalendarSection) ? { bgcolor: 'action.hover' } : {},
|
||||
}}
|
||||
>
|
||||
<Box sx={{ width: 18, flexShrink: 0, display: 'flex', alignItems: 'center' }}>
|
||||
{(canExpand || (isCalendarSection && !academicEmpty)) && (
|
||||
loading
|
||||
? <CircularProgress size={10} />
|
||||
: (
|
||||
<IconButton size="small" sx={{ p: 0, color: 'text.secondary' }} onClick={handleToggle}>
|
||||
{expanded
|
||||
? <ExpandMore sx={{ fontSize: 14 }} />
|
||||
: <ChevronRightIcon sx={{ fontSize: 14 }} />}
|
||||
</IconButton>
|
||||
)
|
||||
)}
|
||||
{isEmpty && !isCalendarSection && !isTimetableSection && !isSchoolSection && (
|
||||
<Box sx={{ width: 18, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
{node.status === 'no_school'
|
||||
? <UnlinkedIcon sx={{ fontSize: 11, color: 'text.disabled' }} />
|
||||
: node.status === 'not_initialized'
|
||||
? <PendingIcon sx={{ fontSize: 11, color: 'text.disabled' }} />
|
||||
: null}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Icon sx={{ fontSize: 13, mr: 0.75, flexShrink: 0, color: isEmpty ? 'text.disabled' : 'primary.main', opacity: isEmpty ? 0.5 : 1 }} />
|
||||
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
fontWeight: 600, letterSpacing: '0.04em',
|
||||
textTransform: 'uppercase', fontSize: '0.68rem',
|
||||
color: isEmpty ? 'text.disabled' : 'text.secondary',
|
||||
flexGrow: 1, overflow: 'hidden',
|
||||
textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{node.label}
|
||||
</Typography>
|
||||
|
||||
{isEmpty && !isCalendarSection && !isTimetableSection && !isSchoolSection && node.status && (
|
||||
<Tooltip title={STATUS_MESSAGES[node.status]} placement="right">
|
||||
<Typography variant="caption" sx={{ fontSize: '0.6rem', color: 'text.disabled', ml: 0.5, flexShrink: 0 }}>
|
||||
{node.status === 'no_school' ? '—' : '…'}
|
||||
</Typography>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* Timetable section — role-aware action */}
|
||||
{showCalendarSetup && (
|
||||
<Tooltip title="Set up school calendar" placement="right">
|
||||
<IconButton
|
||||
size="small"
|
||||
sx={{ p: 0.25, ml: 0.5, color: 'primary.main' }}
|
||||
onClick={e => { e.stopPropagation(); ctx.onSetupSchoolCalendar(); }}
|
||||
>
|
||||
<SetupIcon sx={{ fontSize: 13 }} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{showCalendarPending && (
|
||||
<Tooltip title="School calendar not set up yet — contact your school admin" placement="right">
|
||||
<PendingIcon sx={{ fontSize: 11, color: 'text.disabled', ml: 0.5 }} />
|
||||
</Tooltip>
|
||||
)}
|
||||
{showTimetableSetup && (
|
||||
<Tooltip title="Set up my timetable" placement="right">
|
||||
<IconButton
|
||||
size="small"
|
||||
sx={{ p: 0.25, ml: 0.5, color: 'primary.main' }}
|
||||
onClick={e => { e.stopPropagation(); ctx.onSetupTimetable(); }}
|
||||
>
|
||||
<SetupIcon sx={{ fontSize: 13 }} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{showLegacySetup && (
|
||||
<Tooltip title="Set up timetable" placement="right">
|
||||
<IconButton
|
||||
size="small"
|
||||
sx={{ p: 0.25, ml: 0.5, color: 'primary.main' }}
|
||||
onClick={e => { e.stopPropagation(); ctx.onSetupTimetable(); }}
|
||||
>
|
||||
<SetupIcon sx={{ fontSize: 13 }} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{showTimetableEdit && (
|
||||
<Tooltip title="Edit my class schedule" placement="right">
|
||||
<IconButton
|
||||
size="small"
|
||||
sx={{ p: 0.25, ml: 0.5, color: 'text.secondary' }}
|
||||
onClick={e => { e.stopPropagation(); ctx.onSetupTimetable(); }}
|
||||
>
|
||||
<EditIcon sx={{ fontSize: 13 }} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* Calendar mode toggle */}
|
||||
{isCalendarSection && (
|
||||
<Box sx={{ px: 1.5, pb: 0.5 }}>
|
||||
<ToggleButtonGroup
|
||||
value={ctx.calendarMode}
|
||||
exclusive
|
||||
onChange={(_, v) => { if (v) ctx.setCalendarMode(v); }}
|
||||
size="small"
|
||||
sx={{ height: 22 }}
|
||||
>
|
||||
<ToggleButton value="generic" sx={{ px: 1, fontSize: '0.6rem', textTransform: 'none' }}>
|
||||
Generic
|
||||
</ToggleButton>
|
||||
<ToggleButton value="academic" sx={{ px: 1, fontSize: '0.6rem', textTransform: 'none' }}>
|
||||
Academic
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
{ctx.calendarMode === 'academic' && academicEmpty && (
|
||||
<Typography variant="caption" sx={{ display: 'block', color: 'text.disabled', fontSize: '0.6rem', mt: 0.5 }}>
|
||||
No academic calendar — set up school calendar first
|
||||
</Typography>
|
||||
)}
|
||||
{ctx.calendarMode === 'academic' && ctx.academicCalendarStatus === 'loading' && (
|
||||
<CircularProgress size={10} sx={{ mt: 0.5, ml: 0.5 }} />
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{(canExpand || (isCalendarSection && ctx.calendarMode === 'academic' && displayChildren.length > 0)) && (
|
||||
<Collapse in={expanded} timeout="auto">
|
||||
{displayChildren.map(child => (
|
||||
<TreeItem key={child.neo4j_node_id} node={child} depth={depth + 1}
|
||||
onSelect={onSelect} onExpand={onExpand} />
|
||||
))}
|
||||
</Collapse>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
// Regular navigable node
|
||||
return (
|
||||
<Box>
|
||||
<Box
|
||||
onClick={handleClick}
|
||||
sx={{
|
||||
display: 'flex', alignItems: 'center',
|
||||
pl: depth * 1.5 + 0.5, pr: 0.5, py: 0.35,
|
||||
cursor: 'pointer', borderRadius: 1, mx: 0.5,
|
||||
fontSize: '0.78rem', minHeight: 26,
|
||||
bgcolor: isActive ? 'action.selected' : 'transparent',
|
||||
'&:hover': { bgcolor: isActive ? 'action.selected' : 'action.hover' },
|
||||
}}
|
||||
>
|
||||
<Box sx={{ width: 18, flexShrink: 0, display: 'flex', alignItems: 'center' }}>
|
||||
{canExpand && (
|
||||
loading
|
||||
? <CircularProgress size={10} />
|
||||
: (
|
||||
<IconButton size="small" sx={{ p: 0, color: 'text.secondary' }} onClick={handleToggle}>
|
||||
{expanded
|
||||
? <ExpandMore sx={{ fontSize: 14 }} />
|
||||
: <ChevronRightIcon sx={{ fontSize: 14 }} />}
|
||||
</IconButton>
|
||||
)
|
||||
)}
|
||||
</Box>
|
||||
<Icon sx={{ fontSize: 13, mr: 0.75, flexShrink: 0, color: isActive ? 'primary.main' : 'text.secondary' }} />
|
||||
<Box sx={{
|
||||
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
flexGrow: 1, fontSize: '0.78rem',
|
||||
color: isActive ? 'primary.main' : 'text.primary',
|
||||
fontWeight: isActive ? 600 : 400,
|
||||
}}>
|
||||
{node.label}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{canExpand && (
|
||||
<Collapse in={expanded} timeout="auto">
|
||||
{children.map(child => (
|
||||
<TreeItem key={child.neo4j_node_id} node={child} depth={depth + 1}
|
||||
onSelect={onSelect} onExpand={onExpand} />
|
||||
))}
|
||||
</Collapse>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Main Panel ───────────────────────────────────────────────────────────────
|
||||
|
||||
export function CCGraphNavPanel() {
|
||||
const { accessToken } = useAuth();
|
||||
const { navigateToNeoNode, context } = useNavigationStore();
|
||||
const [tree, setTree] = useState<TreeNode | null>(null);
|
||||
const [schoolStatus, setSchoolStatus] = useState<SchoolStatus | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [calendarMode, setCalendarMode] = useState<CalendarMode>('generic');
|
||||
const [academicCalendarStatus, setAcademicCalendarStatus] = useState<NavPanelContextValue['academicCalendarStatus']>('idle');
|
||||
const [academicTerms, setAcademicTerms] = useState<TreeNode[]>([]);
|
||||
|
||||
const [calendarWizardOpen, setCalendarWizardOpen] = useState(false);
|
||||
const [timetableWizardOpen, setTimetableWizardOpen] = useState(false);
|
||||
|
||||
const apiBase = import.meta.env.VITE_API_BASE as string;
|
||||
const activeNodeId = context.node?.type !== 'workspace' ? context.node?.id : undefined;
|
||||
|
||||
const fetchTree = useCallback(async () => {
|
||||
if (!accessToken) return;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch(`${apiBase}/graph/tree`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!res.ok) throw new Error(`${res.status}`);
|
||||
const data = await res.json();
|
||||
setTree(data.tree);
|
||||
} catch (err) {
|
||||
logger.error('graph-nav-panel', 'Failed to load graph tree', err);
|
||||
setError('Failed to load navigation tree');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [accessToken, apiBase]);
|
||||
|
||||
const fetchSchoolStatus = useCallback(async () => {
|
||||
if (!accessToken) return;
|
||||
try {
|
||||
const res = await fetch(`${apiBase}/school/status`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
setSchoolStatus(data);
|
||||
} catch {
|
||||
// non-fatal — panel still works without school status
|
||||
}
|
||||
}, [accessToken, apiBase]);
|
||||
|
||||
useEffect(() => {
|
||||
if (accessToken && !tree) fetchTree();
|
||||
}, [accessToken, tree, fetchTree]);
|
||||
|
||||
useEffect(() => {
|
||||
if (accessToken && !schoolStatus) fetchSchoolStatus();
|
||||
}, [accessToken, schoolStatus, fetchSchoolStatus]);
|
||||
|
||||
// Fetch academic calendar when switching to academic mode
|
||||
useEffect(() => {
|
||||
if (calendarMode !== 'academic' || !accessToken) return;
|
||||
if (academicCalendarStatus !== 'idle') return;
|
||||
setAcademicCalendarStatus('loading');
|
||||
fetch(`${apiBase}/graph/calendar/academic`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.status === 'populated') {
|
||||
setAcademicTerms(data.terms);
|
||||
setAcademicCalendarStatus('populated');
|
||||
} else {
|
||||
setAcademicCalendarStatus(data.status || 'empty');
|
||||
}
|
||||
})
|
||||
.catch(() => setAcademicCalendarStatus('error'));
|
||||
}, [calendarMode, accessToken, apiBase, academicCalendarStatus]);
|
||||
|
||||
const handleSetCalendarMode = useCallback((m: CalendarMode) => {
|
||||
setCalendarMode(m);
|
||||
if (m === 'academic') setAcademicCalendarStatus('idle');
|
||||
}, []);
|
||||
|
||||
const handleExpand = useCallback(async (node: TreeNode): Promise<TreeNode[]> => {
|
||||
if (!accessToken) return [];
|
||||
const params = new URLSearchParams({
|
||||
neo4j_node_id: node.neo4j_node_id,
|
||||
neo4j_db_name: node.neo4j_db_name,
|
||||
node_type: node.node_type,
|
||||
section_id: node.section_id || '',
|
||||
});
|
||||
try {
|
||||
const res = await fetch(`${apiBase}/graph/node/children?${params}`, {
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json();
|
||||
return data.children || [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}, [accessToken, apiBase]);
|
||||
|
||||
const handleSelect = useCallback((node: TreeNode) => {
|
||||
if (!node.is_section) navigateToNeoNode(node);
|
||||
}, [navigateToNeoNode]);
|
||||
|
||||
const refreshAll = useCallback(() => {
|
||||
setTree(null);
|
||||
setSchoolStatus(null);
|
||||
setAcademicCalendarStatus('idle');
|
||||
setAcademicTerms([]);
|
||||
}, []);
|
||||
|
||||
const handleCalendarWizardComplete = useCallback(() => {
|
||||
logger.info('graph-nav-panel', 'School calendar setup complete');
|
||||
refreshAll();
|
||||
}, [refreshAll]);
|
||||
|
||||
const handleTimetableWizardComplete = useCallback((timetableId: string) => {
|
||||
logger.info('graph-nav-panel', 'Teacher timetable setup complete', { timetableId });
|
||||
refreshAll();
|
||||
}, [refreshAll]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', pt: 3 }}>
|
||||
<CircularProgress size={20} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box sx={{ p: 1.5, fontSize: '0.78rem', color: 'error.main' }}>
|
||||
{error}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (!tree) return null;
|
||||
|
||||
const ctxValue: NavPanelContextValue = {
|
||||
calendarMode,
|
||||
setCalendarMode: handleSetCalendarMode,
|
||||
academicCalendarStatus,
|
||||
academicTerms,
|
||||
schoolStatus,
|
||||
onSetupSchoolCalendar: () => setCalendarWizardOpen(true),
|
||||
onSetupTimetable: () => setTimetableWizardOpen(true),
|
||||
activeNodeId,
|
||||
};
|
||||
|
||||
const defaultSchoolInfo: SchoolInfo = {
|
||||
name: '', urn: '', website: '', address: {},
|
||||
headteacher: '', term_dates_url: '', staff_list_url: '',
|
||||
};
|
||||
|
||||
return (
|
||||
<NavPanelContext.Provider value={ctxValue}>
|
||||
<Box sx={{ pt: 0.5, pb: 2 }}>
|
||||
<TreeItem
|
||||
node={tree}
|
||||
depth={0}
|
||||
onSelect={handleSelect}
|
||||
onExpand={handleExpand}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{schoolStatus?.school_info && (
|
||||
<SchoolCalendarWizard
|
||||
open={calendarWizardOpen}
|
||||
onClose={() => setCalendarWizardOpen(false)}
|
||||
onComplete={handleCalendarWizardComplete}
|
||||
apiBase={apiBase}
|
||||
schoolInfo={schoolStatus.school_info || defaultSchoolInfo}
|
||||
/>
|
||||
)}
|
||||
|
||||
<TeacherTimetableWizard
|
||||
open={timetableWizardOpen}
|
||||
onClose={() => setTimetableWizardOpen(false)}
|
||||
onComplete={handleTimetableWizardComplete}
|
||||
apiBase={apiBase}
|
||||
periodsTemplate={schoolStatus?.periods_template || []}
|
||||
timetableId={schoolStatus?.timetable_id || null}
|
||||
/>
|
||||
</NavPanelContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user