Skip to content

Commit db351c3

Browse files
committed
Tighten labeling and add label cleanup
1 parent a9259cb commit db351c3

22 files changed

Lines changed: 1591 additions & 131 deletions
3.55 MB
Loading

frontend/src/hooks/use-ops.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getApiUrl,
77
runMailboxBackfill,
88
runAutoLabel,
9+
runLabelCleanup,
910
runFullAnchorWorkflow,
1011
runOpsScan,
1112
runSafeCleanupWorkflow,
@@ -101,6 +102,20 @@ export function useRunMailboxBackfill() {
101102
});
102103
}
103104

105+
export function useRunLabelCleanup() {
106+
const invalidate = useInvalidateWorkspace();
107+
return useMutation({
108+
mutationFn: (timeRange: MailboxTimeRange) => runLabelCleanup(timeRange),
109+
onSuccess: (result) => {
110+
invalidate();
111+
toast.success("InboxAnchor labels removed", {
112+
description: `${result.count || 0} emails had InboxAnchor-generated labels removed without touching the messages.`,
113+
});
114+
},
115+
onError: (err) => toast.error(`Failed to clean labels: ${err.message}`),
116+
});
117+
}
118+
104119
export function useRunSafeCleanupWorkflow() {
105120
const invalidate = useInvalidateWorkspace();
106121
return useMutation({

frontend/src/lib/api-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ export interface OpsProgress {
546546
cached_count: number;
547547
hydrated_count: number;
548548
labeled_count: number;
549+
labels_removed_count: number;
549550
archived_count: number;
550551
marked_read_count: number;
551552
trashed_count: number;
@@ -601,6 +602,13 @@ export async function runAutoLabel(timeRange?: MailboxTimeRange): Promise<Workfl
601602
});
602603
}
603604

605+
export async function runLabelCleanup(timeRange?: MailboxTimeRange): Promise<WorkflowMutationResult> {
606+
return apiFetch<WorkflowMutationResult>("/ops/clean-labels", {
607+
method: "POST",
608+
body: JSON.stringify({ force_refresh: true, time_range: timeRange }),
609+
});
610+
}
611+
604612
export async function runSafeCleanupWorkflow(
605613
timeRange?: MailboxTimeRange,
606614
): Promise<WorkflowMutationResult> {

frontend/src/routes/index.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
useOpsOverview,
1010
useOpsProgress,
1111
useRunAutoLabel,
12+
useRunLabelCleanup,
1213
useRunMailboxBackfill,
1314
useRunFullAnchorWorkflow,
1415
useRunOpsScan,
@@ -21,6 +22,7 @@ import {
2122
Anchor,
2223
AlertTriangle,
2324
ArrowRight,
25+
Eraser,
2426
Inbox,
2527
Layers3,
2628
LogOut,
@@ -71,6 +73,7 @@ function CommandCenter() {
7173
const scanMutation = useRunOpsScan();
7274
const backfillMutation = useRunMailboxBackfill();
7375
const autoLabelMutation = useRunAutoLabel();
76+
const cleanLabelsMutation = useRunLabelCleanup();
7477
const cleanupMutation = useRunSafeCleanupWorkflow();
7578
const fullAnchorMutation = useRunFullAnchorWorkflow();
7679
const overviewError = error instanceof Error ? error.message : "InboxAnchor could not load the live mailbox overview yet.";
@@ -79,6 +82,7 @@ function CommandCenter() {
7982
scanMutation.isPending ||
8083
backfillMutation.isPending ||
8184
autoLabelMutation.isPending ||
85+
cleanLabelsMutation.isPending ||
8286
cleanupMutation.isPending ||
8387
fullAnchorMutation.isPending;
8488
const { data: progress } = useOpsProgress(timeRange, isLoading || busy);
@@ -95,6 +99,13 @@ function CommandCenter() {
9599
{ label: "Hydrated", value: progress.hydrated_count },
96100
{ label: "Batches", value: progress.batch_count },
97101
]
102+
: progress.latest_action === "remove_labels"
103+
? [
104+
{ label: "Emails read", value: progress.read_count },
105+
{ label: "Labels removed", value: progress.labels_removed_count },
106+
{ label: "Processed", value: progress.processed_count },
107+
{ label: "Remaining", value: Math.max(progress.target_count - progress.processed_count, 0) },
108+
]
98109
: progress.mode === "workflow"
99110
? [
100111
{ label: "Emails read", value: progress.read_count },
@@ -401,6 +412,15 @@ function CommandCenter() {
401412
loading={autoLabelMutation.isPending}
402413
onClick={() => autoLabelMutation.mutate(timeRange)}
403414
/>
415+
<WorkflowCard
416+
title="Reset InboxAnchor labels"
417+
icon={<Eraser className="h-4 w-4" />}
418+
description="Remove only InboxAnchor-generated labels from the selected mailbox window without deleting or archiving any email."
419+
impact={overview?.workflows.find((item) => item.slug === "clean-labels")?.impact}
420+
cta="Clean labels"
421+
loading={cleanLabelsMutation.isPending}
422+
onClick={() => cleanLabelsMutation.mutate(timeRange)}
423+
/>
404424
<WorkflowCard
405425
title="Safe cleanup"
406426
icon={<ShieldCheck className="h-4 w-4" />}

0 commit comments

Comments
 (0)