import SwiftUI /// The bounded Engineering listing, shared by the phone tab and Mac detail. struct ChangedFilesList: View { let facts: ThinChangeFiles var openFile: (ThinChangedFile) -> Void var body: some View { VStack(alignment: .leading, spacing: 16) { Text(ChangedFilesPresentation.total(files: facts.files, additions: facts.additions, deletions: facts.deletions)) .font(.headline).fixedSize(horizontal: false, vertical: true) ForEach(ChangedFilesPresentation.groups(facts)) { group in VStack(alignment: .leading, spacing: 0) { if !group.folder.isEmpty { Text(verbatim: VisibleCodeText.display(group.folder)).font(Typo.secondaryStrong).foregroundStyle(Palette.secondary).padding(.bottom, 8) } ForEach(group.files) { file in Button { openFile(file) } label: { ChangedFileLabel(file: file) } .buttonStyle(.plain) .accessibilityLabel(accessibility(file)) .accessibilityIdentifier("changed-file-" + file.path) Divider() } } } if facts.truncated { Text(String(format: EquipoStrings.text("native.changes.truncated"), facts.entries.count)) .font(Typo.secondary).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true) } } } private func accessibility(_ file: ThinChangedFile) -> String { [ChangedFilesPresentation.displayPath(file), ChangedFilesPresentation.status(file), ChangedFilesPresentation.renamedFrom(file), file.binary ? EquipoStrings.text("native.changes.binary") : ChangedFilesPresentation.total(files: 1, additions: file.additions, deletions: file.deletions)] .compactMap { $0 }.joined(separator: ", ") } } private struct ChangedFileLabel: View { let file: ThinChangedFile var body: some View { HStack(alignment: .top, spacing: 12) { VStack(alignment: .leading, spacing: 6) { Text(verbatim: ChangedFilesPresentation.displayPath(file)).font(.system(.subheadline, design: .monospaced)) .foregroundStyle(Palette.text).fixedSize(horizontal: false, vertical: true) if let old = ChangedFilesPresentation.renamedFrom(file) { Text(verbatim: old) .font(Typo.caption).foregroundStyle(Palette.secondary).fixedSize(horizontal: false, vertical: true) } HStack(spacing: 12) { Text(ChangedFilesPresentation.status(file)).font(Typo.caption).foregroundStyle(Palette.secondary) if file.binary { Text(EquipoStrings.text("native.changes.binary")).font(Typo.caption).foregroundStyle(Palette.secondary) } else { Text(verbatim: "+\(file.additions)").foregroundStyle(Palette.positive) Text(verbatim: "−\(file.deletions)").foregroundStyle(Palette.negative) } }.font(.system(.caption, design: .monospaced)) }.frame(maxWidth: .infinity, alignment: .leading) Image(systemName: "chevron.right").font(.caption).foregroundStyle(Palette.secondary) }.padding(.vertical, 12).frame(minHeight: 44).contentShape(Rectangle()) } }