Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display currently running robot run #417

Merged
merged 6 commits into from
Jan 30, 2025
Merged

feat: display currently running robot run #417

merged 6 commits into from
Jan 30, 2025

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented Jan 29, 2025

Closes: #416

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced run creation process with additional metadata tracking.
    • Improved URL-based navigation for run details.
  • Bug Fixes

    • Refined error handling for run creation and storage operations.
  • Improvements

    • Added robotMetaId to run response for better context.
    • Updated component logic to support dynamic run and recording navigation.
    • Streamlined URL parameter extraction and handling.

The updates focus on improving the user experience by providing more detailed run information and more intuitive navigation between runs and recordings.

@RohitR311 RohitR311 added Type: Enhancement Improvements to existing features Scope: UI/UX Issues/PRs related to UI/UX labels Jan 29, 2025
@RohitR311 RohitR311 requested a review from amhsirak January 29, 2025 18:28
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces enhancements to the application's run and recording management system by adding a new robotMetaId to various components and endpoints. The changes span multiple files in the server and client-side code, focusing on improving response structures, error handling, and URL-based navigation. The modifications enable better tracking and routing of robot runs by incorporating the robotMetaId throughout the application's workflow.

Changes

File Change Summary
server/src/routes/storage.ts Added robotMetaId to the PUT endpoint response and improved error logging.
src/api/storage.ts Updated createRunForStoredRecording to return robotMetaId in the response.
src/components/run/ColapsibleRow.tsx Added urlRunId prop and updated component logic for row expansion.
src/components/run/RunsTable.tsx Introduced URL parameter extraction and updated accordion rendering logic.
src/pages/MainPage.tsx Modified CreateRunResponse interface and navigation flow to use robotMetaId.

Possibly related PRs

  • feat: reset remote browser recording state #314: The main PR introduces the robotMetaId to the response object in the PUT endpoint, which is relevant to the changes in the createRunForStoredRecording function in the retrieved PR, where robotMetaId is also added to the return type, enhancing error handling.
  • feat: ability to update credentials for robots with authentication #363: The main PR's addition of robotMetaId aligns with the changes in the RobotEdit.tsx file, where the isLogin property is introduced, indicating a connection to managing robot states, including authentication.
  • feat: optimize robots and runs table ui #382: The changes in the RunsTable component regarding pagination and state management relate to the main PR's focus on enhancing the response structure, as both involve improving how data is handled and displayed.

Suggested labels

Type: Feature

Suggested reviewers

  • amhsirak

Poem

🐰 A Rabbit's Tale of Robot Runs 🤖
With metadata dancing light,
Our robot's journey takes its flight
Through URLs and tables bright,
A new path gleaming, clear and tight!
Hop along, dear code so fair! 🌟


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/run/RunsTable.tsx (1)

83-89: Consider using a more robust URL parsing approach.

While the current regex-based URL parameter extraction works, consider using a more maintainable approach.

Consider using the useParams hook from react-router-dom:

-const getUrlParams = () => {
-  const match = location.pathname.match(/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/);
-  return {
-    robotMetaId: match?.[1] || null,
-    urlRunId: match?.[2] || null
-  };
-};
+import { useParams } from 'react-router-dom';
+
+// In component:
+const { robotMetaId: urlRobotMetaId, runId: urlRunId } = useParams<{
+  robotMetaId: string;
+  runId: string;
+}>();
server/src/routes/storage.ts (1)

504-504: LGTM! Consider adding a type definition for the response.

The addition of robotMetaId to the response object is correct and aligns with the PR objective. However, to improve type safety and documentation, consider defining an interface for the response object.

