linear-tui 0.12.0

A TUI client for Linear.app — manage issues, projects, and cycles from your terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
//! Linear's answers: what comes back for each [`Request`] a use case made.
//!
//! The UI queues a [`Request`] (the use cases' output port), the main loop
//! hands it to `crate::infra::dispatch` on the tokio runtime, and the
//! resulting [`Message`] comes back over an mpsc channel. The UI thread never
//! awaits a network call, so input and animation stay responsive.

use crate::core::entity::*;
use crate::core::usecase::Request;

/// Every response that fills a list names what it was fetched for — the team,
/// view, project, or cycle — so a reply that lands after the user has moved
/// on can be told apart from one for the list on screen and dropped.
#[derive(Debug)]
pub enum Message {
    Teams(Vec<Team>),
    Viewer {
        id: UserId,
        organization: Option<Organization>,
    },
    TeamContext {
        team_id: TeamId,
        states: Vec<WorkflowState>,
        members: Vec<User>,
    },
    Issues {
        team_id: TeamId,
        /// Echoed back so a page fetched for another preset can be dropped.
        preset: Preset,
        page: Page<Issue>,
    },
    MyIssues(Page<Issue>),
    PaletteResults {
        seq: u64,
        issues: Vec<Issue>,
    },
    SearchResults {
        term: String,
        team_id: Option<TeamId>,
        issues: Vec<Issue>,
    },
    CustomViews(Vec<CustomView>),
    Favorites(Vec<Favorite>),
    ViewIssues {
        /// Echoed back so a late page cannot be filed under the wrong view.
        view_id: CustomViewId,
        page: Page<Issue>,
    },
    ViewProjects {
        view_id: CustomViewId,
        page: Page<Project>,
    },
    Projects {
        team_id: TeamId,
        page: Page<Project>,
    },
    Cycles {
        team_id: TeamId,
        page: Page<Cycle>,
    },
    IssueDetail(Box<Issue>),
    ProjectIssues {
        project_id: ProjectId,
        page: Page<Issue>,
    },
    CycleIssues {
        cycle_id: CycleId,
        page: Page<Issue>,
    },
    IssueCreated {
        team_id: TeamId,
        issue: Box<Issue>,
    },
    /// The labels a team's issues can carry.
    Labels {
        team_id: TeamId,
        labels: Vec<Label>,
    },
    /// The projects with a name, in any case.
    ProjectsFound {
        name: String,
        projects: Vec<Project>,
    },
    /// One project, with its teams and milestones.
    ProjectDetail(Box<Project>),
    ProjectStatuses(Vec<ProjectStatus>),
    ProjectCreated(Box<Project>),
    MilestoneCreated {
        project_id: ProjectId,
        milestone: Box<Milestone>,
    },
    /// A comment or reply is posted; Linear gives back its id and URL.
    CommentPosted {
        issue_id: IssueId,
        comment: Box<Comment>,
    },
    /// A mutation succeeded; carries the status line to show.
    Mutated(&'static str),
    /// A request failed. Carries the request itself, so the failure can be
    /// undone precisely: a page cursor made retryable, an optimistic patch
    /// re-read from the server.
    Failed {
        request: Box<Request>,
        error: String,
    },
}

/// What failed, as the error popup and the headless commands phrase it.
pub fn failure(request: &Request) -> &'static str {
    use crate::core::usecase::{agent, cycle, favorite, issue, notes, project, team, user, view};
    match request {
        Request::Issue(request) => match request {
            issue::Request::TeamIssues { .. } => "Failed to load issues",
            issue::Request::MyIssues { .. } => "Failed to load my issues",
            issue::Request::ViewIssues { .. } => "Failed to load view issues",
            issue::Request::ProjectIssues { .. } => "Failed to load project issues",
            issue::Request::CycleIssues { .. } => "Failed to load cycle issues",
            issue::Request::Detail { .. } => "Failed to load detail",
            issue::Request::Search { .. } | issue::Request::QuickSearch { .. } => "Search failed",
            issue::Request::SetStatus { .. } => "Failed to update status",
            issue::Request::SetPriority { .. } => "Failed to update priority",
            issue::Request::SetAssignee { .. } => "Failed to update assignee",
            issue::Request::Update { .. } => "Failed to update issue",
            issue::Request::Comment { .. } => "Failed to post comment",
            issue::Request::EditComment { .. } => "Failed to edit comment",
            issue::Request::DeleteComment { .. } => "Failed to delete comment",
            issue::Request::Create { .. } => "Failed to create issue",
            issue::Request::OpenInBrowser(_) => "Failed to open browser",
        },
        Request::Project(request) => match request {
            project::Request::TeamProjects { .. } => "Failed to load projects",
            project::Request::ViewProjects { .. } => "Failed to load view projects",
            project::Request::OpenInBrowser(_) => "Failed to open browser",
            project::Request::Find { .. } => "Failed to find the project",
            project::Request::Detail { .. } => "Failed to load the project",
            project::Request::Statuses => "Failed to load project statuses",
            project::Request::Create { .. } => "Failed to create project",
            project::Request::Update { .. } => "Failed to update project",
            project::Request::Delete { .. } => "Failed to delete project",
            project::Request::CreateMilestone { .. } => "Failed to create milestone",
            project::Request::UpdateMilestone { .. } => "Failed to update milestone",
            project::Request::DeleteMilestone { .. } => "Failed to delete milestone",
        },
        Request::Cycle(cycle::Request::TeamCycles { .. }) => "Failed to load cycles",
        Request::Team(team::Request::Teams) => "Failed to load teams",
        Request::Team(team::Request::Context { .. }) => "Failed to load team context",
        Request::Team(team::Request::Labels { .. }) => "Failed to load labels",
        Request::View(view::Request::Views) => "Failed to load views",
        Request::Favorite(favorite::Request::Favorites) => "Failed to load favorites",
        Request::Favorite(favorite::Request::OpenInBrowser(_)) => "Failed to open browser",
        Request::User(user::Request::Viewer) => "Failed to identify current user",
        Request::Notes(notes::Request::Deliver(_))
        | Request::Agent(agent::Request::Focus { .. }) => "Failed to reach herdr",
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::core::entity::{Handoff, TeamId};
    use crate::core::usecase::{agent, cycle, favorite, issue, notes, project, team, user, view};

    /// A failed load says what could not be loaded, a failed change what
    /// could not be changed, and anything handed to herdr that herdr could
    /// not be reached.
    #[test]
    fn a_failure_says_what_could_not_be_done() {
        let team = || TeamId::from("t");
        let cases: Vec<(Request, &str)> = vec![
            (
                issue::Request::TeamIssues {
                    team_id: team(),
                    preset: Default::default(),
                    after: None,
                }
                .into(),
                "Failed to load issues",
            ),
            (
                issue::Request::MyIssues {
                    user_id: "u".into(),
                    after: None,
                }
                .into(),
                "Failed to load my issues",
            ),
            (
                issue::Request::ViewIssues {
                    view_id: "v".into(),
                    after: None,
                }
                .into(),
                "Failed to load view issues",
            ),
            (
                issue::Request::ProjectIssues {
                    project_id: "p".into(),
                    after: None,
                }
                .into(),
                "Failed to load project issues",
            ),
            (
                issue::Request::CycleIssues {
                    cycle_id: "c".into(),
                    after: None,
                }
                .into(),
                "Failed to load cycle issues",
            ),
            (
                issue::Request::Detail {
                    issue_id: "i".into(),
                }
                .into(),
                "Failed to load detail",
            ),
            (
                issue::Request::Search {
                    term: "x".into(),
                    team_id: None,
                }
                .into(),
                "Search failed",
            ),
            (
                issue::Request::QuickSearch {
                    term: "x".into(),
                    seq: 1,
                }
                .into(),
                "Search failed",
            ),
            (
                issue::Request::SetStatus {
                    issue_id: "i".into(),
                    state_id: "s".into(),
                }
                .into(),
                "Failed to update status",
            ),
            (
                issue::Request::SetPriority {
                    issue_id: "i".into(),
                    priority: Default::default(),
                }
                .into(),
                "Failed to update priority",
            ),
            (
                issue::Request::SetAssignee {
                    issue_id: "i".into(),
                    assignee_id: None,
                }
                .into(),
                "Failed to update assignee",
            ),
            (
                issue::Request::Update {
                    issue_id: "i".into(),
                    changes: Default::default(),
                }
                .into(),
                "Failed to update issue",
            ),
            (
                issue::Request::Comment {
                    issue_id: "i".into(),
                    body: "b".into(),
                    parent_id: None,
                }
                .into(),
                "Failed to post comment",
            ),
            (
                issue::Request::EditComment {
                    issue_id: "i".into(),
                    comment_id: "c".into(),
                    body: "b".into(),
                }
                .into(),
                "Failed to edit comment",
            ),
            (
                issue::Request::DeleteComment {
                    issue_id: "i".into(),
                    comment_id: "c".into(),
                }
                .into(),
                "Failed to delete comment",
            ),
            (
                issue::Request::Create {
                    team_id: team(),
                    draft: Default::default(),
                }
                .into(),
                "Failed to create issue",
            ),
            (
                issue::Request::OpenInBrowser("u".into()).into(),
                "Failed to open browser",
            ),
            (
                project::Request::TeamProjects {
                    team_id: team(),
                    after: None,
                }
                .into(),
                "Failed to load projects",
            ),
            (
                project::Request::ViewProjects {
                    view_id: "v".into(),
                    after: None,
                }
                .into(),
                "Failed to load view projects",
            ),
            (
                project::Request::OpenInBrowser("u".into()).into(),
                "Failed to open browser",
            ),
            (
                project::Request::Find { name: "p".into() }.into(),
                "Failed to find the project",
            ),
            (
                project::Request::Detail {
                    project_id: "p".into(),
                }
                .into(),
                "Failed to load the project",
            ),
            (
                project::Request::Statuses.into(),
                "Failed to load project statuses",
            ),
            (
                project::Request::Create {
                    draft: Default::default(),
                }
                .into(),
                "Failed to create project",
            ),
            (
                project::Request::Update {
                    project_id: "p".into(),
                    changes: Default::default(),
                }
                .into(),
                "Failed to update project",
            ),
            (
                project::Request::Delete {
                    project_id: "p".into(),
                }
                .into(),
                "Failed to delete project",
            ),
            (
                project::Request::CreateMilestone {
                    project_id: "p".into(),
                    draft: Default::default(),
                }
                .into(),
                "Failed to create milestone",
            ),
            (
                project::Request::UpdateMilestone {
                    milestone_id: "m".into(),
                    changes: Default::default(),
                }
                .into(),
                "Failed to update milestone",
            ),
            (
                project::Request::DeleteMilestone {
                    milestone_id: "m".into(),
                }
                .into(),
                "Failed to delete milestone",
            ),
            (
                cycle::Request::TeamCycles {
                    team_id: team(),
                    after: None,
                }
                .into(),
                "Failed to load cycles",
            ),
            (team::Request::Teams.into(), "Failed to load teams"),
            (
                team::Request::Context { team_id: team() }.into(),
                "Failed to load team context",
            ),
            (
                team::Request::Labels { team_id: team() }.into(),
                "Failed to load labels",
            ),
            (view::Request::Views.into(), "Failed to load views"),
            (
                favorite::Request::Favorites.into(),
                "Failed to load favorites",
            ),
            (
                favorite::Request::OpenInBrowser("u".into()).into(),
                "Failed to open browser",
            ),
            (
                user::Request::Viewer.into(),
                "Failed to identify current user",
            ),
            (
                notes::Request::Deliver(Handoff::Focus { pane: "p".into() }).into(),
                "Failed to reach herdr",
            ),
            (
                agent::Request::Focus { pane: "p".into() }.into(),
                "Failed to reach herdr",
            ),
        ];
        for (request, wording) in cases {
            assert_eq!(failure(&request), wording, "{request:?}");
        }
    }
}