Repository Public
1import MCCCore2import SwiftUI34// Helpers internal to the Alerts / Actions / Activity / Audit screens.56/// Leading content and a trailing accessory side by side; stacked at accessibility text sizes so that neither truncates.7struct AdaptiveRow<Leading: View, Trailing: View>: View {8 @Environment(\.dynamicTypeSize) private var size9 @ViewBuilder var leading: Leading10 @ViewBuilder var trailing: Trailing11 var body: some View {12 if size.isAccessibilitySize {13 VStack(alignment: .leading, spacing: Tokens.Space.s2) { leading; trailing }14 } else {15 HStack(alignment: .firstTextBaseline, spacing: Tokens.Space.s3) {16 leading.frame(maxWidth: .infinity, alignment: .leading)17 trailing18 }19 }20 }21}2223/// Chronological timeline of an alert or an incident.24struct TimelineList: View {25 @Environment(\.mccTheme) private var theme26 let events: [API.TimelineEvent]27 var body: some View {28 let items = AlertsLogic.timeline(events)29 if items.isEmpty {30 Text(tr("alerts.timeline.empty")).font(.callout).foregroundStyle(theme.textSecondary)31 } else {32 VStack(alignment: .leading, spacing: Tokens.Space.s4) {33 ForEach(items, id: \.id) { e in34 HStack(alignment: .top, spacing: Tokens.Space.s3) {35 Image(systemName: "circle.fill").font(.system(.caption2)).foregroundStyle(theme.accent).padding(.top, Tokens.Space.s2).accessibilityHidden(true)36 VStack(alignment: .leading, spacing: Tokens.Space.s1) {37 Text(e.kind).font(.callout.weight(.medium)).foregroundStyle(theme.textPrimary)38 if !e.body.isEmpty { Text(e.body).font(.callout).foregroundStyle(theme.textPrimary).textSelection(.enabled) }39 Text([e.actorDisplayName, Format.dateTime(e.ts)].compactMap { $0 }.joined(separator: " · "))40 .font(.footnote).foregroundStyle(theme.textSecondary)41 }42 }43 .frame(maxWidth: .infinity, alignment: .leading)44 .accessibilityElement(children: .combine)45 .accessibilityIdentifier("timeline-event")46 }47 }48 }49 }50}5152/// Small form sheet: one text field (comment, reason) and a confirm button. Used for acknowledge / resolve /53/// comment / approve / reject. `onConfirm` returns true when the sheet can close.54struct TextPromptSheet: View {55 @Environment(\.dismiss) private var dismiss56 @Environment(\.mccTheme) private var theme57 @Session private var session58 let title: String59 var message: String?60 let fieldLabel: String61 var required = false62 var fieldID = "prompt-field"63 let confirmTitle: String64 var confirmID = "prompt-confirm"65 var destructive = false66 let onConfirm: (String) async -> Bool67 @State private var text = ""68 @State private var working = false6970 var body: some View {71 NavigationStack {72 Form {73 if let message { Section { Text(message).font(.callout).foregroundStyle(theme.textSecondary) } }74 Section(fieldLabel) {75 TextField(fieldLabel, text: $text, axis: .vertical)76 .lineLimit(3...8)77 .frame(minHeight: Tokens.Size.touchMin)78 .accessibilityLabel(fieldLabel)79 .accessibilityIdentifier(fieldID)80 }81 Section {82 Button(role: destructive ? .destructive : nil) {83 working = true84 Task {85 let ok = await onConfirm(text.trimmingCharacters(in: .whitespacesAndNewlines))86 working = false87 if ok { dismiss() }88 }89 } label: {90 HStack { if working { ProgressView() }; Text(confirmTitle) }.frame(maxWidth: .infinity, minHeight: Tokens.Size.touchMin)91 }92 .disabled(working || !session.canMutate || (required && text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty))93 .accessibilityIdentifier(confirmID)94 }95 }96 .navigationTitle(title)97 .navigationBarTitleDisplayMode(.inline)98 .toolbar { ToolbarItem(placement: .cancellationAction) { Button(tr("common.cancel")) { dismiss() } } }99 }100 .mccThemed()101 .presentationDetents([.medium, .large])102 }103}104105/// Severity as icon + text (never colour alone).106struct SeverityLabel: View {107 let severity: API.Severity108 var body: some View { StatusLabel(severity.label, tone: severity.tone) }109}110