Skip to content

Commit

Permalink
Remove option to report error in github and add option to copy error …
Browse files Browse the repository at this point in the history
…to clipboard (#3351)

<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
  • Loading branch information
bgoncal authored Jan 22, 2025
1 parent b3aa00a commit bc5b9a4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
1 change: 1 addition & 0 deletions Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"component.collapsible_view.expand" = "Expand";
"connection.error.details.button.discord" = "Ask in Discord";
"connection.error.details.button.doc" = "Read documentation";
"connection.error.details.button.clipboard" = "Copy to clipboard";
"connection.error.details.button.github" = "Report issue in GitHub";
"connection.error.details.button.search_github" = "Search in GitHub";
"connection.error.details.label.code" = "Code";
Expand Down
32 changes: 24 additions & 8 deletions Sources/App/WebView/ConnectionErrorDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI

struct ConnectionErrorDetailsView: View {
@Environment(\.dismiss) private var dismiss
private let feedbackGenerator = UINotificationFeedbackGenerator()
let error: Error
var body: some View {
ScrollView {
Expand All @@ -25,6 +26,7 @@ struct ConnectionErrorDetailsView: View {
}
}
.padding(.vertical)
copyToClipboardButton
documentationLink
discordLink
githubLink
Expand All @@ -42,6 +44,28 @@ struct ConnectionErrorDetailsView: View {
}
}

private var copyToClipboardButton: some View {
ActionLinkButton(
icon: Image(systemSymbol: .docOnDoc),
title: L10n.Connection.Error.Details.Button.clipboard,
tint: .init(uiColor: Asset.Colors.haPrimary.color)
) {
UIPasteboard.general
.string =
"""
\(L10n.Connection.Error.Details.Label.description): \n
\(error.localizedDescription) \n
\(L10n.Connection.Error.Details.Label.domain): \n
\((error as NSError).domain) \n
\(L10n.Connection.Error.Details.Label.code): \n
\((error as NSError).code) \n
\(L10n.urlLabel): \n
\((error as? URLError)?.failingURL?.absoluteString ?? "")
"""
feedbackGenerator.notificationOccurred(.success)
}
}

private var documentationLink: some View {
ExternalLinkButton(
icon: Image(systemSymbol: .docTextFill),
Expand All @@ -62,14 +86,6 @@ struct ConnectionErrorDetailsView: View {

@ViewBuilder
private var githubLink: some View {
ExternalLinkButton(
icon: Image("github.fill"),
title: L10n.Connection.Error.Details.Button.github,
url: ExternalLink.githubReportIssue,
tint: .init(uiColor: .init(dynamicProvider: { trait in
trait.userInterfaceStyle == .dark ? .white : .black
}))
)
if let searchURL = ExternalLink.githubSearchIssue(domain: (error as NSError).domain) {
ExternalLinkButton(
icon: Image("github.fill"),
Expand Down
35 changes: 35 additions & 0 deletions Sources/Shared/DesignSystem/Components/ExternalLinkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ public struct ExternalLinkButton: View {
}
}

public struct ActionLinkButton: View {
let icon: Image
let title: String
let tint: Color
let action: () -> Void

public init(icon: Image, title: String, tint: Color, action: @escaping () -> Void) {
self.icon = icon
self.title = title
self.tint = tint
self.action = action
}

public var body: some View {
Button(action: {
action()
}, label: {
HStack(spacing: Spaces.two) {
icon
.frame(width: 30, height: 30)
.font(.title2)
.tint(tint)
Text(title)
.frame(maxWidth: .infinity, alignment: .leading)
.tint(Color(uiColor: .label))
.font(.body.bold())
}
})
.frame(maxWidth: 600)
.padding()
.background(Color(uiColor: .secondarySystemBackground))
.clipShape(RoundedRectangle(cornerRadius: 12))
}
}

#Preview {
VStack {}
.sheet(isPresented: .constant(true)) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ public enum L10n {
/// Connection error
public static var title: String { return L10n.tr("Localizable", "connection.error.details.title") }
public enum Button {
/// Copy to clipboard
public static var clipboard: String { return L10n.tr("Localizable", "connection.error.details.button.clipboard") }
/// Ask in Discord
public static var discord: String { return L10n.tr("Localizable", "connection.error.details.button.discord") }
/// Read documentation
Expand Down

0 comments on commit bc5b9a4

Please sign in to comment.