Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: logic for conditionally rendering feedback UI #2678

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

Mike-Heneghan
Copy link
Contributor

@Mike-Heneghan Mike-Heneghan commented Jan 18, 2024

What

  • Based on Figma prototype conditionally render the new UI components
  • Add dummy form submission methods and basic inout validation

Why

  • Sets up the paths for users to provide feedback
  • Discrete chunk of work which can be tested / reviewed

Testing

Screen recording

Screen.Recording.2024-01-18.at.15.14.59.mov

Copy link

github-actions bot commented Jan 18, 2024

Removed vultr server and associated DNS entries

);
const previousFeedbackView = usePrevious(currentFeedbackView);

function handleFeedbackViewClick(event: FeedbackViewClickEvents) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried implementing the handler as a single function with a switch statement which I think has worked pretty well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - nice and need and maintainable! Take a look at my comment below on how we could make this a little safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there's an opportunity to refactor this file, potentially splitting into more components and reusing more content? Although I don't want to get too bogged down in optimisations I suppose and can always come back to it later?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a nice to have in future I think - for now it feels ok to group them? We can always come back and split up (and maybe write some Storybook stories) and tests sometime soon?

@Mike-Heneghan Mike-Heneghan self-assigned this Jan 19, 2024
@Mike-Heneghan Mike-Heneghan requested a review from a team January 19, 2024 11:47
@Mike-Heneghan Mike-Heneghan marked this pull request as ready for review January 19, 2024 11:47
@Mike-Heneghan
Copy link
Contributor Author

@ianjon3s
Copy link
Contributor

I've had a click through test of this and it's all working perfectly from a user-perspective!

@Mike-Heneghan
Copy link
Contributor Author

I've had a click through test of this and it's all working perfectly from a user-perspective!

Thanks for checking this Ian! It was really helpful having your prototype for this work 🙌

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super clean and nice code - a pleasure to review!

A few minor comments and suggestions, nothing blocking.

Some small UI / design thoughts (these are for @ianjon3s to think about also...!) -

image

  • The white on grey here feels quite hard to look at - is there an alternative or is this ok?

  • Should we use the ErrorWrapper component over native browser validation (e.g. for required fields)? The benefits would be a more consistent UI and we also now capture analytics via the ErrorWrapper which could be useful to track.

editor.planx.uk/src/ui/public/FeedbackOption.tsx Outdated Show resolved Hide resolved
editor.planx.uk/src/components/Feedback.tsx Outdated Show resolved Hide resolved
}
}

const handleFeedbackFormSubmit = (e: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e: any is great for now but once we have a real form (and maybe Formik) wired up we should make sure to type this correctly 👍

);
}

function Feedback(): FCReturn {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TypeScript switch statements don't read types as nicely as they should unfortunately.

I'd suggest adding an exhaustive check here as it would throw a type error if we added a new FeedbackView but didn't update this case statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh maybe we should enforce this with something like https://typescript-eslint.io/rules/switch-exhaustiveness-check/ to avoid having to repeatedly use an exhausive guard. Maybe a nicer solution!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very interesting point and I can definitely imagine lots of situations where the switch isn't updated.

I had a wee look at the link you shared and I think I've added it to our eslint setup here: 426c45c

Seems to be working for me locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this!

Locally on your branch this isn't quite working for me (it's maybe a me issue!).

If I drop the final "thanks" case from this switch locally I can run pnpm check and it picks up an issue with this file -

➜  editor.planx.uk git:(mh/setup-feedback-form-conditional-rendering) pnpm check

> editor.planx.uk@ check /Users/dafyddllyr/Code/planx-new/editor.planx.uk
> tsc --noEmit && pnpm lint

src/components/Feedback.tsx:363:24 - error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

