Skip to content

Commit 9a6060b

Browse files
committed
wip
1 parent 68820f9 commit 9a6060b

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
import { Task } from "@lit/task";
22
import { type ReactiveController } from "lit";
3+
import queryString from "query-string";
4+
5+
import { type Workflow } from "./types";
36

47
import { type WorkflowsList } from "@/pages/org/workflows-list";
8+
import { type APIPaginatedList } from "@/types/api";
9+
import { type UserInfo } from "@/types/user";
10+
11+
const stringifyQuery = (query: {}) =>
12+
queryString.stringify(query, {
13+
arrayFormat: "comma",
14+
});
515

616
export class ClockController implements ReactiveController {
717
host: WorkflowsList;
818

9-
timeout: number;
10-
private _timerID?: number;
19+
private readonly POLL_INTERVAL_SECONDS;
20+
private runningIntervalId?: number;
21+
private allIntervalId?: number;
1122

1223
readonly task;
1324

14-
constructor(host: WorkflowsList, timeout = 1000, INITIAL_PAGE_SIZE = 10) {
25+
constructor(
26+
host: WorkflowsList,
27+
INITIAL_PAGE_SIZE = 10,
28+
POLL_INTERVAL_SECONDS = 10,
29+
userInfo: () => UserInfo | undefined,
30+
) {
1531
(this.host = host).addController(this);
16-
this.timeout = timeout;
32+
this.POLL_INTERVAL_SECONDS = POLL_INTERVAL_SECONDS;
1733
this.task = new Task(this.host, {
1834
task: async (
1935
[showRunningFirst, filterBy, orderBy, page, filterByCurrentUser],
@@ -26,16 +42,16 @@ export class ClockController implements ReactiveController {
2642
...filterBy,
2743
page: page || 1,
2844
pageSize: this.task.value?.pageSize || INITIAL_PAGE_SIZE,
29-
userid: filterByCurrentUser ? this.host.userInfo?.id : undefined,
45+
userid: filterByCurrentUser ? userInfo()?.id : undefined,
3046
sortBy: orderBy.field,
3147
sortDirection: orderBy.direction === "desc" ? -1 : 1,
3248
running: true,
33-
};
49+
} as const;
3450

3551
const query = stringifyQuery(queryParams);
3652

37-
const workflows = await this.api.fetch<APIPaginatedList<Workflow>>(
38-
`/orgs/${this.orgId}/crawlconfigs?${query}`,
53+
const workflows = await this.host.api.fetch<APIPaginatedList<Workflow>>(
54+
`/orgs/${this.host.orgId}/crawlconfigs?${query}`,
3955
{
4056
signal: signal,
4157
},
@@ -49,32 +65,21 @@ export class ClockController implements ReactiveController {
4965
clearTimeout(this.allIntervalId);
5066

5167
this.runningIntervalId = window.setTimeout(() => {
52-
void this.runningWorkflowsTask.run();
68+
void this.task.run();
5369
}, 1000 * POLL_INTERVAL_SECONDS);
5470

5571
return workflows;
5672
},
5773
args: () =>
5874
[
59-
this.showRunningFirst,
60-
this.filterBy,
61-
this.orderBy,
62-
this.page[WorkflowGroup.RUNNING],
63-
this.filterByCurrentUser,
75+
this.host.showRunningFirst,
76+
this.host.filterBy,
77+
this.host.orderBy,
78+
this.host.page[WorkflowGroup.RUNNING],
79+
this.host.filterByCurrentUser,
6480
] as const,
6581
});
6682
}
67-
hostConnected() {
68-
// Start a timer when the host is connected
69-
this._timerID = setInterval(() => {
70-
this.value = new Date();
71-
// Update the host with new value
72-
this.host.requestUpdate();
73-
}, this.timeout);
74-
}
75-
hostDisconnected() {
76-
// Clear the timer when the host is disconnected
77-
clearInterval(this._timerID);
78-
this._timerID = undefined;
79-
}
83+
hostConnected() {}
84+
hostDisconnected() {}
8085
}

frontend/src/pages/org/workflows-list.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type SortDirection = "asc" | "desc";
3939

4040
const FILTER_BY_CURRENT_USER_STORAGE_KEY =
4141
"btrix.filterByCurrentUser.crawlConfigs";
42-
const INITIAL_PAGE_SIZE = 1;
43-
const POLL_INTERVAL_SECONDS = 1;
42+
const INITIAL_PAGE_SIZE = 10;
43+
const POLL_INTERVAL_SECONDS = 10;
4444
// const ABORT_REASON_THROTTLE = "throttled";
4545
// NOTE Backend pagination max is 1000
4646
const SEEDS_MAX = 1000;

0 commit comments

Comments
 (0)