Skip to content

Commit c762b57

Browse files
committed
Refactors Sidebar into modules and execution hook
Breaks the sidebar into focused sections (file, bay, edit, validation) to improve readability and maintainability Extracts script execution into a reusable hook that encapsulates mutation, loading state, and messaging for easier reuse and testing Centralizes sidebar-related types in a shared types module Moves the webhook inspector into its own directory and updates import paths Aims for no functional changes, only structural improvements
1 parent 2a8753a commit c762b57

File tree

10 files changed

+408
-211
lines changed

10 files changed

+408
-211
lines changed

src/components/Sidebar.tsx

Lines changed: 0 additions & 201 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react';
2+
import { CollapsibleSection } from '../CollapsibleSection';
3+
import { LocationSelector } from '../LocationSelector';
4+
import { BaySelector } from '../BaySelector';
5+
import { Bay, Location } from '../../types/sidebarTypes';
6+
7+
interface SidebarBayOperationsProps {
8+
selectedFacilityId: string | null;
9+
selectedLocationId: string | null;
10+
persistedLocationId: string | null;
11+
selectedBayId: string | null;
12+
persistedBayId: string | null;
13+
onLocationSelect: (location: Location | null) => void;
14+
onBaySelect: (bay: Bay | null) => void;
15+
canExecute: boolean;
16+
executing: boolean;
17+
execMessage: string | null;
18+
onExecuteScript: () => void;
19+
isValid: boolean;
20+
selectedBayObj: Bay | null;
21+
}
22+
23+
export const SidebarBayOperations: React.FC<SidebarBayOperationsProps> = ({
24+
selectedFacilityId,
25+
selectedLocationId,
26+
persistedLocationId,
27+
selectedBayId,
28+
persistedBayId,
29+
onLocationSelect,
30+
onBaySelect,
31+
canExecute,
32+
executing,
33+
execMessage,
34+
onExecuteScript,
35+
isValid,
36+
selectedBayObj,
37+
}) => {
38+
return (
39+
<CollapsibleSection
40+
title="Bay Operations"
41+
className="bay-operations-section"
42+
bodyClassName="bay-buttons"
43+
defaultOpen
44+
persistKey="bay-operations"
45+
>
46+
<LocationSelector
47+
selectedFacilityId={selectedFacilityId}
48+
selectedLocationId={selectedLocationId}
49+
persistedLocationId={persistedLocationId}
50+
onLocationSelect={onLocationSelect}
51+
/>
52+
<BaySelector
53+
selectedFacilityId={selectedFacilityId}
54+
selectedLocationId={selectedLocationId}
55+
selectedBayId={selectedBayId}
56+
persistedBayId={persistedBayId}
57+
onBaySelect={onBaySelect}
58+
/>
59+
<button
60+
className="tree-btn execute-btn"
61+
disabled={!canExecute || executing}
62+
onClick={onExecuteScript}
63+
title={!isValid ? 'Script must be valid' : !selectedBayObj ? 'Select a bay first' : 'Execute script on bay'}
64+
>
65+
{executing ? 'Executing...' : 'Execute Script'}
66+
</button>
67+
{execMessage && (
68+
<div className="exec-status small-note">{execMessage}</div>
69+
)}
70+
</CollapsibleSection>
71+
);
72+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
import { CollapsibleSection } from '../CollapsibleSection';
3+
import { TreeView } from '../TreeView';
4+
import { CloneSelectedButton, AddActivityButton, AddStepButton } from '../buttons';
5+
import { ScriptData, Activity, Step } from '../../types';
6+
7+
interface SidebarEditOperationsProps {
8+
script: ScriptData;
9+
selectedRef: { kind: 'script' } | { kind: 'activity'; activityId: string } | { kind: 'step'; activityId: string; stepId: string } | null;
10+
selectedNode: Activity | Step | null;
11+
isValid: boolean;
12+
parentActivityForAdd: Activity | undefined;
13+
onCloneSelected: () => void;
14+
onShowActivityDialog: () => void;
15+
onShowStepDialog: () => void;
16+
onSelectScript: () => void;
17+
onSelectActivity: (activityId: string) => void;
18+
onSelectStep: (activityId: string, stepId: string) => void;
19+
onDeleteActivity: (activityId: string) => void;
20+
onDeleteStep: (activityId: string, stepId: string) => void;
21+
}
22+
23+
export const SidebarEditOperations: React.FC<SidebarEditOperationsProps> = ({
24+
script,
25+
selectedRef,
26+
selectedNode,
27+
isValid,
28+
parentActivityForAdd,
29+
onCloneSelected,
30+
onShowActivityDialog,
31+
onShowStepDialog,
32+
onSelectScript,
33+
onSelectActivity,
34+
onSelectStep,
35+
onDeleteActivity,
36+
onDeleteStep,
37+
}) => {
38+
return (
39+
<CollapsibleSection
40+
title="Edit Operations"
41+
className="edit-operations-section"
42+
bodyClassName="edit-buttons"
43+
defaultOpen
44+
persistKey="edit-operations"
45+
>
46+
<CloneSelectedButton
47+
selectedNode={selectedNode}
48+
isValid={isValid}
49+
onClick={onCloneSelected}
50+
/>
51+
<AddActivityButton onClick={onShowActivityDialog} />
52+
<AddStepButton
53+
parentActivityForAdd={parentActivityForAdd}
54+
onShowStepDialog={onShowStepDialog}
55+
/>
56+
{/* Script Structure Tree */}
57+
<TreeView
58+
script={script}
59+
selectedRef={selectedRef}
60+
onSelectScript={onSelectScript}
61+
onSelectActivity={onSelectActivity}
62+
onSelectStep={onSelectStep}
63+
onDeleteActivity={onDeleteActivity}
64+
onDeleteStep={onDeleteStep}
65+
/>
66+
</CollapsibleSection>
67+
);
68+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { CollapsibleSection } from '../CollapsibleSection';
3+
import { LoadScriptButton, DownloadButton } from '../buttons';
4+
5+
interface SidebarFileOperationsProps {
6+
isValid: boolean;
7+
onLoadScript: () => void;
8+
onDownloadScript: () => void;
9+
}
10+
11+
export const SidebarFileOperations: React.FC<SidebarFileOperationsProps> = ({
12+
isValid,
13+
onLoadScript,
14+
onDownloadScript,
15+
}) => {
16+
return (
17+
<CollapsibleSection
18+
title="File Operations"
19+
className="file-operations-section"
20+
bodyClassName="file-buttons"
21+
defaultOpen
22+
persistKey="file-operations"
23+
>
24+
<LoadScriptButton onClick={onLoadScript} />
25+
<DownloadButton isValid={isValid} onClick={onDownloadScript} />
26+
</CollapsibleSection>
27+
);
28+
};

0 commit comments

Comments
 (0)