docbrown/app/javascript
Daniel Uber 68867e7c68
Ensure we have current user information before deciding how to handle the "flag user" button (#13279)
* Make test fail again

Minimal reproduction via `rspec
spec/system/user/trusted_user_flags_user_spec.rb --order=random
--seed=9374` which runs in this order:

- when signed in as a trusted user
- when not logged in
- when signed in as the non-trusted user
- when signed in as the user

Because "not logged in" immediately precedes "non-trusted user" in this
order, the browser store cache is cleared and there is no user. Since
there's no user, the flag is not removed.

* Wait for current user promise before processing current user

* Extract button callback registration to function

This addresses a code climate concern (function exceeded 50 lines) by
extracting the button behavior to a function of (button, id, name),
and calls that within the exported initFlag function.

* Prefer request to fetch

Addresses feedback to use @utilities/http's request method in  place
of fetch (which automatically adds the needed csrf headers)

* Reorder imports

Satisfies code climate report that imports are out of order

* Add honeybadger notify to error handling

Do more than just notify that something went wrong. Notify honeybadger
on failure to flag/unflag a user.

* Remove temp variable

This makes the notify code look more like the suggestion

* Reduce function arglist

Since the user id and name are properties of the flagButton's dataset,
we can efficiently extract them from the flagButton.

Only pull user id from dataset to check if current user = profile
user, and extract id and name from dataset after passing the
flagButton.

* reorder imports

Not sure how I managed to reverse this in 18aeb675b but here we go again

* Test button behavior

The original tests only asserted that the link to reactions was
present and labeled correctly. Add additional check that we can use
the button and that the label toggling occurs (this adds a request to
the test case, but adds a test for user facing behavior).

* Tame eslint check

I was getting conflicting feedback on import ordering from code
climate and eslint. Since telling eslint to ignore its rules was
immediately clear to me (there's an example on the line before this)
that's the direction I headed, but I can revisit if it matters

https://github.com/forem/forem/pull/13279#issuecomment-814411401
captures the conflict (code climate wants @utilities/http first,
eslint wants ../chat/util first, one or the other fails regardless of
the ordering.

* Use multiple rules in one ignore comment

https://eslint.org/docs/user-guide/configuring/rules#disabling-rules
supports multiple warnings separated by commas

* Remove stray comment

* Move documentation comment to the code it describes

* Replace invalid name

I had copied from the suggested code snippet the
userData.profileUserID name, but userData in this context is a global
function, and `profileUserId` (capitalization) is the bound variable
in this context.

Fix it before we throw an error trying to report an error (ironically,
before the window alert telling the user an error occurred, I think
this would have been visible only in console).

* Actually call the remove button function
2021-04-07 16:28:21 -05:00
..
.storybook Added react aliases in Storybook webpack configuration. (#12825) 2021-02-26 09:25:38 +00:00
actionsPanel CSS size reduce + cleanups. (#12625) 2021-02-16 13:44:26 +01:00
admin Remove buffer gem and related code: step 1 (#12993) 2021-03-24 09:58:38 +07:00
analytics Use 2-digit month and day for JS Date class (#13257) 2021-04-07 14:25:39 -04:00
article-form [15 min fix] Allow resize hook to contrain max-height as well as min (#13269) 2021-04-06 12:11:03 +01:00
articles improve keyboard accessibility of modals 12427 10610 (#12511) 2021-02-24 16:01:10 +00:00
chat ✂️ Remove search from Connect (#13235) 2021-04-06 13:03:31 -04:00
CommentSubscription Fix subscribe to discussion button when user is not logged in (#12837) 2021-03-03 18:50:29 -06:00
common-prop-types Updates ESLint rules to error on default imports (#12512) 2021-02-02 10:24:03 -05:00
contentDisplayPolicy Updates ESLint rules to error on default imports (#12512) 2021-02-02 10:24:03 -05:00
crayons Fixed bug with iOS devices that crashed the post editor (#13281) 2021-04-07 05:52:17 -04:00
githubRepos Deprecate old button stylings with Crayons buttons (#10694) [deploy] 2020-10-14 07:28:41 -07:00
icons Storybook: Add DocsPage and test out static content (#11397) 2020-12-02 09:56:38 -08:00
leftSidebar Replace redundant div with Fragment (#12613) 2021-02-09 11:41:46 -06:00
listings improve keyboard accessibility of modals 12427 10610 (#12511) 2021-02-24 16:01:10 +00:00
modCenter Updates ESLint rules to error on default imports (#12512) 2021-02-02 10:24:03 -05:00
onboarding Adding aria labels in Suggested people to follow screen during onboarding (#12384) 2021-03-17 11:59:50 -04:00
organization Fixed Error: Not implemented: window.computedStyle(elt, pseudoElt) console error in frontend tests. (#11633) 2020-11-26 16:55:33 -05:00
packs Add flag link to profile dropdown view (#12862) 2021-04-01 09:26:43 +00:00
podcasts Remove non application files from frontend code coverage (#11752) 2020-12-04 20:00:20 -05:00
profileDropdown Ensure we have current user information before deciding how to handle the "flag user" button (#13279) 2021-04-07 16:28:21 -05:00
readingList Remove pro role + expose analytics to all users via dashboard (#13156) 2021-03-30 15:02:18 -07:00
responseTemplates [15 minute fix] Fixed bug with templates not being inserted for comments. (#13149) 2021-03-30 13:02:54 +02:00
Search Fix search confusion (#13130) 2021-03-26 11:08:56 +01:00
searchableItemList [Search 2.0] Reading list (#13052) 2021-03-24 15:40:00 +01:00
shared/components Update shortcut code with best practices (#13026) 2021-03-24 14:03:45 +00:00
sidebar-widget Refactoring SidebarWidget and sidebarUser (#10887) 2021-02-03 17:47:54 +00:00
Snackbar Storybook: Add DocsPage and test out static content (#11397) 2020-12-02 09:56:38 -08:00
topNavigation Fix more button not working after navigating back to the home page (#12612) 2021-03-25 12:48:41 -04:00
utilities [15 min fix] Allow resize hook to contrain max-height as well as min (#13269) 2021-04-06 12:11:03 +01:00
.eslintrc.js [15 Minute Fix] Added the prefer-const eslint rule (#13098) 2021-03-23 16:29:56 -04:00
netlify.toml Try yarn instead over npm for storybook deploys (#12376) 2021-02-26 10:30:56 -05:00