Skip to content

Commit 08cc49e

Browse files
committed
Add isPaused crawler util function for frontend
1 parent 7fc2532 commit 08cc49e

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

frontend/src/features/archived-items/crawl-status.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import startCase from "lodash/fp/startCase";
55

66
import { TailwindElement } from "@/classes/TailwindElement";
77
import { labelWithIcon } from "@/layouts/labelWithIcon";
8-
import {
9-
PAUSED_STATES,
10-
RUNNING_STATES,
11-
type CrawlState,
12-
} from "@/types/crawlState";
8+
import { RUNNING_STATES, type CrawlState } from "@/types/crawlState";
9+
import { isPaused } from "@/utils/crawler";
1310
import { animatePulse } from "@/utils/css";
1411

1512
type CrawlType = "crawl" | "qa";
@@ -377,10 +374,7 @@ export class CrawlStatus extends TailwindElement {
377374
) {
378375
return "pausing";
379376
}
380-
if (
381-
!this.shouldPause &&
382-
(PAUSED_STATES as readonly string[]).includes(this.state || "")
383-
) {
377+
if (!this.shouldPause && isPaused(this.state || "")) {
384378
return "resuming";
385379
}
386380
return this.state;

frontend/src/features/crawl-workflows/workflow-action-menu/workflow-action-menu.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { BtrixElement } from "@/classes/BtrixElement";
1010
import { ClipboardController } from "@/controllers/clipboard";
1111
import { WorkflowTab } from "@/routes";
1212
import type { Crawl, ListWorkflow, Workflow } from "@/types/crawler";
13-
import { PAUSED_STATES } from "@/types/crawlState";
14-
import { isNotFailed, isSuccessfullyFinished } from "@/utils/crawler";
13+
import { isNotFailed, isPaused, isSuccessfullyFinished } from "@/utils/crawler";
1514
import { isArchivingDisabled } from "@/utils/orgs";
1615

1716
@customElement("btrix-workflow-action-menu")
@@ -42,9 +41,7 @@ export class WorkflowActionMenu extends BtrixElement {
4241

4342
const canCrawl = this.appState.isCrawler;
4443
const archivingDisabled = isArchivingDisabled(this.org, true);
45-
const paused = (PAUSED_STATES as readonly string[]).includes(
46-
workflow.lastCrawlState || "",
47-
);
44+
const paused = isPaused(workflow.lastCrawlState || "");
4845
const crawling =
4946
workflow.isCrawlRunning &&
5047
!workflow.lastCrawlStopping &&

frontend/src/pages/org/workflow-detail.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ import { pageNav, type Breadcrumb } from "@/layouts/pageHeader";
3232
import { WorkflowTab } from "@/routes";
3333
import { deleteConfirmation, noData, notApplicable } from "@/strings/ui";
3434
import type { APIPaginatedList, APIPaginationQuery } from "@/types/api";
35-
import { PAUSED_STATES, type CrawlState } from "@/types/crawlState";
35+
import { type CrawlState } from "@/types/crawlState";
3636
import { type StorageSeedFile } from "@/types/workflow";
3737
import { isApiError } from "@/utils/api";
3838
import { settingsForDuplicate } from "@/utils/crawl-workflows/settingsForDuplicate";
3939
import {
4040
DEFAULT_MAX_SCALE,
4141
isActive,
42+
isPaused,
4243
isSkipped,
4344
isSuccessfullyFinished,
4445
renderName,
@@ -367,9 +368,7 @@ export class WorkflowDetail extends BtrixElement {
367368
}
368369

369370
private get isPaused() {
370-
return (PAUSED_STATES as readonly string[]).includes(
371-
this.workflow?.lastCrawlState || "",
372-
);
371+
return isPaused(this.workflow?.lastCrawlState || "");
373372
}
374373

375374
private get isResuming() {
@@ -920,9 +919,8 @@ export class WorkflowDetail extends BtrixElement {
920919

921920
return (
922921
this.workflow.lastCrawlShouldPause ===
923-
!(PAUSED_STATES as readonly string[]).includes(
924-
this.workflow.lastCrawlState || "",
925-
) || isLoading(this.pauseResumeTask)
922+
!isPaused(this.workflow.lastCrawlState || "") ||
923+
isLoading(this.pauseResumeTask)
926924
);
927925
}
928926

frontend/src/utils/crawler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { html, type TemplateResult } from "lit";
55
import type { ArchivedItem, Crawl, Upload, Workflow } from "@/types/crawler";
66
import {
77
FAILED_STATES,
8+
PAUSED_STATES,
89
RUNNING_AND_WAITING_STATES,
910
SUCCESSFUL_AND_FAILED_STATES,
1011
SUCCESSFUL_STATES,
@@ -51,6 +52,10 @@ export function isNotFailed({ state }: { state: string | null }) {
5152
);
5253
}
5354

55+
export function isPaused(state: string | null) {
56+
return state && (PAUSED_STATES as readonly string[]).includes(state);
57+
}
58+
5459
export function isPageScopeType(
5560
scope?: (typeof WorkflowScopeType)[keyof typeof WorkflowScopeType],
5661
) {

0 commit comments

Comments
 (0)