Skip to content

Feedback presend warning

Hans5958 edited this page Jun 21, 2023 · 4 revisions

The feedback presend warning system (PSW) is a mechanism that warns the feedback writer before submitting a feedback with a specific RegEx triggers.

How it works is when the Submit button is pressed and a RegEx pattern matches the feedback content, a warning will be shown, and the submit button will be disabled for 5 seconds. If 5 seconds have elapsed, and nothing is changed on the content field, the Submit button can be pressed again and the feedback will be submitted. It is the developer's wish that the user to reconsider sending the feedback when the warning is shown.

Adding a warning

To add a warning, do the following steps:

  1. Add the relevant i18n key strings on i18n/en.yml.

    Inside the FeedbackPage.PreSendWarning dictionary, add a dictionary with the key of the warning ID you choose. Inside of this dictionary, add strings with Heading and Description as the key. In some cases, the dictionary may be adjusted, but the previously mentioned format is recommended.

    The Heading string should be short enough, but still convoys the reasoning of the warning being triggered (e.g. if the trigger is related to themes, the heading should have themes on it, like Some themes are not working due to a bug.

    The Description string should include additional information related to the warning, such as contexts related to the bug, advices to work around the bug, relevant links, etc.

    Placeholders (e.g. {{ .Tag1Start }}) can be added as you wish.

    For example, here's an example with the warning ID of NotST.

    FeedbackPage:
      # ...
      PreSendWarning:
          # ...
          NotST:
            Heading: We are not the Scratch Team.
            Description: Keep in mind that Scratch Addons is not affiliated with the Scratch website or the organizations that maintain it.
  2. Add the relevant object on layouts/shortcodes/specifics/feedback-form.html

    Inside window.i18nStrings.preSendWarning.variations (the window.i18nStrings object, then inside of it, preSendWarning.variations), add a object with the key of the warning ID you choose, but in camelCase. Inside of this object, add strings with heading and description as the key. In some cases, the object may be adjusted, but the previously mentioned format is recommended.

    If there are placeholders (e.g. {{ .Tag1Start }}), you should use the $ts value to fill the placeholder. Since the system replaces the placeholder value in JavaScript (not Hugo), it needs to use the $ts value to differentiate the strings from the translators and the placeholder itself.

    For example, here's an example with the warning ID of NotST.

    window.i18nStrings = {
    	// ...
    	preSendWarning: {
    		// ...
    		variations: {
    			// ...
    			notST: {
    				heading: '{{ T "FeedbackPage.PreSendWarning.Variations.NotST.Heading" }}',
    				description: '{{ T "FeedbackPage.PreSendWarning.Variations.NotST.Description" | htmlEscape }}',
    			},
    		}
    	},
    }
  3. Add the relevant object on static/assets/js/feedback.js

    Inside variations, add a object with the key of the warning ID you choose, but in camelCase. Inside of this object, add strings that contain the strings (...i18n.preSendWarning.variations.warningId) and patterns that contain the RegEx patterns that will trigger the warning in an array.

    If there are placeholders (e.g. {{ .Tag1Start }}), you should replace the $ts placeholders with the real values.

    For example, here's an example with the warning ID of NotST.

    const variations = {
    // ...
    notST: {
    	strings: {
    		...i18n.preSendWarning.variations.notST
    	},
    	patterns: [
    		/\bscratch\s*team\b/i,
    		/\bst\b/,
    	]
    },
    }

Removing a warning

To remove a warning, remove the added parts mentioned on the previous section. For temporary warnings, the recommended time to remove the warning is on the next minor release of Scratch Addons.