363   function Feedback(): FCReturn {
                           ~~~~~~~~

Found 1 error in src/components/Feedback.tsx:363

However my IDE doesn't pick up the affected line, it just gives an issue right at the top of the affected file -
image

(The location of the .tsconfig.json should be /Users/dafyddllyr/Code/planx-new/editor.planx.uk/tsconfig.json)

Are you hitting these issues?

Copy link
Contributor Author

@Mike-Heneghan Mike-Heneghan Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a weird one 🤔

Normally I use npx lint-staged before I make a commit and when I remove the thanks case I see:

❯ npx lint-staged
✔ Preparing lint-staged...
❯ Running tasks for staged files...
  ❯ package.json — 1 file
    ❯ src/**/*.{js,jsx,ts,tsx} — 1 file
      ✖ eslint --fix [FAILED]
    ✔ src/**/*.{js,jsx,ts,tsx,json,css,scss,md,html} — 1 file
    ❯ src/**/*.{ts,tsx} — 1 file
      ✖ scripts/tsc-lint.sh [KILLED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ eslint --fix:

/Users/mike/planx-new/editor.planx.uk/src/components/Feedback.tsx
   95:40  warning  Unexpected any. Specify a different type                                             @typescript-eslint/no-explicit-any
   98:28  warning  Unexpected any. Specify a different type                                             @typescript-eslint/no-explicit-any
  345:12  warning  'ThanksForFeedback' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars
  364:13  error    Switch is not exhaustive. Cases not matched: "thanks"                                @typescript-eslint/switch-exhaustiveness-check

✖ 4 problems (1 error, 3 warnings)


✖ scripts/tsc-lint.sh failed without output (KILLED).

When I try pnpm check I see:

Checking formatting...
All matched files use Prettier code style!
❯ pnpm check

> editor.planx.uk@ check /Users/mike/planx-new/editor.planx.uk
> tsc --noEmit && pnpm lint

src/components/Feedback.tsx:363:24 - error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

363   function Feedback(): FCReturn {
                           ~~~~~~~~


Found 1 error in src/components/Feedback.tsx:363

In both cases I don't see any warning in my editor 🤔

Copy link
Contributor Author

@Mike-Heneghan Mike-Heneghan Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have time maybe we could jump on a huddle at @DafyddLlyr as I'm slightly perplexed by this one. I think my setup/workflow hasn't been quite right.

On main I don't see the FCReturn comment so I've definitely introduced a bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lets do that 👍

Could you please drop these changes from the PR so that we can look at it in isolation, and don't hold up this PR unnecessarily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also thinking FCReturn might actually be correct as if a case is missing i.e. the currentFeedbackView is "thanks" then the component does indeed lack a return statement and isn't guaranteed to return a react component?

);
const previousFeedbackView = usePrevious(currentFeedbackView);

function handleFeedbackViewClick(event: FeedbackViewClickEvents) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - nice and need and maintainable! Take a look at my comment below on how we could make this a little safer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a nice to have in future I think - for now it feels ok to group them? We can always come back and split up (and maybe write some Storybook stories) and tests sometime soon?

<>
type View = "yes/no" | "input" | "thanks";

type Sentiment = "helpful" | "unhelpful";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also tried to reflect the language of the feedback_type_enum here so that it hopefully makes things easier when the forms are wired up.

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small question - might be an issue with my local setup but just wanted to cross-check.

);
}

function Feedback(): FCReturn {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this!

Locally on your branch this isn't quite working for me (it's maybe a me issue!).

If I drop the final "thanks" case from this switch locally I can run pnpm check and it picks up an issue with this file -

➜  editor.planx.uk git:(mh/setup-feedback-form-conditional-rendering) pnpm check

> editor.planx.uk@ check /Users/dafyddllyr/Code/planx-new/editor.planx.uk
> tsc --noEmit && pnpm lint

src/components/Feedback.tsx:363:24 - error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

363   function Feedback(): FCReturn {
                           ~~~~~~~~

Found 1 error in src/components/Feedback.tsx:363

However my IDE doesn't pick up the affected line, it just gives an issue right at the top of the affected file -
image

(The location of the .tsconfig.json should be /Users/dafyddllyr/Code/planx-new/editor.planx.uk/tsconfig.json)

Are you hitting these issues?

@Mike-Heneghan Mike-Heneghan force-pushed the mh/setup-feedback-form-conditional-rendering branch from 7d9f353 to cef5a41 Compare January 24, 2024 13:38
@Mike-Heneghan
Copy link
Contributor Author

Super clean and nice code - a pleasure to review!

A few minor comments and suggestions, nothing blocking.

Some small UI / design thoughts (these are for @ianjon3s to think about also...!) -

image

  • The white on grey here feels quite hard to look at - is there an alternative or is this ok?
  • Should we use the ErrorWrapper component over native browser validation (e.g. for required fields)? The benefits would be a more consistent UI and we also now capture analytics via the ErrorWrapper which could be useful to track.

There are great spots @DafyddLlyr!

I'll defer to your judgement/update for the "Report an Issue" button @ianjon3s but we can update this in a later PR.

For the ErrorWrapper I think I'll add this when I wire up the forms following the pattern in your work with the design settiings @DafyddLlyr 👍

@Mike-Heneghan Mike-Heneghan merged commit 185e2a0 into main Jan 24, 2024
12 checks passed
@Mike-Heneghan Mike-Heneghan deleted the mh/setup-feedback-form-conditional-rendering branch January 24, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants