oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3struct TaskReviewSummary: View {
4 let task: ThinTask
5 var body: some View {
6 VStack(alignment: .leading, spacing: 8) {
7 SectionTitle(text: EquipoStrings.text("fact.review"))
8 if let review = TaskPage.latestReview(task) {
9 if ["running", "queued"].contains(review.state) {
10 Text(EquipoStrings.text("review.running")).foregroundStyle(Palette.secondary)
11 } else {
12 if !review.headline.isEmpty { Text(review.headline).font(.headline) }
13 if !review.summary.isEmpty { Text(review.summary).font(Typo.body).textSelection(.enabled).fixedSize(horizontal: false, vertical: true) }
14 }
15 } else { Text(EquipoStrings.text("runner.verdict.skipped")).foregroundStyle(Palette.secondary) }
16 }
17 }
18}
19
20struct TaskChecksView: View {
21 let task: ThinTask
22 let client: EquipoClient
23 @State private var sections: [CheckSection] = []
24 @State private var failure: String?
25 @State private var loadedStep: String?
26 private var step: ThinStep? { TaskPage.checksLogStep(task) }
27 var body: some View {
28 VStack(alignment: .leading, spacing: 16) {
29 if let step {
30 if loadedStep == step.id, let failure {
31 Text(failure).foregroundStyle(Palette.negative)
32 Button(EquipoStrings.text("read.retry")) { Task { await load(step) } }
33 } else if loadedStep != step.id {
34 ProgressView().accessibilityLabel(EquipoStrings.text("fact.checks"))
35 } else {
36 ForEach(sections) { section in
37 if section.isSummary { Text(section.text).font(Typo.body).textSelection(.enabled).fixedSize(horizontal: false, vertical: true) }
38 else { CheckSectionView(section: section) }
39 }
40 }
41 } else {
42 VStack(alignment: .leading, spacing: 8) {
43 SectionTitle(text: EquipoStrings.text("fact.checks"))
44 Text(EquipoStrings.text(TaskPage.latestChecks(task) == nil ? "runner.verdict.skipped" : "checks.running"))
45 .foregroundStyle(Palette.secondary)
46 }
47 }
48 TaskReviewSummary(task: task)
49 }
50 .task(id: task.revision) { sections = []; loadedStep = nil; if let step { await load(step) } }
51 }
52 private func load(_ step: ThinStep) async {
53 failure = nil
54 do {
55 let log = try await client.stepLog(step.id)
56 try Task.checkCancellation()
57 sections = CheckSection.split(log, step: step); loadedStep = step.id
58 } catch {
59 guard !Task.isCancelled else { return }
60 failure = StoppedWorkActions.logFailure(error); loadedStep = step.id
61 }
62 }
63}
64
65private struct CheckSectionView: View {
66 let section: CheckSection
67 @State private var expanded: Bool
68 init(section: CheckSection) { self.section = section; _expanded = State(initialValue: section.failed) }
69 var body: some View {
70 DisclosureGroup(isExpanded: $expanded) {
71 LogTailView(tail: section.text)
72 } label: {
73 Label(section.name.isEmpty ? EquipoStrings.text("native.step.log_tail") : section.name,
74 systemImage: section.failed ? "xmark.circle.fill" : "text.alignleft")
75 .font(.system(.subheadline, design: .monospaced)).foregroundStyle(section.failed ? Palette.negative : Palette.text)
76 }
77 .onChange(of: section.failed) { if section.failed { expanded = true } }
78 }
79}
80
81struct TaskMoveSheet: View {
82 @Bindable var model: TaskDetailModel
83 @State private var selected = ""
84 @Environment(\.dismiss) private var dismiss
85 var body: some View {
86 NavigationStack {
87 Form {
88 Text(EquipoStrings.text("placement.restart_note"))
89 if model.busy { ProgressView().accessibilityLabel(EquipoStrings.text("placement.destination")) }
90 if let failure = model.failure { Text(failure).foregroundStyle(Palette.negative) }
91 Picker(EquipoStrings.text("placement.destination"), selection: $selected) {
92 Text(EquipoStrings.text("placement.question")).tag("")
93 ForEach(model.destinations, id: \.self) { Text(verbatim: $0).tag($0) }
94 }
95 Button(EquipoStrings.text(model.task?.steps?.contains(where: { $0.specialist == "engineering" }) == true ? "placement.restart" : "placement.confirm")) {
96 let revision = model.task?.revision
97 Task { await model.perform(.move, seenRevision: revision, repo: selected) }
98 }.disabled(model.busy || !model.destinations.contains(selected))
99 }
100 .navigationTitle(EquipoStrings.text("placement.title"))
101 .toolbar { ToolbarItem(placement: .cancellationAction) { Button(EquipoStrings.text("placement.back")) { dismiss() } } }
102 }.frame(minWidth: 300, minHeight: 300)
103 }
104}
105