feat(sessions): keep every session, record review details, name and stamp the PDF
Sessions are now the unit of the product instead of an implicit capture run. - Nothing is deleted by default: the fixed 10-session cap is gone. An age limit (Never / 7 / 14 / 30 / 90 / 180 / 365 days) is chosen in Settings > Sessions and applied on launch, after archiving, and by "Clean up now". Sent PDFs are never touched. - Each session carries review details: lane, deployed version, commit, reviewer (pre-filled with the Mac user) and a free note. They persist in session.json and are inherited by the next session, so a review run is typed once. - PDF file names are Redline-<yyyyMMdd-HHmm>-<LANE>-<SHORTID>.pdf, and every page carries a two-line reference footer (tool, build time, session / lane, deployed build, commit, reviewer, note). The PDF document info carries the same values in Author and Keywords. - Verification: 159 tests, a headless panel self-test, and a LaunchServices-driven end-to-end run that types and clicks the real panel.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import SwiftUI
|
||||
import ShotdeckCore
|
||||
|
||||
/// The five review-detail fields of a session, in one compact grid.
|
||||
///
|
||||
/// Values are held locally while typing and written through to the session manifest
|
||||
/// on every change, so closing the panel cannot lose them. The local copy is re-seeded
|
||||
/// whenever the open session changes (a new session inherits the previous details).
|
||||
struct SessionContextEditor: View {
|
||||
@Environment(AppModel.self) private var model
|
||||
|
||||
@State private var lane = ""
|
||||
@State private var deployedVersion = ""
|
||||
@State private var commitHash = ""
|
||||
@State private var reviewer = ""
|
||||
@State private var note = ""
|
||||
@State private var seededSessionID: UUID?
|
||||
/// What this view last wrote (or seeded). Lets an out-of-band change — a context
|
||||
/// inherited by a new session, for example — refresh the fields without fighting
|
||||
/// the user's own keystrokes.
|
||||
@State private var lastKnownContext: ReviewContext = .empty
|
||||
/// The pending debounced write and its value. Typing replaces it, so one short
|
||||
/// pause writes once instead of once per keystroke, and an older write can never
|
||||
/// land after a newer one.
|
||||
@State private var pendingWrite: Task<Void, Never>?
|
||||
@State private var lastScheduledWrite: ReviewContext = .empty
|
||||
|
||||
private let labelWidth: CGFloat = 84
|
||||
|
||||
var body: some View {
|
||||
Grid(alignment: .leading, horizontalSpacing: 8, verticalSpacing: 4) {
|
||||
row("Lane", text: $lane, prompt: "dev03, customer test lane…")
|
||||
row("Deployed", text: $deployedVersion, prompt: "build that is live")
|
||||
row("Commit", text: $commitHash, prompt: "git SHA")
|
||||
row("Reviewer", text: $reviewer, prompt: "who is reviewing")
|
||||
row("Note", text: $note, prompt: "what this session covers")
|
||||
}
|
||||
.onAppear { seedIfNeeded() }
|
||||
.onChange(of: model.session.id) { _, _ in seedIfNeeded() }
|
||||
.onChange(of: model.session.context) { _, newValue in
|
||||
guard newValue != lastKnownContext else { return }
|
||||
seed(from: newValue)
|
||||
}
|
||||
.onChange(of: lane) { _, _ in commit() }
|
||||
.onChange(of: deployedVersion) { _, _ in commit() }
|
||||
.onChange(of: commitHash) { _, _ in commit() }
|
||||
.onChange(of: reviewer) { _, _ in commit() }
|
||||
.onChange(of: note) { _, _ in commit() }
|
||||
}
|
||||
|
||||
private func row(_ label: String, text: Binding<String>, prompt: String) -> some View {
|
||||
GridRow(alignment: .center) {
|
||||
Text(label)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: labelWidth, alignment: .trailing)
|
||||
TextField(prompt, text: text)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.font(.caption)
|
||||
.onSubmit { commit() }
|
||||
}
|
||||
}
|
||||
|
||||
private func seedIfNeeded() {
|
||||
guard seededSessionID != model.session.id else { return }
|
||||
seededSessionID = model.session.id
|
||||
seed(from: model.session.context)
|
||||
}
|
||||
|
||||
private func seed(from context: ReviewContext) {
|
||||
lane = context.lane
|
||||
deployedVersion = context.deployedVersion
|
||||
commitHash = context.commit
|
||||
reviewer = context.reviewer
|
||||
note = context.note
|
||||
lastKnownContext = context
|
||||
}
|
||||
|
||||
private func commit() {
|
||||
let context = ReviewContext(
|
||||
lane: lane,
|
||||
deployedVersion: deployedVersion,
|
||||
commit: commitHash,
|
||||
reviewer: reviewer,
|
||||
note: note
|
||||
)
|
||||
guard context != model.session.context else { return }
|
||||
guard context != lastScheduledWrite else { return }
|
||||
lastKnownContext = context
|
||||
lastScheduledWrite = context
|
||||
pendingWrite?.cancel()
|
||||
pendingWrite = Task {
|
||||
try? await Task.sleep(for: .milliseconds(150))
|
||||
guard !Task.isCancelled else { return }
|
||||
await model.setContextField(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user