site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Implement `Survey*` UI components for initial rating survey

Open aaemnnosttv opened this issue 5 years ago • 17 comments

Feature Description

While user surveys will be capable of displaying multiple questions of various types, the initial implementation will be limited to a single rating-type question only with two potential completions. This issue is about building the necessary UI components for this initial survey – none of which should be specific to the initial survey as far as the contents are concerned; this should all come via props.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • A new SurveyQuestionRating component should be created in assets/js/components/surveys/
    • It should require the following props:
      • question [string] – the question text
      • choices [array] available 5 answer objects with properties: answer_ordinal [int] and text [string]
      • answerQuestion [function] should be called with the answer object corresponding to the selected choice
      • dismissSurvey [function] should be called when the close button (X) is clicked
    • The text for labelling the low/high ends of the rating spectrum should come from the 1st and 5th choices respectively (passed via props)
      • Additionally, each individual choice should have its text value provided (visually hidden) on each choice element for accessibility
  • A new SurveyCompletion component should be created in assets/js/components/surveys/
    • It should require the following props:
      • title [string] – primary heading on the survey card
      • children [*] secondary text
      • ctaText [string] – text for follow up CTA button
      • ctaURL [string] – URL for follow up CTA button
      • ctaOnClick [function] – onClick handler for follow up CTA button
      • dismissSurvey [function] – should be called when the close button (X) is clicked
  • See the design for how this should look
  • Common components may be extracted as necessary
  • Storybook stories should be added for these two components

Implementation Brief

  • Create new file assets/js/components/surveys/SurveyQuestionRating which exports the SurveyQuestionRating functional component with the props defined in the AC.
    • Associate each answer_ordinal to the icon as in the designs in Figma, meaning answer_ordinal 1 will be the unhappy icon and answer_ordinal 5 will be the delighted icon. It's fine to hardcode the icons for now.
  • Create new file assets/js/components/surveys/SurveyCompletion which exports the SurveyCompletion functional component with the props defined in the AC.
  • Create new file assets/js/components/surveys/SurveyHeader which exports the SurveyHeader functional component with the following props:
    • title: [string] – text shown next to the Google logo.
    • dismissSurvey: [function] should be called when the close button (X) is clicked.
  • SurveyQuestionRating and SurveyCompletion should both use the SurveyHeader component to render the top section of the components, i.e where we have the Google logo, text and close button.
  • Components should be styled as per the designs in Figma, without the fixed position. This will be taken care of in #3375.
    • Use the Grid, Row and Cell components for the grid layout.
      • For rendering the icons, use a Row with 5 Cells which do no wrap across breakpoints. Each cell will also contain the "text" associated to the icon. For e.g "Unhappy" for 1 and "Delighted" for 5. The value can be obtained via the text property of each choice and the Button component should be used for rendering the icons.
      • The texts for Icon 1 and Icon 5 only should be visible at all times.
      • For accessibility, each icon should have the text visually hidden via the aria-label prop of the Button component.
      • As per the designs for desktop, the max width of the component is 400px and we should be able to reduce the width to 320px on small screens by reducing the padding between grid cells and the icon dimensions if necessary.
      • Upon hover, each icon should have a darker grey rounded background, similar to what is done for the "Help" icon here: https://google.github.io/site-kit-wp/storybook/develop/?path=/story/global--plugin-header-with-help-menu
  • SVGs (for the emojis) should be added in the assets/svg folder and prefixed with survey-. For e.g survey-unhappy.svg.
  • Instead of using the SVG from the designs for the close icon, we can use the closeSmall icon from @wordpress/icons. https://wordpress.github.io/gutenberg/?path=/story/icons-icon--library
  • All styles for the above components should go in assets/sass/components/survey/_googlesitekit-survey.scss.
  • Any class names used in the component should follow the BEM methodology, with the googlesitekit-survey prefix.
  • Create SurveyQuestionRating.stories.js and SurveyCompletion.stories.js which will contain the stories for both components.

Test Coverage

  • No tests to be added.

Visual Regression Changes

  • N/A

QA Brief

Check if the components from the following URLs: * https://google.github.io/site-kit-wp/storybook/pull/3436/?path=/story/components-surveys--survey-question-rating-story * https://google.github.io/site-kit-wp/storybook/pull/3436/?path=/story/components-surveys--survey-completion-story match the designs in Figma.

Changelog entry

  • Add React components for rendering user survey UI.

aaemnnosttv avatar May 19 '21 11:05 aaemnnosttv

ACs lgtm!

felixarntz avatar May 19 '21 18:05 felixarntz

@aaemnnosttv I've suggested we add another property, Icon for the answers object which is not present in the AC. Let me know what you think.

asvinb avatar May 20 '21 15:05 asvinb

@aaemnnosttv I've suggested we add another property, Icon for the answers object which is not present in the AC. Let me know what you think.

@asvinb we can't really do that since choices comes from the API. I think for the rating we can always assume it will be 5 choices but we should use the provided objects and associate them with their respective icons within the component. We also don't need the icons to be flexible right now and I'm not sure that we ever will.

  • Components should be styled as per the designs in Figma. * This includes using fixed positioning for the survey SurveyQuestionRating component with a 36px margin bottom and right.

These components shouldn't be concerned with positioning on the screen since that's only really relevant to the CurrentSurvey. Think of these components more like a base tooltip component. We should be able to write stories for these with the component(s) in place (just like any other) rather than it always rendering in a fixed position.

  • Use the Grid, Row and Cell components for the grid layout.

Would you please elaborate a little more on this? What kind of grid do we need for each? How many rows/cols and would it use the same in all viewports?

