github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/jobs/jobStatusOptions.ts (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import {cockroach} from "src/js/protos"; 12 import Job = cockroach.server.serverpb.JobsResponse.IJob; 13 import {BadgeStatus} from "src/components"; 14 15 export enum JobStatusVisual { 16 BadgeOnly, 17 BadgeWithDuration, 18 ProgressBarWithDuration, 19 BadgeWithMessage, 20 } 21 22 export function jobToVisual(job: Job): JobStatusVisual { 23 if (job.type === "CHANGEFEED") { 24 return JobStatusVisual.BadgeOnly; 25 } 26 switch (job.status) { 27 case JOB_STATUS_SUCCEEDED: 28 return JobStatusVisual.BadgeWithDuration; 29 case JOB_STATUS_FAILED: 30 return JobStatusVisual.BadgeOnly; 31 case JOB_STATUS_CANCELED: 32 return JobStatusVisual.BadgeOnly; 33 case JOB_STATUS_PAUSED: 34 return JobStatusVisual.BadgeOnly; 35 case JOB_STATUS_RUNNING: 36 return JobStatusVisual.ProgressBarWithDuration; 37 case JOB_STATUS_PENDING: 38 return JobStatusVisual.BadgeWithMessage; 39 default: 40 return JobStatusVisual.BadgeOnly; 41 } 42 } 43 44 export const JOB_STATUS_SUCCEEDED = "succeeded"; 45 export const JOB_STATUS_FAILED = "failed"; 46 export const JOB_STATUS_CANCELED = "canceled"; 47 export const JOB_STATUS_PAUSED = "paused"; 48 export const JOB_STATUS_RUNNING = "running"; 49 export const JOB_STATUS_PENDING = "pending"; 50 51 export const statusOptions = [ 52 {value: "", label: "All"}, 53 {value: "succeeded", label: "Succeeded"}, 54 {value: "failed", label: "Failed"}, 55 {value: "running", label: "Running"}, 56 {value: "pending", label: "Pending"}, 57 {value: "canceled", label: "Canceled"}, 58 {value: "paused", label: "Paused"}, 59 ]; 60 61 export function jobHasOneOfStatuses(job: Job, ...statuses: string[]) { 62 return statuses.indexOf(job.status) !== -1; 63 } 64 65 export const jobStatusToBadgeStatus = (status: string): BadgeStatus => { 66 switch (status) { 67 case JOB_STATUS_SUCCEEDED: 68 return "success"; 69 case JOB_STATUS_FAILED: 70 return "danger"; 71 case JOB_STATUS_CANCELED: 72 return "default"; 73 case JOB_STATUS_PAUSED: 74 return "default"; 75 case JOB_STATUS_RUNNING: 76 return "info"; 77 case JOB_STATUS_PENDING: 78 return "warning"; 79 default: 80 return "info"; 81 } 82 };