From f090e076543e8035c10cd01cfa7a844d96e93fd0 Mon Sep 17 00:00:00 2001 From: Vadym Struts Date: Wed, 8 Jan 2025 14:04:33 +0100 Subject: [PATCH] fix contact info + key press handling + labels Signed-off-by: Vadym Struts --- .../res/layout/report_broken_site_layout.xml | 10 +++++++- .../android/strings/android_brave_strings.grd | 5 +++- .../webcompat_reporter_ui.cc | 7 ++++++ .../resources/brave_components_strings.grd | 1 + .../browser/webcompat_reporter_service.cc | 2 ++ .../ui/components/ReportView.tsx | 24 +++++++++++++++++++ components/webui/webui_resources.cc | 2 ++ 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/android/java/res/layout/report_broken_site_layout.xml b/android/java/res/layout/report_broken_site_layout.xml index 495bf4e4dafc..b544b44d9931 100644 --- a/android/java/res/layout/report_broken_site_layout.xml +++ b/android/java/res/layout/report_broken_site_layout.xml @@ -80,7 +80,6 @@ android:id="@+id/contact_info_text" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="14dp" android:hint="@string/report_broken_site_contact_placeholder" android:importantForAutofill="no" android:maxLines="1" @@ -90,6 +89,15 @@ android:textColor="@color/wallet_text_color" android:textColorHint="@color/brave_theme_hint_text" /> + + - Thank you for helping make Brave better for all. This report will only contain information necessary for us to fix this site. %1$s + Thank you for helping make Brave better for all. This report will only contain information necessary for us to fix this site. If you provide contact info it will be stored for future reports. %1$s Learn more. @@ -1675,6 +1675,9 @@ Are you sure you want to do this? Contact me at: (optional) + + If you provide contact info it will be stored for future reports. + Email, Twitter, etc. diff --git a/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc index 529489571dc5..3a16aa52c72a 100644 --- a/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc +++ b/browser/ui/webui/webcompat_reporter/webcompat_reporter_ui.cc @@ -238,6 +238,13 @@ void WebcompatReporterDOMHandler::HandleSubmitReport( pending_report_->contact = contact_arg->GetString(); } + // if (contact_arg != nullptr && contact_arg->is_string() && + // !contact_arg->GetString().empty()) { + // pending_report_->contact = contact_arg->GetString(); + // } else { + // reporter_service_->SetContactInfoSaveFlag(false); + // } + if (reporter_service_) { reporter_service_->SubmitWebcompatReport(pending_report_->Clone()); } diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 42be235ef86f..15b7f0ca3dc0 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -451,6 +451,7 @@ This page cannot be reported because it was not served over HTTP/HTTPS. This page is a local web page and is not eligible for reporting. This is an error page. It cannot be reported as a broken site. + If you provide contact info it will be stored for future reports. Thank you for helping make Brave better for all. This report will only contain information necessary for us to fix this site. Learn more. Additional details (optional) diff --git a/components/webcompat_reporter/browser/webcompat_reporter_service.cc b/components/webcompat_reporter/browser/webcompat_reporter_service.cc index ac2e4eee07a7..9bf3a2a53b06 100644 --- a/components/webcompat_reporter/browser/webcompat_reporter_service.cc +++ b/components/webcompat_reporter/browser/webcompat_reporter_service.cc @@ -94,8 +94,10 @@ void ProcessContactInfo( return; } if (!report_info->contact || report_info->contact->empty()) { + profile_prefs->ClearPref(webcompat_reporter::prefs::kContactInfoPrefs); return; } + profile_prefs->SetString( webcompat_reporter::prefs::kContactInfoPrefs, profile_prefs->GetBooleanOr( diff --git a/components/webcompat_reporter/ui/components/ReportView.tsx b/components/webcompat_reporter/ui/components/ReportView.tsx index ae96f6bf45af..7cba5644be35 100644 --- a/components/webcompat_reporter/ui/components/ReportView.tsx +++ b/components/webcompat_reporter/ui/components/ReportView.tsx @@ -52,6 +52,8 @@ interface State { const WEBCOMPAT_INFO_WIKI_URL = 'https://github.com/brave/brave-browser/wiki/Web-compatibility-reports' export default class ReportView extends React.PureComponent { + private handleKeyPress: (e: KeyboardEvent) => void; + constructor (props: Props) { super(props) this.state = { @@ -60,6 +62,17 @@ export default class ReportView extends React.PureComponent { attachScreenshot: false, screenshotObjectUrl: null } + this.handleKeyPress = this._handleKeyPress.bind(this); + } + + private _handleKeyPress(e: KeyboardEvent) { + const { onClose, onSubmitReport } = this.props; + const { details, contact, attachScreenshot } = this.state + if (e.key === 'Escape') { + onClose(); + } else if (e.key === 'Enter') { + onSubmitReport(details, contact, attachScreenshot); + } } handleContactInfoChange = async (ev: React.ChangeEvent) => { @@ -97,6 +110,14 @@ export default class ReportView extends React.PureComponent { window.open(screenshotObjectUrl, '_blank', 'noopener') } + componentDidMount() { + document.addEventListener('keydown', this.handleKeyPress); + } + + componentWillUnmount() { + document.removeEventListener('keydown', this.handleKeyPress); + } + render () { const { siteUrl, @@ -151,6 +172,9 @@ export default class ReportView extends React.PureComponent { value={contact} id='contact-info' /> + + {getLocale('reportContactPopupInfoLabel')} + GetWebUILocalizedStrings( IDS_BRAVE_WEBCOMPATREPORTER_REPORT_CONTACT_PLACEHOLDER}, {"reportContactLabel", IDS_BRAVE_WEBCOMPATREPORTER_REPORT_CONTACT_LABEL}, + {"reportContactPopupInfoLabel", + IDS_BRAVE_WEBCOMPATREPORTER_REPORT_CONTACT_INFO_APOPUP_EXPL}, {"attachScreenshotLabel", IDS_BRAVE_WEBCOMPATREPORTER_ATTACH_SCREENSHOT_LABEL}, {"viewScreenshotLabel",