aaemnnosttv avatar May 25 '21 07:05 aaemnnosttv

Ready for another pass @aaemnnosttv

asvinb avatar May 25 '21 09:05 asvinb

Looks good @asvinb ! The only thing I'm not 💯 sure about is the "Unhappy" and "Delighted" text. I believe this should come from the 1st and 5th answer objects (from their text property) rather than hard-coding a translatable string (as we would normally). This part isn't defined either way in the IB but probably a detail which is missing in the AC too.

@felixarntz – can you clarify if the high/low range labels should be taken from the first and last answer objects or handled the same as normal i18n strings in the plugin?

aaemnnosttv avatar May 26 '21 08:05 aaemnnosttv

@asvinb @aaemnnosttv Indeed the labels should come from the API response. As a matter of fact, each of the five options has a human-readable label, and all of these should be considered:

  • The ones for the 1 and 5 rating should show on the left and right below the rating icons.
  • All from 1 to 5 should show on hover above the faces, or at a minimum be the text used for assistive technologies to which the icons wouldn't mean anything.

felixarntz avatar May 26 '21 13:05 felixarntz

Sounds good. IB updated @felixarntz , although I'am not clear for the hover state of each face. I don't see any designs for it. Any idea?

asvinb avatar May 26 '21 15:05 asvinb

@asvinb Good catch, I thought that had been captured in the Figma file somewhere, but it doesn't look like it.

The hover effect should surface a tooltip with the text as some sort of tooltip, with similar appearance how it is e.g. in Google Drive: Screen Shot 2021-05-26 at 1 55 59 PM

This would be great to do via a generally reusable component, e.g. TooltipIcon or so? For the first iteration though it would be also okay to only use the text as screen reader text and not do any hover effect, since adding that might increase the scope. @aaemnnosttv What do you think? Maybe add a follow-up issue to implement the hover tooltip via a reusable component? Such a component we should eventually then use for e.g. the icons in the Site Kit header bar as well.

felixarntz avatar May 26 '21 18:05 felixarntz

This would be great to do via a generally reusable component, e.g. TooltipIcon or so? For the first iteration though it would be also okay to only use the text as screen reader text and not do any hover effect, since adding that might increase the scope. @aaemnnosttv What do you think? Maybe add a follow-up issue to implement the hover tooltip via a reusable component? Such a component we should eventually then use for e.g. the icons in the Site Kit header bar as well.

@felixarntz I think it could be okay to include the component here if it didn't require substantial additional effort. Maybe for now it could be local to surveys/ and we can extract it to something more generic, add stories etc in a follow-up issue. I agree we should keep the scope the same here though so I don't think the ACs need to change that much, but I'll amend them to clarify the source of the text and accessibility details 👍

aaemnnosttv avatar May 27 '21 07:05 aaemnnosttv

@asvinb I've updated the ACs to reflect the clarifications from @felixarntz.

Note that the full hover state+tooltip is not required, but is more of a nice to have for now. If it's not going to complicate things we can include it, but otherwise best to leave for a future enhancement. For now, I think we can follow what we already have in the plugin header (e.g. help menu icon) which I believe is just background color and border radius; the color is inherited.

Assigning back to you for any finishing touches, but otherwise I think we're good to go here.

aaemnnosttv avatar May 27 '21 08:05 aaemnnosttv

@aaemnnosttv IB updated. Can you review? One notable thing I added is using the Button component to display the icons and then use the aria-label prop to pass the text property of each choice.

asvinb avatar May 27 '21 08:05 asvinb

IB ✅

aaemnnosttv avatar May 27 '21 13:05 aaemnnosttv

Increasing estimate from 11 to 15 to account for additional QA time required for UI changes.

eclarke1 avatar May 28 '21 08:05 eclarke1

Just noticed @aaemnnosttv was the original reviewer here; in the interest of working on #3380 I'm going to assign this one to him again for now. 😅

tofumatt avatar May 31 '21 17:05 tofumatt

QA ⚠️

Need to verify a couple of points below. Apart from those, it all seems good. @aaemnnosttv can you provide any guidance here?

SurveyQuestionRating

  • A new component has been created in the specified location
  • The new component requires the correct props
  • The text for the low and high ends come from the 1st and 5th choice props, as specified.
  • ⚠️ Text on the choices is visually hidden, but this is done with display: none;, which I believe hides the text from screen readers.
  • ⚠️ The component looks exactly like the designs as far as I can make out, although at storybook's 'small mobile' setting, it overflows:

Screenshot 2021-06-02 at 17 07 36

SurveyCompletion

  • A new component has been created in the specified location
  • The new component requires the correct props
  • The component looks exactly like the designs

johnPhillips avatar Jun 02 '21 16:06 johnPhillips

⚠️ Text on the choices is visually hidden, but this is done with display: none;, which I believe hides the text from screen readers.

@johnPhillips that may be but this text is not intended for screen readers; each button wrapping the choices gets an appropriate aria-label attribute for this purpose.

⚠️ The component looks exactly like the designs as far as I can make out, although at storybook's 'small mobile' setting, it overflows

Taking a closer look, the main problem there is the added 50px of padding on either side which isn't representative of the components. That's not to say either whether or not we would want to show these in mobile at all. Since this issue is just about the UI component though, the overflow only starts to happen at a width below 260px which is likely smaller than most phones so it's not something we need to worry about now I think.

image

aaemnnosttv avatar Jun 03 '21 10:06 aaemnnosttv

Thanks @aaemnnosttv!

QA ✅

johnPhillips avatar Jun 03 '21 10:06 johnPhillips