+interface RunResponse {
+  browserId: string;
+  runId: string;
+  robotMetaId: string;
+}

 router.put('/runs/:id', requireSignIn, async (req: AuthenticatedRequest, res) => {
   try {
     // ... existing code ...

-    return res.send({
+    const response: RunResponse = {
       browserId: id,
       runId: plainRun.runId,
       robotMetaId: recording.recording_meta.id,
-    });
+    };
+    return res.send(response);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98ba962 and b4c5622.

📒 Files selected for processing (5)
  • server/src/routes/storage.ts (1 hunks)
  • src/api/storage.ts (1 hunks)
  • src/components/run/ColapsibleRow.tsx (2 hunks)
  • src/components/run/RunsTable.tsx (4 hunks)
  • src/pages/MainPage.tsx (4 hunks)
🔇 Additional comments (9)
src/pages/MainPage.tsx (3)

28-28: LGTM! Enhanced response type with robotMetaId.

The addition of robotMetaId to CreateRunResponse interface improves type safety and documentation.


45-46: LGTM! Proper state initialization.

The state initialization correctly includes the new robotMetaId field with an empty string default.


95-97: LGTM! Enhanced navigation with robotMetaId.

The navigation implementation properly uses both robotMetaId and runId for precise routing to specific runs.

src/api/storage.ts (1)

164-164: LGTM! Consistent error response structure.

The error case properly returns an object with empty strings for all fields, maintaining type safety and consistency with the success case.

src/components/run/ColapsibleRow.tsx (3)

38-38: LGTM! Added URL run ID prop.

The urlRunId prop enables the component to sync its state with URL parameters.


66-68: LGTM! Proper state synchronization.

The useEffect hook correctly synchronizes the open state with URL parameters and isOpen prop.


73-77: LGTM! Enhanced navigation logic.

The navigation implementation properly handles both expansion and collapse states using robotMetaId.

src/components/run/RunsTable.tsx (2)

93-95: LGTM! Clear accordion expansion logic.

The isAccordionExpanded function properly determines expansion state based on URL parameters.


263-267: LGTM! Comprehensive row state handling.

The row state properly considers both URL parameters and runtime state (current run).

Copy link
Member

@amhsirak amhsirak left a comment

Choose a reason for hiding this comment

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

@RohitR311 resolve conflicts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/run/RunsTable.tsx (3)

90-96: Enhance URL parameter handling robustness.

The URL parameter extraction could be more robust with validation and error handling.

Consider this enhanced implementation:

 const getUrlParams = () => {
-  const match = location.pathname.match(/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/);
+  try {
+    const match = location.pathname.match(/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/);
+    const robotMetaId = match?.[1];
+    const urlRunId = match?.[2];
+    
+    if (robotMetaId && !isValidRobotMetaId(robotMetaId)) {
+      console.warn(`Invalid robotMetaId format: ${robotMetaId}`);
+    }
+    
+    return {
+      robotMetaId: robotMetaId || null,
+      urlRunId: urlRunId || null
+    };
+  } catch (error) {
+    console.error('Error parsing URL parameters:', error);
+    return { robotMetaId: null, urlRunId: null };
+  }
 };

Add this helper function at the top of the file:

const isValidRobotMetaId = (id: string): boolean => {
  // Implement validation logic based on your robotMetaId format
  return /^[a-zA-Z0-9-_]+$/.test(id);
};

332-336: Simplify row expansion logic and consider prop drilling.

The row expansion logic could be simplified, and the urlRunId prop might indicate prop drilling.

Consider these improvements:

-          isOpen={urlRunId === row.runId || (runId === row.runId && runningRecordingName === row.name)}
+          isOpen={isRowExpanded(row, { urlRunId, runId, runningRecordingName })}
           currentLog={currentInterpretationLog}
           abortRunHandler={abortRunHandler}
           runningRecordingName={runningRecordingName}
-          urlRunId={urlRunId}
+          expansionState={{ urlRunId, runId, runningRecordingName }}

Add this helper function to improve readability:

const isRowExpanded = (
  row: Data,
  { urlRunId, runId, runningRecordingName }: {
    urlRunId: string | null;
    runId: string;
    runningRecordingName: string;
  }
): boolean => {
  const isUrlMatch = urlRunId === row.runId;
  const isRunningMatch = runId === row.runId && runningRecordingName === row.name;
  return isUrlMatch || isRunningMatch;
};

Consider using React Context if urlRunId is needed by multiple child components to avoid prop drilling.


Line range hint 1-479: Consider architectural improvements for better maintainability.

The component handles multiple responsibilities (URL parsing, data management, UI rendering) and could benefit from further modularization.

Consider these architectural improvements:

  1. Extract URL parameter handling into a custom hook:
// hooks/useRunsUrlParams.ts
export const useRunsUrlParams = () => {
  const location = useLocation();
  return useMemo(() => getUrlParams(location), [location]);
};
  1. Extract table state management into a separate context or custom hook:
// hooks/useRunsTableState.ts
export const useRunsTableState = (initialState: TableState) => {
  // Move pagination, sorting, and filtering logic here
};
  1. Consider splitting the component into smaller, focused components:
  • RunsTableHeader
  • RunsTableFilters
  • RunsTablePagination

This would improve maintainability and make the code easier to test.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4c5622 and 3efd413.

📒 Files selected for processing (1)
  • src/components/run/RunsTable.tsx (3 hunks)
🔇 Additional comments (1)
src/components/run/RunsTable.tsx (1)

100-102: LGTM! Clean and efficient implementation.

The accordion expansion logic is well-implemented with proper memoization and clear conditional logic.

@RohitR311 RohitR311 requested a review from amhsirak January 30, 2025 14:33
@amhsirak amhsirak merged commit bcb880f into develop Jan 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: UI/UX Issues/PRs related to UI/UX Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: redirect to currently executing run
2 participants