Skip to content

Renamed useBatch to useRealtimeBatch #1447

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

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-trains-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/react-hooks": patch
---

useBatch renamed to useRealtimeBatch
16 changes: 15 additions & 1 deletion packages/react-hooks/src/hooks/useRealtimeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ import { AnyTask, InferRunTypes, TaskRunShape } from "@trigger.dev/core/v3";
import { useEffect, useState } from "react";
import { useApiClient } from "./useApiClient.js";

export function useBatch<TTask extends AnyTask>(batchId: string) {
/**
* hook to subscribe to realtime updates of a batch of task runs.
*
* @template TTask - The type of the task.
* @param {string} batchId - The unique identifier of the batch to subscribe to.
* @returns {{ runs: TaskRunShape<TTask>[], error: Error | null }} An object containing the current state of the runs and any error encountered.
*
* @example
*
* ```ts
* import type { myTask } from './path/to/task';
* const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
* ```
*/
export function useRealtimeBatch<TTask extends AnyTask>(batchId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Breaking change: useBatch hook is still being used in the codebase

The renamed hook useRealtimeBatch has breaking changes that need to be addressed:

  • references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx: Still imports and uses useBatch from "@trigger.dev/react-hooks"
  • references/v3-catalog/src/trigger/taskHierarchy.ts: Contains useBatch parameter in multiple task definitions, but this appears to be unrelated to the hook (it's a boolean parameter with different functionality)
🔗 Analysis chain

Function rename improves clarity.

The new name useRealtimeBatch better describes the real-time nature of the hook's functionality.

Let's verify that all imports of the old name have been updated:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old function name 'useBatch'
# Expect: No occurrences of the old name, except in test files or comments

echo "Checking for remaining references to 'useBatch'..."
rg --type ts --type tsx 'useBatch' \
  --glob '!{**/*.test.*,**/*.spec.*}' \
  --glob '!**/dist/**' \
  --glob '!**/node_modules/**'

Length of output: 265


Script:

#!/bin/bash
# Let's try a different approach using ripgrep without file type filters
# and manually exclude test files and build directories

echo "Checking for remaining references to 'useBatch'..."
rg 'useBatch' \
  --type-not test \
  --glob '!{**/*.test.*,**/*.spec.*,**/__tests__/**}' \
  --glob '!{**/dist/**,**/build/**,**/node_modules/**}' \
  -C 2

Length of output: 286


Script:

#!/bin/bash
# Simplify the search using basic ripgrep command
# and pipe through grep to filter out test files

echo "Checking for remaining references to 'useBatch'..."
rg 'useBatch' -l | grep -v -E '(test|spec|__tests__|dist|build|node_modules)'

# Also search for export statements to verify the old name isn't exported elsewhere
echo -e "\nChecking for exports of 'useBatch'..."
rg 'export.*useBatch' -l | grep -v -E '(test|spec|__tests__|dist|build|node_modules)'

Length of output: 504


Script:

#!/bin/bash
# Let's check the actual content of the files that still reference 'useBatch'

echo "Checking content in taskHierarchy.ts:"
rg 'useBatch' -C 3 references/v3-catalog/src/trigger/taskHierarchy.ts

echo -e "\nChecking content in ClientBatchRunDetails.tsx:"
rg 'useBatch' -C 3 references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx

Length of output: 3023

const [runShapes, setRunShapes] = useState<TaskRunShape<TTask>[]>([]);
const [error, setError] = useState<Error | null>(null);
const apiClient = useApiClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Card, CardContent } from "@/components/ui/card";
import { TriggerAuthContext, useBatch } from "@trigger.dev/react-hooks";
import { TriggerAuthContext, useRealtimeBatch } from "@trigger.dev/react-hooks";
import type { exampleTask } from "@/trigger/example";

import { Badge } from "@/components/ui/badge";
Expand Down Expand Up @@ -117,7 +117,7 @@ export function BackgroundRunsTable({ runs }: { runs: TaskRunShape<typeof exampl
}

function BatchRunTableWrapper({ batchId }: { batchId: string }) {
const { runs, error } = useBatch<typeof exampleTask>(batchId);
const { runs, error } = useRealtimeBatch<typeof exampleTask>(batchId);

console.log(runs);

Expand Down