Skip to content

Commit 469e94c

Browse files
committed
Fix hidden circular dependency in watched folders code
1 parent 7aeec93 commit 469e94c

6 files changed

Lines changed: 52 additions & 42 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ pipeline/
2222
customFiles/
2323
configs/
2424
watchedFolders/
25+
# The rule above targets the app's runtime watched-folders working dir, but it
26+
# also matches this frontend source component dir; keep the source tracked.
27+
!frontend/editor/src/proprietary/components/watchedFolders/
2528
clientWebUI/
2629
# Scratch dir used by local fixture-regeneration runs (see
2730
# app/proprietary/src/test/resources/db-migration-fixtures/README.md).

frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderHomePage.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,10 @@ import { useNavigationActions } from "@app/contexts/NavigationContext";
3232
import {
3333
WATCHED_FOLDER_VIEW_ID,
3434
WATCHED_FOLDER_WORKBENCH_ID,
35-
} from "@app/components/watchedFolders/WatchedFoldersRegistration";
36-
import { timeAgo } from "@app/components/watchedFolders/WatchedFolderWorkbenchView";
35+
timeAgo,
36+
} from "@app/components/watchedFolders/watchedFolderShared";
3737
import "@app/components/watchedFolders/WatchedFolders.css";
3838

39-
export function humaniseOp(op: string): string {
40-
return op
41-
.replace(/-pdf$|-pages$|-documents?$/i, "")
42-
.replace(/[-_]/g, " ")
43-
.replace(/\bocr\b/gi, "OCR")
44-
.replace(/\b\w/g, (c) => c.toUpperCase())
45-
.trim();
46-
}
47-
4839
interface FolderCardProps {
4940
folder: WatchedFolder;
5041
status: "idle" | "processing" | "done";

frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { automationStorage } from "@app/services/automationStorage";
1616
import {
1717
WATCHED_FOLDER_VIEW_ID,
1818
WATCHED_FOLDER_WORKBENCH_ID,
19-
} from "@app/components/watchedFolders/WatchedFoldersRegistration";
19+
} from "@app/components/watchedFolders/watchedFolderShared";
2020

2121
export function WatchedFolderSection() {
2222
const { t } = useTranslation();

frontend/editor/src/proprietary/components/watchedFolders/WatchedFolderWorkbenchView.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ import { useToolWorkflow } from "@app/contexts/ToolWorkflowContext";
4747
import {
4848
WATCHED_FOLDER_VIEW_ID,
4949
WATCHED_FOLDER_WORKBENCH_ID,
50-
} from "@app/components/watchedFolders/WatchedFoldersRegistration";
50+
timeAgo,
51+
humaniseOp,
52+
} from "@app/components/watchedFolders/watchedFolderShared";
5153
import { automationStorage } from "@app/services/automationStorage";
5254
import {
5355
useFolderAutomation,
@@ -58,10 +60,7 @@ import { AutomationConfig } from "@app/types/automation";
5860
import { iconMap } from "@app/components/tools/automate/iconMap";
5961
import { fileStorage } from "@app/services/fileStorage";
6062
import { FileId, StirlingFile } from "@app/types/fileContext";
61-
import {
62-
WatchedFolderHomePage,
63-
humaniseOp,
64-
} from "@app/components/watchedFolders/WatchedFolderHomePage";
63+
import { WatchedFolderHomePage } from "@app/components/watchedFolders/WatchedFolderHomePage";
6564
import { useNavigationActions } from "@app/contexts/NavigationContext";
6665
import { FilePreviewModal } from "@app/components/watchedFolders/FilePreviewModal";
6766
import { folderDirectoryHandleStorage } from "@app/services/folderDirectoryHandleStorage";
@@ -174,28 +173,6 @@ interface WatchedFolderWorkbenchViewProps {
174173
};
175174
}
176175

177-
export function timeAgo(date: Date, t: TFunction): string {
178-
const secs = Math.floor((Date.now() - date.getTime()) / 1000);
179-
if (secs < 60) return t("watchedFolders.time.justNow", "just now");
180-
const mins = Math.floor(secs / 60);
181-
if (mins < 60)
182-
return t("watchedFolders.time.minutesAgo", {
183-
count: mins,
184-
defaultValue: `${mins}m ago`,
185-
});
186-
const hours = Math.floor(mins / 60);
187-
if (hours < 24)
188-
return t("watchedFolders.time.hoursAgo", {
189-
count: hours,
190-
defaultValue: `${hours}h ago`,
191-
});
192-
const days = Math.floor(hours / 24);
193-
return t("watchedFolders.time.daysAgo", {
194-
count: days,
195-
defaultValue: `${days}d ago`,
196-
});
197-
}
198-
199176
function RetryCountdown({
200177
nextRetryAt,
201178
t,

frontend/editor/src/proprietary/components/watchedFolders/WatchedFoldersRegistration.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { useToolWorkflow } from "@app/contexts/ToolWorkflowContext";
44
import { WatchedFolderWorkbenchView } from "@app/components/watchedFolders/WatchedFolderWorkbenchView";
55
import { seedDefaultFolders } from "@app/data/watchedFolderPresets";
66
import { useWatchedFolderUrlSync } from "@app/hooks/useWatchedFolderUrlSync";
7-
8-
export const WATCHED_FOLDER_VIEW_ID = "watchedFolder";
9-
export const WATCHED_FOLDER_WORKBENCH_ID = "custom:watchedFolder" as const;
7+
import {
8+
WATCHED_FOLDER_VIEW_ID,
9+
WATCHED_FOLDER_WORKBENCH_ID,
10+
} from "@app/components/watchedFolders/watchedFolderShared";
1011

1112
export default function WatchedFoldersRegistration() {
1213
const { t } = useTranslation();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Leaf module for the watched-folders trio (registration, workbench view, home
2+
// page): the shared view IDs plus small pure formatters. Kept dependency-free so
3+
// those three components don't have to import one another and form a cycle.
4+
import type { TFunction } from "i18next";
5+
6+
export const WATCHED_FOLDER_VIEW_ID = "watchedFolder";
7+
export const WATCHED_FOLDER_WORKBENCH_ID = "custom:watchedFolder" as const;
8+
9+
export function timeAgo(date: Date, t: TFunction): string {
10+
const secs = Math.floor((Date.now() - date.getTime()) / 1000);
11+
if (secs < 60) return t("watchedFolders.time.justNow", "just now");
12+
const mins = Math.floor(secs / 60);
13+
if (mins < 60)
14+
return t("watchedFolders.time.minutesAgo", {
15+
count: mins,
16+
defaultValue: `${mins}m ago`,
17+
});
18+
const hours = Math.floor(mins / 60);
19+
if (hours < 24)
20+
return t("watchedFolders.time.hoursAgo", {
21+
count: hours,
22+
defaultValue: `${hours}h ago`,
23+
});
24+
const days = Math.floor(hours / 24);
25+
return t("watchedFolders.time.daysAgo", {
26+
count: days,
27+
defaultValue: `${days}d ago`,
28+
});
29+
}
30+
31+
export function humaniseOp(op: string): string {
32+
return op
33+
.replace(/-pdf$|-pages$|-documents?$/i, "")
34+
.replace(/[-_]/g, " ")
35+
.replace(/\bocr\b/gi, "OCR")
36+
.replace(/\b\w/g, (c) => c.toUpperCase())
37+
.trim();
38+
}

0 commit comments

Comments
 (0)