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
|
//
// SecurityEventRow.swift
// octosentry
//
import AppKit
import SwiftUI
struct SecurityEventRow: View {
let event: SecurityEvent
private static let relativeFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .abbreviated
return formatter
}()
var body: some View {
Button {
NSWorkspace.shared.open(event.detailURL)
} label: {
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 6) {
Text(event.nativeSeverityLabel.uppercased())
.font(.caption2.weight(.bold))
.foregroundStyle(event.severity.color)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(event.severity.color.opacity(0.18), in: Capsule())
Text(event.source.displayName)
.font(.caption2.weight(.semibold))
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(.secondary.opacity(0.15), in: Capsule())
Text(event.repoFullName)
.font(.caption)
.foregroundStyle(.secondary)
Spacer()
Text(Self.relativeFormatter.localizedString(for: event.createdAt, relativeTo: .now))
.font(.caption2)
.foregroundStyle(.secondary)
}
Text(event.summary)
.font(.callout)
.lineLimit(1)
.foregroundStyle(.primary)
}
.padding(10)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}
}
#Preview {
SecurityEventRow(event: SecurityEvent(
id: "preview-1",
source: .dependabot,
repoFullName: "zerolabsco/octosentry",
severity: .critical,
nativeSeverityLabel: "Critical",
summary: "Denial of service in some-package",
detailURL: URL(string: "https://github.com")!,
createdAt: .now.addingTimeInterval(-3600 * 26),
updatedAt: .now,
seenLocally: false
))
}
|