Skip to main content

pipedash_plugin_api/presentation/
defaults.rs

1use super::{
2    ActionCopy,
3    Notice,
4    PipelineTerminology,
5    PluginPresentation,
6    StatusOption,
7    ViewCopy,
8    WizardCopy,
9};
10use crate::types::PipelineStatus;
11
12fn notice(title: &str, message: &str) -> Notice {
13    Notice {
14        title: title.to_string(),
15        message: message.to_string(),
16    }
17}
18
19impl Default for PipelineTerminology {
20    fn default() -> Self {
21        Self {
22            item: "pipeline".to_string(),
23            items: "pipelines".to_string(),
24            group: "organization".to_string(),
25            groups: "organizations".to_string(),
26            group_title: "Organization".to_string(),
27            source_title: "Repository".to_string(),
28            sources_title: "Repositories".to_string(),
29            history: "Run history".to_string(),
30            trigger: "Trigger".to_string(),
31            run: "run".to_string(),
32            runs: "runs".to_string(),
33            organization_label: "Organization".to_string(),
34            section_count_label: "Workflows".to_string(),
35        }
36    }
37}
38
39impl Default for ViewCopy {
40    fn default() -> Self {
41        Self {
42            title: "Pipelines".to_string(),
43            list_title: "All pipelines".to_string(),
44            search_placeholder: "Search repositories, workflows…".to_string(),
45            matching_empty: notice(
46                "No matching workflows",
47                "No repositories or workflows match the current filters.",
48            ),
49            hidden_empty: notice(
50                "All workflows are hidden",
51                "Turn on Show hidden pipelines in View options to list them and unhide them.",
52            ),
53            empty: notice(
54                "No workflows yet",
55                "Workflows appear here after they run on your configured providers.",
56            ),
57            pinned_empty: notice(
58                "No pinned workflows",
59                "Use the pin icon on a pipeline to keep it here.",
60            ),
61        }
62    }
63}
64
65pub(super) fn status_options() -> Vec<StatusOption> {
66    [
67        (PipelineStatus::Success, "Success"),
68        (PipelineStatus::Failed, "Failed"),
69        (PipelineStatus::Degraded, "Degraded"),
70        (PipelineStatus::Running, "Running"),
71        (PipelineStatus::Pending, "Pending"),
72        (PipelineStatus::Cancelled, "Cancelled"),
73        (PipelineStatus::Skipped, "Skipped"),
74    ]
75    .into_iter()
76    .map(|(value, label)| StatusOption {
77        value,
78        label: label.to_string(),
79    })
80    .collect()
81}
82
83fn trigger_copy() -> ActionCopy {
84    ActionCopy {
85        label: "Trigger workflow".to_string(),
86        compact_label: "Trigger".to_string(),
87        title: "Trigger".to_string(),
88        success: notice(
89            "Workflow triggered",
90            "Workflow has been triggered successfully",
91        ),
92        error_title: "Couldn't trigger workflow".to_string(),
93        note: None,
94    }
95}
96
97fn rerun_copy() -> ActionCopy {
98    ActionCopy {
99        label: "Rerun workflow".to_string(),
100        compact_label: "Rerun".to_string(),
101        title: "Rerun".to_string(),
102        success: notice("Workflow triggered", "Workflow rerun started"),
103        error_title: "Couldn't rerun workflow".to_string(),
104        note: None,
105    }
106}
107
108pub(super) fn presentation(provider_name: &str) -> PluginPresentation {
109    PluginPresentation {
110        terminology: PipelineTerminology::default(),
111        status_options: status_options(),
112        wizard: WizardCopy {
113            credentials_description: "Enter your API credentials".to_string(),
114            name_placeholder: format!("e.g. {provider_name} (work)"),
115            permissions_title: "Token permissions".to_string(),
116        },
117        view: ViewCopy::default(),
118        trigger: trigger_copy(),
119        rerun: rerun_copy(),
120        history_note: None,
121        empty_history_description: "This workflow has no recorded runs.".to_string(),
122        run_details_title: "Run details".to_string(),
123        progress_title: "Run in progress".to_string(),
124        archived_notice: None,
125        force_cancel_confirmation:
126            "Force cancel only after normal cancellation fails. You can't undo this.".to_string(),
127    }
128}