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

QuickTalk: Refactor to functional component #3213

Merged
merged 5 commits into from
May 27, 2022

Conversation

shaunanoordin
Copy link
Member

PR Overview

Package: lib-classifier
Affects: experimental QuickTalk feature (only affects projects with experimental tool enabled)

This PR refactors the QuickTalkContainer into a functional component.

  • No actual functions or features have been changed (EDIT: except for the two minor changes below). Users should see no difference in the feature.
  • Minor: error messages now use translated text.
  • Minor: when QuickTalk panel opens, close button now automatically gets focus. (I thought I added this in 3048, but I must have dropped it, d'oh!)

Testing

  • Test on lib-classifier (not app-project) with a project with QuickTalk enabled, e.g. https://local.zooniverse.org:8080/?env=staging&project=darkeshard%2Ftest-project-2022&workflow=3581
  • You should be able to see the QuickTalk button on the lower-right of the screen, with a number if any comments already exist.
  • If you click on the button, the QuickTalk panel should expand, and you should see any comments already made.
  • If you're logged in, you should be able to post comments on the expanded panel.

Known UI issues: (collapsed) QuickTalk button should have a background so it doesn't blend into the page (z-index madness) ; a message saying "you should be logged in if you want to post a message" should appear on the expanded panel.

Status

Ready for review! 👍

@coveralls
Copy link

coveralls commented May 26, 2022

Coverage Status

Coverage increased (+0.02%) to 83.283% when pulling c7dec75 on fix-quicktalk-auth-mk2 into ad72d01 on master.

@eatyourgreens eatyourgreens self-assigned this May 26, 2022
@@ -174,21 +148,21 @@ class QuickTalkContainer extends React.Component {

const authorization = await getBearerToken(authClient) // Check bearer token to ensure session hasn't timed out
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I’ve pointed this bug out before but this will return an empty string if you call it before you call checkCurrent. See #2986.

@@ -198,11 +172,10 @@ class QuickTalkContainer extends React.Component {
}

await talkClient.type('comments').create(comment).save()
Copy link
Contributor

Choose a reason for hiding this comment

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

This could use panoptes.post to post comments with the new API client.

author_ids = author_ids.filter((id, i) => author_ids.indexOf(id) === i)

apiClient.type('users').get({ id: author_ids })
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use panoptes.get in the new API client.

})

talkClient.type('roles')
Copy link
Contributor

Choose a reason for hiding this comment

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

Are Talk roles different from Panoptes roles? You can use the new client to get roles. The useProjectRoles hook has an example.

@@ -101,24 +86,24 @@ class QuickTalkContainer extends React.Component {
page: 1,
sort: 'created_at', // PFE used '-created_at' to sort in reverse order, and I have no idea why.
}


talkClient.type('comments').get(query)
Copy link
Contributor

Choose a reason for hiding this comment

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

The new API client could be used here too.

@eatyourgreens eatyourgreens force-pushed the fix-quicktalk-auth-mk2 branch from de64631 to 41649bf Compare May 26, 2022 02:32
@eatyourgreens
Copy link
Contributor

There’s an auth bug in the existing code, which can be fixed here.

All the API calls should use the new panoptes client but maybe do that in a separate PR? You shouldn’t need to import any code from the old panoptes-client and you aren’t doing anything here that isn’t being done with the new client elsewhere in the classifier.

Copy link
Contributor

@eatyourgreens eatyourgreens left a comment

Choose a reason for hiding this comment

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

Looks good but:

  • there's an auth bug which blocks the first posted comment from being posted.
  • all API requests should really be handled with panoptes-js not the old client.
  • after I post a comment, keyboard focus goes back to the window, or parent document. I'm not sure. Either way, posting a comment from the keyboard works until after the comment is posted, at which point the Quick Talk panel loses keyboard focus.

@github-actions github-actions bot added the approved This PR is approved for merging label May 26, 2022
@eatyourgreens
Copy link
Contributor

This might be useful for managing keyboard focus.

@@ -174,21 +148,21 @@ class QuickTalkContainer extends React.Component {

const authorization = await getBearerToken(authClient) // Check bearer token to ensure session hasn't timed out
const user = await authClient.checkCurrent()
Copy link
Contributor

Choose a reason for hiding this comment

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

Another thought about auth: Panoptes user sessions are quite long-lived, so call this once, when the component mounts, in order to establish a session (if one exists.)

Then get a bearer token as and when you need access to perform a restricted action, like posting a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use the usePanoptesUser and usePanoptesAuth hooks, although that would then limit you to following the Rules of Hooks eg. no conditional execution.
https://github.com/zooniverse/front-end-monorepo/tree/master/packages/lib-classifier/src/hooks#usepanoptesauth

@shaunanoordin shaunanoordin force-pushed the fix-quicktalk-auth-mk2 branch from 41649bf to c7dec75 Compare May 27, 2022 13:27
@shaunanoordin
Copy link
Member Author

Thanks Jim! 👍 I'm merging this PR, with the following goals for the follow up PR:

  • "First comment not posting" auth bug to be investigated
  • apiClient and talkClient to be changed to use new panoptes-js client.
  • (Address UI visual + accessibility improvements? Might put that in a third PR)

@shaunanoordin shaunanoordin merged commit 31c4cf9 into master May 27, 2022
@shaunanoordin shaunanoordin deleted the fix-quicktalk-auth-mk2 branch May 27, 2022 14:40
@eatyourgreens
Copy link
Contributor

This is the auth bug.
#3213 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This PR is approved for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants