Skip to content
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
27 changes: 27 additions & 0 deletions apps/code/src/renderer/api/posthogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
AvailableSuggestedReviewersResponse,
SandboxEnvironment,
SandboxEnvironmentInput,
SignalProcessingStateResponse,
SignalReport,
SignalReportArtefact,
SignalReportArtefactsResponse,
Expand Down Expand Up @@ -1025,6 +1026,32 @@ export class PostHogAPIClient {
};
}

async getSignalProcessingState(): Promise<SignalProcessingStateResponse> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_processing/`,
);
const path = `/api/projects/${teamId}/signal_processing/`;

const response = await this.api.fetcher.fetch({
method: "get",
url,
path,
});

if (!response.ok) {
throw new Error(
`Failed to fetch signal processing state: ${response.statusText}`,
);
}

const data = await response.json();
return {
paused_until:
typeof data?.paused_until === "string" ? data.paused_until : null,
};
}

async getAvailableSuggestedReviewers(
query?: string,
): Promise<AvailableSuggestedReviewersResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { InboxSourcesDialog } from "@features/inbox/components/InboxSourcesDialo
import {
useInboxAvailableSuggestedReviewers,
useInboxReportsInfinite,
useInboxSignalProcessingState,
} from "@features/inbox/hooks/useInboxReports";
import { useSignalSourceConfigs } from "@features/inbox/hooks/useSignalSourceConfigs";
import { useInboxReportSelectionStore } from "@features/inbox/stores/inboxReportSelectionStore";
Expand Down Expand Up @@ -118,6 +119,13 @@ export function InboxSignalsTab() {
[allReports, searchQuery],
);

const { data: signalProcessingState } = useInboxSignalProcessingState({
enabled: isInboxView,
refetchInterval: inboxPollingActive ? INBOX_REFETCH_INTERVAL_MS : false,
refetchIntervalInBackground: false,
staleTime: inboxPollingActive ? INBOX_REFETCH_INTERVAL_MS : 12_000,
});

const readyCount = useMemo(
() => allReports.filter((r) => r.status === "ready").length,
[allReports],
Expand Down Expand Up @@ -378,6 +386,7 @@ export function InboxSignalsTab() {
livePolling={inboxPollingActive}
readyCount={readyCount}
processingCount={processingCount}
pipelinePausedUntil={signalProcessingState?.paused_until}
reports={reports}
/>
</Box>
Expand Down Expand Up @@ -447,6 +456,7 @@ export function InboxSignalsTab() {
totalCount={0}
filteredCount={0}
isSearchActive={false}
pipelinePausedUntil={signalProcessingState?.paused_until}
searchDisabledReason={searchDisabledReason}
hideFilters
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,46 @@ interface SignalsToolbarProps {
livePolling?: boolean;
readyCount?: number;
processingCount?: number;
pipelinePausedUntil?: string | null;
searchDisabledReason?: string | null;
hideFilters?: boolean;
reports?: SignalReport[];
}

function formatPauseRemaining(pausedUntil: string): string {
const diffMs = new Date(pausedUntil).getTime() - Date.now();

if (diffMs <= 0) {
return "resuming soon";
}

const totalMinutes = Math.ceil(diffMs / 60_000);

if (totalMinutes < 60) {
return `${totalMinutes}m`;
}

const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;

if (hours < 24) {
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
}

const days = Math.floor(hours / 24);
const remainingHours = hours % 24;

return remainingHours > 0 ? `${days}d ${remainingHours}h` : `${days}d`;
}

export function SignalsToolbar({
totalCount,
filteredCount,
isSearchActive,
livePolling = false,
readyCount,
processingCount = 0,
pipelinePausedUntil,
searchDisabledReason,
hideFilters,
reports = [],
Expand Down Expand Up @@ -79,10 +107,17 @@ export function SignalsToolbar({
? `${filteredCount} of ${totalCount}`
: `${totalCount}`;

const pipelineHint =
const pipelineHintParts = [
readyCount != null && processingCount > 0
? `${readyCount} ready · ${processingCount} in pipeline`
: null;
: null,
pipelinePausedUntil
? `Pipeline paused · resumes in ${formatPauseRemaining(pipelinePausedUntil)}`
: "Pipeline running",
].filter(Boolean);

const pipelineHint =
pipelineHintParts.length > 0 ? pipelineHintParts.join(" · ") : null;

const handleConfirmSuppress = async () => {
const ok = await suppressSelected();
Expand Down
15 changes: 15 additions & 0 deletions apps/code/src/renderer/features/inbox/hooks/useInboxReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useAuthenticatedInfiniteQuery } from "@hooks/useAuthenticatedInfiniteQu
import { useAuthenticatedQuery } from "@hooks/useAuthenticatedQuery";
import type {
AvailableSuggestedReviewersResponse,
SignalProcessingStateResponse,
SignalReportArtefactsResponse,
SignalReportSignalsResponse,
SignalReportsQueryParams,
Expand All @@ -32,6 +33,7 @@ const reportKeys = {
authIdentity ?? "anonymous",
"available-reviewers",
] as const,
signalProcessingState: ["inbox", "signal-processing-state"] as const,
};

export function useInboxReports(
Expand Down Expand Up @@ -149,6 +151,19 @@ export function useInboxAvailableSuggestedReviewers(options?: {
return query;
}

export function useInboxSignalProcessingState(options?: {
enabled?: boolean;
refetchInterval?: number | false | (() => number | false | undefined);
refetchIntervalInBackground?: boolean;
staleTime?: number;
}) {
return useAuthenticatedQuery<SignalProcessingStateResponse>(
reportKeys.signalProcessingState,
(client) => client.getSignalProcessingState(),
options,
);
}

export function useInboxReportArtefacts(
reportId: string,
options?: { enabled?: boolean },
Expand Down
4 changes: 4 additions & 0 deletions apps/code/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ export interface SignalReportsResponse {
count: number;
}

export interface SignalProcessingStateResponse {
paused_until: string | null;
}

export interface AvailableSuggestedReviewersResponse {
results: AvailableSuggestedReviewer[];
count: number;
Expand Down
Loading