From 118394f290108d10ceaa97e2f6fc8864ecabcbb7 Mon Sep 17 00:00:00 2001 From: Dmitry Pogrebnoy Date: Tue, 27 Feb 2024 12:32:47 +0100 Subject: [PATCH] [Feedback] IDEBIS-37 Implement A/B experiment for evaluation feedback dialogs for Rider We need to override RiderExternalResourceUrlsBase class to be able to implement a custom feedback reporter in another module. It helps us overcome the problem of dependencies. IJ-CR-126889 GitOrigin-RevId: e82a47daf9109c6e785bf1df30d45283b8d306f8 --- .../CommonFeedbackMessagesBundle.properties | 3 +- .../aqua/dialog/AquaNewUserFeedbackDialog.kt | 4 +- .../demo/dialog/DemoFeedbackDialog.kt | 2 +- .../dialog/DemoFeedbackDialogWithEmail.kt | 2 +- .../feedback/dialog/FeedbackUIUtils.kt | 7 ++- .../dialog/uiBlocks/CheckBoxGroupBlock.kt | 50 +++++++++---------- .../dialog/uiBlocks/CheckBoxItemData.kt | 2 +- .../feedback/dialog/uiBlocks/TextAreaBlock.kt | 16 +++--- 8 files changed, 44 insertions(+), 42 deletions(-) diff --git a/platform/feedback/resources/messages/CommonFeedbackMessagesBundle.properties b/platform/feedback/resources/messages/CommonFeedbackMessagesBundle.properties index 39a2109acc8d..c487ee9ab31a 100644 --- a/platform/feedback/resources/messages/CommonFeedbackMessagesBundle.properties +++ b/platform/feedback/resources/messages/CommonFeedbackMessagesBundle.properties @@ -42,7 +42,8 @@ dialog.feedback.block.required=Rate all options dialog.feedback.combobox.required=Choose a value dialog.feedback.checkboxGroup.other.placeholder=Other -dialog.feedback.checkboxGroup.require.not.empty=Choose options or write your own +dialog.feedback.checkboxGroup.require.not.empty=Choose options +dialog.feedback.checkboxGroup.require.not.empty.with.other=Choose options or write your own dialog.feedback.radioGroup.require.not.empty=Choose an option diff --git a/platform/feedback/src/com/intellij/platform/feedback/aqua/dialog/AquaNewUserFeedbackDialog.kt b/platform/feedback/src/com/intellij/platform/feedback/aqua/dialog/AquaNewUserFeedbackDialog.kt index 76f25dbe9f13..3efaf918782c 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/aqua/dialog/AquaNewUserFeedbackDialog.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/aqua/dialog/AquaNewUserFeedbackDialog.kt @@ -40,7 +40,7 @@ class AquaNewUserFeedbackDialog( ) }, "primary_daily_tasks" - ).addOtherTextField(), + ).addOtherTextField().requireAnswer(), ComboBoxBlock( AquaFeedbackBundle.message("new.user.dialog.team.size.label"), List(5) { @@ -57,7 +57,7 @@ class AquaNewUserFeedbackDialog( ) }, "primary_testing_targets" - ).addOtherTextField(), + ).addOtherTextField().requireAnswer(), ) override val mySystemInfoData: CommonFeedbackSystemData by lazy { diff --git a/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialog.kt b/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialog.kt index e7db044865c8..7cfa3eb8d28b 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialog.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialog.kt @@ -46,7 +46,7 @@ class DemoFeedbackDialog( CheckBoxItemData(DemoFeedbackBundle.message("dialog.checkbox.item.${it}.label"), "checkbox_${it}") }, "checkbox_group") - .addOtherTextField(), + .addOtherTextField().requireAnswer(), TextAreaBlock(DemoFeedbackBundle.message("dialog.textarea.label"), "textarea") ) diff --git a/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialogWithEmail.kt b/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialogWithEmail.kt index d629ec022217..90ab990ebc5b 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialogWithEmail.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/demo/dialog/DemoFeedbackDialogWithEmail.kt @@ -50,7 +50,7 @@ class DemoFeedbackDialogWithEmail( CheckBoxItemData(DemoFeedbackBundle.message("dialog.checkbox.item.${it}.label"), "checkbox_${it}") }, "checkbox_group") - .addOtherTextField(), + .addOtherTextField().requireAnswer(), TextAreaBlock(DemoFeedbackBundle.message("dialog.textarea.label"), "textarea") ) diff --git a/platform/feedback/src/com/intellij/platform/feedback/dialog/FeedbackUIUtils.kt b/platform/feedback/src/com/intellij/platform/feedback/dialog/FeedbackUIUtils.kt index b0e8d9310529..d15b78245fa8 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/dialog/FeedbackUIUtils.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/dialog/FeedbackUIUtils.kt @@ -14,7 +14,7 @@ import java.awt.event.KeyAdapter import java.awt.event.KeyEvent -internal fun JBTextArea.adjustBehaviourForFeedbackForm() { +fun JBTextArea.adjustBehaviourForFeedbackForm() { wrapStyleWord = true lineWrap = true addKeyListener(object : KeyAdapter() { @@ -32,8 +32,7 @@ internal fun JBTextArea.adjustBehaviourForFeedbackForm() { }) } -internal const val TEXT_AREA_ROW_SIZE = 5 -internal const val TEXT_AREA_COLUMN_SIZE = 42 +const val TEXT_AREA_ROW_SIZE = 5 internal const val TEXT_FIELD_EMAIL_COLUMN_SIZE = 25 internal const val COMBOBOX_COLUMN_SIZE = 25 @@ -49,7 +48,7 @@ internal fun Row.feedbackAgreement(project: Project?, @NlsContexts.DetailedDescr } } -internal fun createBoldJBLabel(@NlsContexts.Label label: String): JBLabel { +fun createBoldJBLabel(@NlsContexts.Label label: String): JBLabel { return JBLabel(label).apply { font = JBFont.create(font.deriveFont(Font.BOLD), false) } diff --git a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxGroupBlock.kt b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxGroupBlock.kt index 292cf1fa9096..d7aeddc30c7d 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxGroupBlock.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxGroupBlock.kt @@ -12,8 +12,8 @@ import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.put import java.awt.event.FocusEvent import java.awt.event.FocusListener +import java.awt.event.MouseAdapter import java.awt.event.MouseEvent -import java.awt.event.MouseListener import javax.swing.event.ChangeEvent import javax.swing.event.ChangeListener @@ -35,17 +35,29 @@ class CheckBoxGroupBlock( panel.apply { buttonsGroup(indent = false) { row { - label(myGroupLabel).bold().errorOnApply(CommonFeedbackBundle.message("dialog.feedback.checkboxGroup.require.not.empty")) { - val isAllCheckboxEmpty = allCheckBoxes.all { - !it.isSelected - } - if (myIncludeOtherTextField) { - return@errorOnApply isAllCheckboxEmpty && - (otherCheckBox?.isSelected == false || - (otherCheckBox?.isSelected == true && otherTextField?.text?.isBlank() == true)) - } - else { - return@errorOnApply isAllCheckboxEmpty + label(myGroupLabel).apply { + bold() + if (requireAnswer) { + val errorMessage = if (myIncludeOtherTextField) { + CommonFeedbackBundle.message("dialog.feedback.checkboxGroup.require.not.empty.with.other") + } + else { + CommonFeedbackBundle.message("dialog.feedback.checkboxGroup.require.not.empty") + } + + errorOnApply(errorMessage) { + val isAllCheckboxEmpty = allCheckBoxes.all { + !it.isSelected + } + if (myIncludeOtherTextField) { + return@errorOnApply isAllCheckboxEmpty && + (otherCheckBox?.isSelected == false || + (otherCheckBox?.isSelected == true && otherTextField?.text?.isBlank() == true)) + } + else { + return@errorOnApply isAllCheckboxEmpty + } + } } } }.bottomGap(BottomGap.NONE) @@ -93,23 +105,11 @@ class CheckBoxGroupBlock( } } }) - addMouseListener(object : MouseListener { + addMouseListener(object : MouseAdapter() { override fun mouseClicked(e: MouseEvent?) { otherCheckBox?.setSelected(true) requestFocusInWindow() } - - override fun mousePressed(e: MouseEvent?) { - } - - override fun mouseReleased(e: MouseEvent?) { - } - - override fun mouseEntered(e: MouseEvent?) { - } - - override fun mouseExited(e: MouseEvent?) { - } }) } otherCheckBox?.apply { diff --git a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxItemData.kt b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxItemData.kt index cf54b42de1fc..168f803bf50a 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxItemData.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/CheckBoxItemData.kt @@ -5,5 +5,5 @@ import com.intellij.openapi.util.NlsContexts data class CheckBoxItemData(@NlsContexts.Checkbox val label: String, val jsonElementName: String) { - internal var property: Boolean = false + var property: Boolean = false } diff --git a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/TextAreaBlock.kt b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/TextAreaBlock.kt index c682bf7a952e..34612c4bb7db 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/TextAreaBlock.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/dialog/uiBlocks/TextAreaBlock.kt @@ -3,7 +3,6 @@ package com.intellij.platform.feedback.dialog.uiBlocks import com.intellij.openapi.util.NlsContexts import com.intellij.openapi.util.NlsSafe -import com.intellij.platform.feedback.dialog.TEXT_AREA_COLUMN_SIZE import com.intellij.platform.feedback.dialog.TEXT_AREA_ROW_SIZE import com.intellij.platform.feedback.dialog.adjustBehaviourForFeedbackForm import com.intellij.platform.feedback.dialog.createBoldJBLabel @@ -15,10 +14,10 @@ class TextAreaBlock(@NlsContexts.Label private val myLabel: String, private val myJsonElementName: String) : FeedbackBlock, TextDescriptionProvider, JsonDataProvider { private var myProperty: String = "" private var myTextAreaRowSize: Int = TEXT_AREA_ROW_SIZE - private var myTextAreaColumnSize: Int = TEXT_AREA_COLUMN_SIZE @NlsSafe private var myRequireNotEmptyMessage: String? = null + private var myPlaceholder: String? = null override fun addToPanel(panel: Panel) { panel.apply { @@ -37,6 +36,9 @@ class TextAreaBlock(@NlsContexts.Label private val myLabel: String, it.text.isBlank() } } + if (myPlaceholder != null) { + this.component.emptyText.text = myPlaceholder!! + } } }.bottomGap(BottomGap.MEDIUM) } @@ -61,13 +63,13 @@ class TextAreaBlock(@NlsContexts.Label private val myLabel: String, return this } - fun setColumnSize(columnSize: Int): TextAreaBlock { - myTextAreaColumnSize = columnSize - return this - } - fun requireNotEmpty(@NlsContexts.Label requireNotEmptyMessage: String): TextAreaBlock { myRequireNotEmptyMessage = requireNotEmptyMessage return this } + + fun setPlaceholder(placeholder: String): TextAreaBlock { + myPlaceholder = placeholder + return this + } } \ No newline at end of file