-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: logic for conditionally rendering feedback UI #2678
Conversation
Removed vultr server and associated DNS entries |
); | ||
const previousFeedbackView = usePrevious(currentFeedbackView); | ||
|
||
function handleFeedbackViewClick(event: FeedbackViewClickEvents) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
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 🙌 |
There was a problem hiding this 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...!) -
-
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 theErrorWrapper
which could be useful to track.
} | ||
} | ||
|
||
const handleFeedbackFormSubmit = (e: any) => { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 -
(The location of the .tsconfig.json
should be /Users/dafyddllyr/Code/planx-new/editor.planx.uk/tsconfig.json
)
Are you hitting these issues?
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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 -
(The location of the .tsconfig.json
should be /Users/dafyddllyr/Code/planx-new/editor.planx.uk/tsconfig.json
)
Are you hitting these issues?
- Based on Figma prototype conditionally render the new UI components - Add dummy form submission methods
- Move from using enums to type with string unions - Remove overuse of 'feedback' from naming
- Move to using onClick so it's implicit rather than needing to be redefined
7d9f353
to
cef5a41
Compare
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 |
What
Why
Testing
window.featureFlags.toggle("SHOW_INTERNAL_FEEDBACK")
Screen recording
Screen.Recording.2024-01-18.at.15.14.59.mov