Skip to content

Conversation

@yomybaby
Copy link
Member

@yomybaby yomybaby commented Nov 5, 2025

Refactor session creation logic into useStartSession hook

Resolves #4591 (FR-1653)

Summary

This PR extracts the complex session creation logic from the SessionLauncherPage component into a reusable custom hook called useStartSession. This refactoring improves code organization, maintainability, and testability.

Changes

New File

  • react/src/hooks/useStartSession.tsx - Custom hook containing all session creation logic (~297 lines)
    • Handles session creation with all configuration options (batch, interactive, multiple sessions)
    • Manages error handling and notifications
    • Supports owner settings, resource allocation, and storage configuration

Modified File

  • react/src/pages/SessionLauncherPage.tsx - Refactored to use the new hook
    • Removed ~280 lines of embedded session creation logic
    • Simplified component to focus on UI concerns
    • Maintained all existing functionality and behavior

Benefits

  1. Better Separation of Concerns: UI logic separated from business logic
  2. Improved Testability: Session creation logic can now be tested in isolation
  3. Code Reusability: Hook can be used in other components if needed
  4. Easier Maintenance: Changes to session creation logic are now centralized
  5. Follows React Best Practices: Proper use of custom hooks for complex logic

Testing

All existing functionality has been preserved:

  • Session creation with various configurations
  • Batch mode and scheduling
  • Resource allocation
  • Storage mounting
  • Environment variables
  • Multiple session creation
  • Error handling and notifications
  • Navigation after creation

Checklist:

  • Code follows React best practices for custom hooks
  • All existing functionality is maintained
  • Error handling is preserved
  • No breaking changes to the API

@github-actions github-actions bot added the size:XL 500~ LoC label Nov 5, 2025
Copy link
Member Author

yomybaby commented Nov 5, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements 4.64% 531/11433
🔴 Branches 3.77% 302/8016
🔴 Functions 2.89% 102/3529
🔴 Lines 4.59% 513/11176

Test suite run success

121 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from 4c28ccd

@yomybaby yomybaby force-pushed the refactor/FR-1653-extract-session-creation-hook branch from c55bbb6 to 8fd2558 Compare November 5, 2025 10:45
@yomybaby yomybaby marked this pull request as ready for review November 5, 2025 10:45
Copilot AI review requested due to automatic review settings November 5, 2025 10:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors session creation logic by extracting it from SessionLauncherPage into a reusable custom hook useStartSession. The refactoring improves code organization and enables the session creation logic to be used in multiple locations throughout the application.

  • Extracted session creation logic into a new custom hook useStartSession
  • Moved related types, constants, and helper functions to the new hook file
  • Updated SessionLauncherPage to use the new hook instead of inline implementation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
react/src/hooks/useStartSession.tsx New custom hook containing the extracted session creation logic, types, and helper functions
react/src/pages/SessionLauncherPage.tsx Refactored to use the new useStartSession hook, removed inline session creation logic and unused imports
Comments suppressed due to low confidence (1)

react/src/hooks/useStartSession.tsx:34

  • Unknown directive: 'use memo'.
  'use memo';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yomybaby yomybaby force-pushed the refactor/FR-1653-extract-session-creation-hook branch 4 times, most recently from 767de63 to 346cb6a Compare November 5, 2025 11:10
Copy link
Contributor

@ironAiken2 ironAiken2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yomybaby yomybaby force-pushed the refactor/FR-1653-extract-session-creation-hook branch from 346cb6a to cf4df2e Compare November 6, 2025 03:15
@yomybaby yomybaby marked this pull request as draft November 6, 2025 03:17
@yomybaby yomybaby force-pushed the refactor/FR-1653-extract-session-creation-hook branch from cf4df2e to 601fe05 Compare November 6, 2025 03:50
@yomybaby yomybaby marked this pull request as ready for review November 6, 2025 03:50
Copy link
Contributor

@ironAiken2 ironAiken2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@nowgnuesLee nowgnuesLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@graphite-app
Copy link

graphite-app bot commented Nov 6, 2025

Merge activity

…n hook (#4592)

# Refactor session creation logic into useStartSession hook

Resolves #4591 ([FR-1653](https://lablup.atlassian.net/browse/FR-1653))

## Summary

This PR extracts the complex session creation logic from the `SessionLauncherPage` component into a reusable custom hook called `useStartSession`. This refactoring improves code organization, maintainability, and testability.

## Changes

### New File
- **[react/src/hooks/useStartSession.tsx](react/src/hooks/useStartSession.tsx)** - Custom hook containing all session creation logic (~297 lines)
  - Handles session creation with all configuration options (batch, interactive, multiple sessions)
  - Manages error handling and notifications
  - Supports owner settings, resource allocation, and storage configuration

### Modified File
- **[react/src/pages/SessionLauncherPage.tsx](react/src/pages/SessionLauncherPage.tsx)** - Refactored to use the new hook
  - Removed ~280 lines of embedded session creation logic
  - Simplified component to focus on UI concerns
  - Maintained all existing functionality and behavior

## Benefits

1. **Better Separation of Concerns**: UI logic separated from business logic
2. **Improved Testability**: Session creation logic can now be tested in isolation
3. **Code Reusability**: Hook can be used in other components if needed
4. **Easier Maintenance**: Changes to session creation logic are now centralized
5. **Follows React Best Practices**: Proper use of custom hooks for complex logic

## Testing

All existing functionality has been preserved:
- Session creation with various configurations
- Batch mode and scheduling
- Resource allocation
- Storage mounting
- Environment variables
- Multiple session creation
- Error handling and notifications
- Navigation after creation

**Checklist:**

- [x] Code follows React best practices for custom hooks
- [x] All existing functionality is maintained
- [x] Error handling is preserved
- [x] No breaking changes to the API

[FR-1653]: https://lablup.atlassian.net/browse/FR-1653?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
@graphite-app graphite-app bot force-pushed the refactor/FR-1653-extract-session-creation-hook branch from d27b474 to 4c28ccd Compare November 6, 2025 08:11
@graphite-app graphite-app bot merged commit 4c28ccd into main Nov 6, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract session creation logic into useStartSession hook for better code organization

4 participants