Skip to content

Commit 0b33b5c

Browse files
committed
Refactor plan creation flow and update routes
Removed the '/plan/:planId/create' route and updated navigation to use '/plan/:planId' after plan creation. Made 'team_id' mandatory in InputTask, cleaned up code formatting, and clarified comments. This streamlines the plan creation process and ensures consistent routing and data requirements.
1 parent dba758b commit 0b33b5c

File tree

6 files changed

+73
-75
lines changed

6 files changed

+73
-75
lines changed

src/frontend/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function App() {
88
<Router>
99
<Routes>
1010
<Route path="/" element={<HomePage />} />
11-
<Route path="/plan/:planId/create" element={<PlanCreatePage />} />
1211
<Route path="/plan/:planId" element={<PlanPage />} />
1312
<Route path="*" element={<Navigate to="/" replace />} />
1413
</Routes>

src/frontend/src/api/apiService.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class APIService {
127127
async getPlans(sessionId?: string, useCache = true): Promise<PlanWithSteps[]> {
128128
const cacheKey = `plans_${sessionId || 'all'}`;
129129
const params = sessionId ? { session_id: sessionId } : {};
130-
130+
// TODO replace session for team_id
131131
const fetcher = async () => {
132132
const data = await apiClient.get(API_ENDPOINTS.PLANS, { params });
133133
if (useCache) {

src/frontend/src/components/content/HomeInput.tsx

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,36 @@ import { Send } from "@/coral/imports/bundleicons";
4040

4141
// Icon mapping function to convert string icons to FluentUI icons
4242
const getIconFromString = (iconString: string | React.ReactNode): React.ReactNode => {
43-
// If it's already a React node, return it
44-
if (typeof iconString !== 'string') {
45-
return iconString;
46-
}
47-
48-
const iconMap: Record<string, React.ReactNode> = {
49-
// Task/Logo icons
50-
'Wrench': <Wrench20Regular />,
51-
'TestTube': <Clipboard20Regular />, // Fallback since TestTube20Regular doesn't exist
52-
'Terminal': <WindowConsole20Regular />,
53-
'MonitorCog': <Desktop20Regular />,
54-
'BookMarked': <BookmarkMultiple20Regular />,
55-
'Search': <Search20Regular />,
56-
'Robot': <Person20Regular />, // Fallback since Robot20Regular doesn't exist
57-
'Code': <Code20Regular />,
58-
'Play': <Play20Regular />,
59-
'Shield': <Shield20Regular />,
60-
'Globe': <Globe20Regular />,
61-
'Person': <Person20Regular />,
62-
'Database': <Database20Regular />,
63-
'Document': <Document20Regular />,
64-
'Building': <Building20Regular />,
65-
'Desktop': <Desktop20Regular />,
66-
67-
// Default fallback
68-
'📋': <Clipboard20Regular />,
69-
'default': <Clipboard20Regular />,
70-
};
71-
72-
return iconMap[iconString] || iconMap['default'] || <Clipboard20Regular />;
43+
// If it's already a React node, return it
44+
if (typeof iconString !== 'string') {
45+
return iconString;
46+
}
47+
48+
const iconMap: Record<string, React.ReactNode> = {
49+
// Task/Logo icons
50+
'Wrench': <Wrench20Regular />,
51+
'TestTube': <Clipboard20Regular />, // Fallback since TestTube20Regular doesn't exist
52+
'Terminal': <WindowConsole20Regular />,
53+
'MonitorCog': <Desktop20Regular />,
54+
'BookMarked': <BookmarkMultiple20Regular />,
55+
'Search': <Search20Regular />,
56+
'Robot': <Person20Regular />, // Fallback since Robot20Regular doesn't exist
57+
'Code': <Code20Regular />,
58+
'Play': <Play20Regular />,
59+
'Shield': <Shield20Regular />,
60+
'Globe': <Globe20Regular />,
61+
'Person': <Person20Regular />,
62+
'Database': <Database20Regular />,
63+
'Document': <Document20Regular />,
64+
'Building': <Building20Regular />,
65+
'Desktop': <Desktop20Regular />,
66+
67+
// Default fallback
68+
'📋': <Clipboard20Regular />,
69+
'default': <Clipboard20Regular />,
70+
};
71+
72+
return iconMap[iconString] || iconMap['default'] || <Clipboard20Regular />;
7373
};
7474

7575
const HomeInput: React.FC<HomeInputProps> = ({
@@ -114,7 +114,7 @@ const HomeInput: React.FC<HomeInputProps> = ({
114114

115115
try {
116116
const response = await TaskService.createPlan(
117-
input.trim(),
117+
input.trim(),
118118
selectedTeam?.team_id
119119
);
120120
setInput("");
@@ -126,17 +126,17 @@ const HomeInput: React.FC<HomeInputProps> = ({
126126
if (response.plan_id && response.plan_id !== null) {
127127
showToast("Plan created!", "success");
128128
dismissToast(id);
129-
129+
130130
// Navigate to create page (no team ID in URL anymore)
131131
console.log('HomeInput: Navigating to plan creation with team:', selectedTeam?.name);
132-
navigate(`/plan/${response.plan_id}/create`);
132+
navigate(`/plan/${response.plan_id}`);
133133
} else {
134134
showToast("Failed to create plan", "error");
135135
dismissToast(id);
136136
}
137137
} catch (error: any) {
138138
dismissToast(id);
139-
139+
140140
// Check if this is an RAI validation error
141141
let errorDetail = null;
142142
try {
@@ -156,11 +156,11 @@ const HomeInput: React.FC<HomeInputProps> = ({
156156
setRAIError(errorDetail);
157157
} else {
158158
// Handle other errors with toast messages
159-
const errorMessage = errorDetail?.description ||
160-
errorDetail?.message ||
161-
error?.response?.data?.message ||
162-
error?.message ||
163-
"Something went wrong";
159+
const errorMessage = errorDetail?.description ||
160+
errorDetail?.message ||
161+
error?.response?.data?.message ||
162+
error?.message ||
163+
"Something went wrong";
164164
showToast(errorMessage, "error");
165165
}
166166

@@ -188,7 +188,7 @@ const HomeInput: React.FC<HomeInputProps> = ({
188188
}, [input]);
189189

190190
// Convert team starting_tasks to QuickTask format
191-
const tasksToDisplay: QuickTask[] = selectedTeam && selectedTeam.starting_tasks ?
191+
const tasksToDisplay: QuickTask[] = selectedTeam && selectedTeam.starting_tasks ?
192192
selectedTeam.starting_tasks.map((task, index) => {
193193
// Handle both string tasks and StartingTask objects
194194
if (typeof task === 'string') {
@@ -273,17 +273,17 @@ const HomeInput: React.FC<HomeInputProps> = ({
273273
</>
274274
)}
275275
{tasksToDisplay.length === 0 && selectedTeam && (
276-
<div style={{
277-
textAlign: 'center',
276+
<div style={{
277+
textAlign: 'center',
278278
padding: '32px 16px',
279279
color: '#666'
280280
}}>
281281
<Caption1>No starting tasks available for this team</Caption1>
282282
</div>
283283
)}
284284
{!selectedTeam && (
285-
<div style={{
286-
textAlign: 'center',
285+
<div style={{
286+
textAlign: 'center',
287287
padding: '32px 16px',
288288
color: '#666'
289289
}}>

src/frontend/src/models/inputTask.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export interface InputTask {
66
session_id?: string;
77
/** The task description or goal */
88
description: string;
9-
/** Optional team identifier to use for this plan */
10-
team_id?: string;
9+
/** MANDATORY team identifier to use for this plan */
10+
team_id: string;
1111
}
1212

1313
/**

src/frontend/src/pages/HomePage.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ const HomePage: React.FC = () => {
111111
try {
112112
const teams = await TeamService.getUserTeams();
113113
console.log('Teams refreshed after upload:', teams.length);
114-
114+
115115
if (teams.length > 0) {
116116
// Always keep "Business Operations Team" as default, even after new uploads
117117
const businessOpsTeam = teams.find(team => team.name === "Business Operations Team");
118118
const defaultTeam = businessOpsTeam || teams[0];
119119
setSelectedTeam(defaultTeam);
120120
console.log('Default team after upload:', defaultTeam.name);
121121
console.log('Business Operations Team remains default');
122-
122+
123123
// Show a toast notification about the upload success
124124
dispatchToast(
125125
<Toast>
@@ -144,10 +144,10 @@ const HomePage: React.FC = () => {
144144
if (taskName.trim()) {
145145
try {
146146
const response = await TaskService.createPlan(
147-
taskName.trim(),
147+
taskName.trim(),
148148
selectedTeam?.team_id
149149
);
150-
150+
151151
if (response.plan_id && response.plan_id !== null) {
152152
dispatchToast(
153153
<Toast>
@@ -159,10 +159,10 @@ const HomePage: React.FC = () => {
159159
</Toast>,
160160
{ intent: "success" }
161161
);
162-
162+
163163
// Navigate to create page (no team ID in URL anymore)
164164
console.log('Navigating to plan creation with team:', selectedTeam?.name);
165-
navigate(`/plan/${response.plan_id}/create`);
165+
navigate(`/plan/${response.plan_id}`);
166166
} else {
167167
dispatchToast(
168168
<Toast>
@@ -213,11 +213,11 @@ const HomePage: React.FC = () => {
213213
selectedTeam={selectedTeam}
214214
/>
215215
) : (
216-
<div style={{
217-
display: 'flex',
218-
justifyContent: 'center',
219-
alignItems: 'center',
220-
height: '200px'
216+
<div style={{
217+
display: 'flex',
218+
justifyContent: 'center',
219+
alignItems: 'center',
220+
height: '200px'
221221
}}>
222222
<Spinner label="Loading team configuration..." />
223223
</div>

src/frontend/src/pages/PlanCreatePage.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { TeamService } from "../services/TeamService";
2929

3030
/**
3131
* Page component for creating and viewing a plan being generated
32-
* Accessible via the route /plan/{plan_id}/create/{team_id?}
3332
*/
3433
const PlanCreatePage: React.FC = () => {
3534
const { planId, teamId } = useParams<{ planId: string; teamId?: string }>();
@@ -81,7 +80,7 @@ const PlanCreatePage: React.FC = () => {
8180
}
8281
}
8382
};
84-
83+
8584
loadTeamData();
8685
}, [teamId]);
8786

@@ -98,9 +97,9 @@ const PlanCreatePage: React.FC = () => {
9897
try {
9998
setLoading(true);
10099
setError(null);
101-
100+
102101
let toastId = showToast("Generating plan steps...", "progress");
103-
102+
104103
// Call the generate_plan endpoint using apiClient for proper authentication
105104
const result = await apiClient.post('/generate_plan', {
106105
plan_id: planId
@@ -109,10 +108,10 @@ const PlanCreatePage: React.FC = () => {
109108
dismissToast(toastId);
110109
showToast("Plan generated successfully!", "success");
111110
setPlanGenerated(true);
112-
111+
113112
// Now load the plan data to display it
114113
await loadPlanData(false);
115-
114+
116115
} catch (err) {
117116
console.error("Failed to generate plan:", err);
118117
setError(
@@ -145,12 +144,12 @@ const PlanCreatePage: React.FC = () => {
145144
plans.push(data);
146145
}
147146
setAllPlans(plans);
148-
147+
149148
// If plan has steps and we haven't generated yet, mark as generated
150149
if (data.plan.steps && data.plan.steps.length > 0 && !planGenerated) {
151150
setPlanGenerated(true);
152151
}
153-
152+
154153
} catch (err) {
155154
console.log("Failed to load plan data:", err);
156155
setError(
@@ -186,7 +185,7 @@ const PlanCreatePage: React.FC = () => {
186185
await loadPlanData(false);
187186
} catch (error: any) {
188187
dismissToast(id);
189-
188+
190189
// Check if this is an RAI validation error
191190
let errorDetail = null;
192191
try {
@@ -246,7 +245,7 @@ const PlanCreatePage: React.FC = () => {
246245
// Load the basic plan data first
247246
await loadPlanData(true);
248247
};
249-
248+
250249
initializePage();
251250
}, []);
252251

@@ -272,10 +271,10 @@ const PlanCreatePage: React.FC = () => {
272271
return (
273272
<CoralShellColumn>
274273
<CoralShellRow>
275-
<PlanPanelLeft
276-
onNewTaskButton={handleNewTaskButton}
277-
reloadTasks={reloadLeftList}
278-
restReload={()=>setReloadLeftList(false)}
274+
<PlanPanelLeft
275+
onNewTaskButton={handleNewTaskButton}
276+
reloadTasks={reloadLeftList}
277+
restReload={() => setReloadLeftList(false)}
279278
selectedTeam={selectedTeam}
280279
/>
281280

@@ -300,7 +299,7 @@ const PlanCreatePage: React.FC = () => {
300299
/>
301300
</PanelRightToggles>
302301
</ContentToolbar>
303-
302+
304303
{/* Show RAI error if present */}
305304
{raiError && (
306305
<div style={{ padding: '16px 24px 0' }}>
@@ -313,7 +312,7 @@ const PlanCreatePage: React.FC = () => {
313312
/>
314313
</div>
315314
)}
316-
315+
317316
<PlanChat
318317
planData={planData}
319318
OnChatSubmit={handleOnchatSubmit}

0 commit comments

Comments
 (0)