Skip to content

Commit

Permalink
Site Monitoring: Fix line break mode for web server log request url (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
momo-ozawa authored Feb 19, 2024
2 parents 0a626ca + 01e04a9 commit d6978e2
Showing 1 changed file with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ struct WebServerLogsView: View {
Spacer()
}
} else {
List {
Section {
ForEach(viewModel.loadedLogs) { entry in
makeRow(for: entry)
}
if viewModel.hasMore {
footerRow
GeometryReader { geometry in
List {
Section {
ForEach(viewModel.loadedLogs) { entry in
makeRow(for: entry, width: geometry.size.width)
}
if viewModel.hasMore {
footerRow
}
}
.listSectionSeparator(.hidden, edges: .bottom)
}
.listSectionSeparator(.hidden, edges: .bottom)
.listStyle(.plain)
}
.listStyle(.plain)
}
}

Expand Down Expand Up @@ -113,13 +115,13 @@ struct WebServerLogsView: View {
}
}

private func makeRow(for entry: AtomicWebServerLogEntry) -> some View {
private func makeRow(for entry: AtomicWebServerLogEntry, width: CGFloat) -> some View {
let attributedDescription = entry.attributedDescription
return NavigationLink(destination: {
SiteMonitoringEntryDetailsView(text: attributedDescription)
.onAppear { WPAnalytics.track(.siteMonitoringEntryDetailsShown, properties: ["tab": "web_server_logs"]) }
}) {
WebServerLogsRowView(entry: entry)
WebServerLogsRowView(entry: entry, width: width)
.swipeActions(edge: .trailing) {
ShareLink(item: attributedDescription.string) {
Label("Share", systemImage: "square.and.arrow.up")
Expand Down Expand Up @@ -150,7 +152,10 @@ struct WebServerLogsView: View {
}

private struct WebServerLogsRowView: View {
@State private var requestUrlHeight: CGFloat = .zero

let entry: AtomicWebServerLogEntry
let width: CGFloat

var body: some View {
VStack(alignment: .leading) {
Expand All @@ -170,13 +175,33 @@ private struct WebServerLogsRowView: View {
.font(.system(.footnote))
.foregroundStyle(.secondary)
}
Text(entry.requestUrl ?? "")
.font(.system(.subheadline))
.lineLimit(3)
WebServerLogUrlLabel(text: entry.requestUrl ?? "", width: width)
}
}
}

private struct WebServerLogUrlLabel: UIViewRepresentable {
let text: String
let width: CGFloat

func makeUIView(context: Context) -> UILabel {
let label = UILabel()
label.text = text
label.preferredMaxLayoutWidth = width
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
label.setContentHuggingPriority(.defaultHigh, for: .vertical)
label.numberOfLines = 3
label.lineBreakMode = .byCharWrapping
label.font = .preferredFont(forTextStyle: .subheadline)
label.adjustsFontForContentSizeCategory = true
return label
}

func updateUIView(_ uiView: UILabel, context: Context) {
// Do nothing
}
}

@MainActor
final class WebServerLogsViewModel: ObservableObject {
private let blog: Blog
Expand Down

0 comments on commit d6978e2

Please sign in to comment.