|
| 1 | +import React from 'react'; |
| 2 | +import { TopBar } from '../components/TopBar'; |
| 3 | +import { TabBar } from '../components/TabBar'; |
| 4 | +import { Sidebar } from '../components/Sidebar'; |
| 5 | +import { DialogManager } from '../components/DialogManager'; |
| 6 | +import { ScriptEditor } from '../components/ScriptEditor'; |
| 7 | +import { NodeEditor } from '../components/NodeEditor'; |
| 8 | +import { DocViewer } from '../components/DocViewer'; |
| 9 | +import WebhookView from '../components/WebhookView'; |
| 10 | + |
| 11 | +export type TabType = 'edit' | 'documentation' | 'webhook'; |
| 12 | + |
| 13 | +export interface AppShellProps { |
| 14 | + // the props below are a subset of the props used by the original App |
| 15 | + selectedFacility: any; |
| 16 | + selectedFacilityId: string | null; |
| 17 | + onFacilitySelect: (f: any) => void; |
| 18 | + activeTab: TabType; |
| 19 | + setActiveTab: (t: TabType) => void; |
| 20 | + // editor state and handlers (kept generic to avoid tight coupling in this step) |
| 21 | + state: any; |
| 22 | + script: any; |
| 23 | + isValid: boolean; |
| 24 | + validationErrors: any[]; |
| 25 | + selections: any; |
| 26 | + selectedLocation: any; |
| 27 | + selectedBayObj: any; |
| 28 | + onLoadScript: () => void; |
| 29 | + onDownloadScript: () => void; |
| 30 | + onLocationSelect: (l: any) => void; |
| 31 | + onBaySelect: (b: any) => void; |
| 32 | + dispatch: any; |
| 33 | +} |
| 34 | + |
| 35 | +export const AppShell: React.FC<AppShellProps> = (props) => { |
| 36 | + const { |
| 37 | + selectedFacility, |
| 38 | + selectedFacilityId, |
| 39 | + onFacilitySelect, |
| 40 | + activeTab, |
| 41 | + setActiveTab, |
| 42 | + state, |
| 43 | + script, |
| 44 | + isValid, |
| 45 | + validationErrors, |
| 46 | + selections, |
| 47 | + selectedLocation, |
| 48 | + selectedBayObj, |
| 49 | + onLoadScript, |
| 50 | + onDownloadScript, |
| 51 | + onLocationSelect, |
| 52 | + onBaySelect, |
| 53 | + dispatch |
| 54 | + } = props; |
| 55 | + |
| 56 | + const selectedNode = (() => { |
| 57 | + try { return (state && state.selectedRef && state.selectedRef.kind !== 'script') ? state.selectedRef : null; } catch { return null; } |
| 58 | + })(); |
| 59 | + |
| 60 | + return ( |
| 61 | + <div className="app-container"> |
| 62 | + <TopBar |
| 63 | + selectedFacility={selectedFacility} |
| 64 | + selectedFacilityId={selectedFacilityId} |
| 65 | + onFacilitySelect={onFacilitySelect} |
| 66 | + /> |
| 67 | + <TabBar |
| 68 | + activeTab={activeTab} |
| 69 | + onTabChange={setActiveTab} |
| 70 | + /> |
| 71 | + |
| 72 | + {activeTab === 'edit' ? ( |
| 73 | + <div className="tree-flex"> |
| 74 | + <DialogManager |
| 75 | + // dialog props are expected to be provided via dispatch or parent |
| 76 | + showActivityDialog={false} |
| 77 | + showStepDialog={false} |
| 78 | + onCloseActivityDialog={() => {}} |
| 79 | + onCloseStepDialog={() => {}} |
| 80 | + onAddActivity={() => {}} |
| 81 | + onAddStep={() => {}} |
| 82 | + parentActivityForAdd={undefined} |
| 83 | + /> |
| 84 | + <Sidebar |
| 85 | + script={script} |
| 86 | + selectedRef={state.selectedRef} |
| 87 | + selectedNode={selectedNode} |
| 88 | + isValid={isValid} |
| 89 | + validationErrors={validationErrors} |
| 90 | + selectedFacilityId={selectedFacilityId} |
| 91 | + selectedLocationId={selectedLocation?.id || null} |
| 92 | + persistedLocationId={selections?.locationId || null} |
| 93 | + selectedBayId={selectedBayObj?.id || null} |
| 94 | + persistedBayId={selections?.bayId || null} |
| 95 | + selectedBayObj={selectedBayObj} |
| 96 | + onLoadScript={onLoadScript} |
| 97 | + onDownloadScript={onDownloadScript} |
| 98 | + onLocationSelect={onLocationSelect} |
| 99 | + onBaySelect={onBaySelect} |
| 100 | + onCloneSelected={() => dispatch({ type: 'CLONE_SELECTED' })} |
| 101 | + onShowActivityDialog={() => {}} |
| 102 | + onShowStepDialog={() => {}} |
| 103 | + onSelectScript={() => dispatch({ type: 'SELECT_SCRIPT' })} |
| 104 | + onSelectActivity={(activityId: string) => dispatch({ type: 'SELECT_ACTIVITY', activityId })} |
| 105 | + onSelectStep={(activityId: string, stepId: string) => dispatch({ type: 'SELECT_STEP', activityId, stepId })} |
| 106 | + onDeleteActivity={(id: string) => dispatch({ type: 'DELETE_ACTIVITY', activityId: id })} |
| 107 | + onDeleteStep={(activityId: string, stepId: string) => dispatch({ type: 'DELETE_STEP', activityId, stepId })} |
| 108 | + parentActivityForAdd={undefined} |
| 109 | + /> |
| 110 | + |
| 111 | + <div className="tree-main"> |
| 112 | + {state.selectedRef?.kind === 'script' ? ( |
| 113 | + <> |
| 114 | + <h2>Script Configuration</h2> |
| 115 | + <ScriptEditor |
| 116 | + script={script} |
| 117 | + onChange={(s: any) => dispatch({ type: 'LOAD_SCRIPT', script: s })} |
| 118 | + /> |
| 119 | + <pre>{JSON.stringify(script, null, 2)}</pre> |
| 120 | + </> |
| 121 | + ) : selectedNode ? ( |
| 122 | + <NodeEditor |
| 123 | + node={selectedNode} |
| 124 | + onUpdateActivity={(activityId: string, patch: any) => dispatch({ type: 'UPDATE_ACTIVITY', activityId, patch })} |
| 125 | + onUpdateStep={(stepId: string, patch: any) => dispatch({ type: 'UPDATE_STEP', stepId, patch })} |
| 126 | + /> |
| 127 | + ) : ( |
| 128 | + <div className="empty-node-editor">Select a node to edit its details.</div> |
| 129 | + )} |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + ) : activeTab === 'documentation' ? ( |
| 133 | + <div className="documentation-flex"> |
| 134 | + <DocViewer /> |
| 135 | + </div> |
| 136 | + ) : activeTab === 'webhook' ? ( |
| 137 | + <div className="documentation-flex"> |
| 138 | + <WebhookView selectedBayDbId={selectedBayObj?.dbId ?? null} /> |
| 139 | + </div> |
| 140 | + ) : null} |
| 141 | + </div> |
| 142 | + ); |
| 143 | +}; |
| 144 | + |
| 145 | +export default AppShell; |
0 commit comments