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

Homepage: Create RecentProjects component, refactor data fetching in RecentSubjects #6125

Merged
merged 14 commits into from
Jun 14, 2024

Conversation

goplayoutside3
Copy link
Contributor

@goplayoutside3 goplayoutside3 commented Jun 9, 2024

Package

lib-user
lib-react-components

Linked Issue and/or Talk Post

Follows #6117
The rest of the Dashboard on the signed-in homepage is in #6121

Figma Design

Describe your changes

  • Build a RecentProjects component based on the signed-in user's project_contributions. See more comments about it below.
  • Add a badge option to ProjectCard so a user's classification count can be displayed per card on the homepage.
  • Refactor RecentSubject's UI component to use shared ContentBox, and its data fetching now uses the shared usePanoptesProjects hook.
  • Add basic grid layout to UserHome (user's groups component will go in the empty space).

How to Review

Checklist

PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.

General

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

@goplayoutside3 goplayoutside3 added the enhancement New feature or request label Jun 9, 2024
@coveralls
Copy link

Coverage Status

coverage: 79.287% (-0.04%) from 79.323%
when pulling 8370182 on lib-user-recent-projects
into 9a7a630 on master.

Comment on lines 7 to 11
// Returns all projects a user has classified in descending order (most classifications first)
const { data: statsData } = useStats({
sourceId: authUser.id,
query: { project_contributions: true }
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mcbouslog @seanmiller26 as mentioned in the Slack thread, the response from this is a list of projects in descending order from greatest number of classifications to least number of classifications by the user.

Is this "Continue Classifying" section intended to be "projects you've most recently classified"? If so, I'll need to change this fetch to a user's project preferences like PFE's homepage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is a recently classified section, so we can match PFE here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good - I refactored to display projects a user has most recently classified on. The catch with relying on project_preferences is that project_preferences.updated_at is changed when a user interacts with a project beyond just classifying. For instance, closing a tutorial.

In this PR, I only fetched 1 page of project_preferences (20 items) and filtered for those where activity_count > 0 (which means a user has actually classified on a project). This means if I recently interacted with 20 projects, but only classified on 3, then only 3 projects will show in this "Continue Classifying" UI section.

It would be much smoother if the eras request for project_contributions included a sort by most recently classified, but I'll have to follow-up with Michelle after internal team testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A clarification - PFE's homepage recursively gets ALL pages of a user's project preferences rather than just 1 page. This is why it takes a long time for all of your ribbon classifications to load. I'd prefer not to use recursion on the new homepage because it's so data intensive - hence the note about follow-up with Michelle and eras.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not know the specifics here re project_preferences.updated_at Great decisions!

Comment on lines 62 to 53
? recents.slice(0, 10).map(classification => {
const subjectMedia = classification.locations.map(
? recents.map(recent => {
const subjectMedia = recent?.locations?.map(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing this variable name to recent instead of classification was suggested here, because the object is a Recent resource from panoptes, not a Classification resource typically sent from lib-classifier to panoptes.

@coveralls
Copy link

Coverage Status

coverage: 79.324% (+0.001%) from 79.323%
when pulling 3bf726f on lib-user-recent-projects
into 9a7a630 on master.

@coveralls
Copy link

Coverage Status

coverage: 79.14% (-0.2%) from 79.323%
when pulling 1fca965 on lib-user-recent-projects
into 9a7a630 on master.

@coveralls
Copy link

Coverage Status

coverage: 79.131% (-0.2%) from 79.323%
when pulling b5a5ba4 on lib-user-recent-projects
into 9a7a630 on master.

@coveralls
Copy link

Coverage Status

coverage: 79.222% (-0.1%) from 79.323%
when pulling 684a196 on lib-user-recent-projects
into 9a7a630 on master.

Copy link
Contributor

@mcbouslog mcbouslog left a comment

Choose a reason for hiding this comment

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

Looking good!

I made a few changes, see in-line comments. Might be helpful to review last few commits and make sure changes are ok, I might be missing some context.

@@ -30,7 +30,7 @@ function CardsRow({ children }) {
as='ul'
direction='row'
gap='small'
pad={{ horizontal: 'xxsmall', bottom: 'xsmall' }}
pad={{ horizontal: 'xxsmall', bottom: 'xsmall', top: 'xxsmall' }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Added padding top: 'xxsmall' to uls that list cards (project, subject) to leave a little room for the focus styling.

</StyledBox>
</StyledAnchor>
<StyledBox
forwardedAs='a'
Copy link
Contributor

Choose a reason for hiding this comment

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

This refactor gives the SubjectCard focus styling.

{!isLoading && error && (
<Box fill justify='center' align='center' pad='medium'>
<SpacedText>
There was an error fetching your recent projects
Copy link
Contributor

Choose a reason for hiding this comment

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

For consideration, show error.message here

margin='0'
>
{projectPreferences.map(preference => (
<li key={preference?.project?.id}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Added <li>

{!isLoading &&
projectPreferences?.length ? (
<Box
as='ul'
Copy link
Contributor

Choose a reason for hiding this comment

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

Moved ul after loading/error/empty states content

{!isLoading && recents?.length
? (
<Box
as='ul'
Copy link
Contributor

Choose a reason for hiding this comment

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

Moved ul after loading/error/empty states content

mediaSrc={subjectMedia[0]}
projectSlug={classification.slug}
/>
<li key={recent?.id}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Added <li>

return []
} catch (error) {
console.error(error)
throw error
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the related components handle error states I think this fetch should throw an error if it has one so that error can be included in the error returned from useSWR on line 51?

async function fetchUserRecents({ userId }) {
try {
const query = {
page_size: 10,
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactored to page_size: 10 as I think we only need 10

return response.body?.recents
} catch (error) {
console.error(error)
throw error
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to RecentProjectsContainer, since the related components handle error states I think this fetch should throw an error if it has one so that error can be included in the error returned from useSWR on line 35?

@coveralls
Copy link

Coverage Status

coverage: 79.18% (-0.1%) from 79.323%
when pulling b8ad896 on lib-user-recent-projects
into 9a7a630 on master.

@github-actions github-actions bot added the approved This PR is approved for merging label Jun 14, 2024
@mcbouslog mcbouslog enabled auto-merge (squash) June 14, 2024 21:44
@coveralls
Copy link

Coverage Status

coverage: 79.197% (-0.1%) from 79.323%
when pulling 8c7247a on lib-user-recent-projects
into 9a7a630 on master.

@mcbouslog mcbouslog merged commit 37bef25 into master Jun 14, 2024
8 checks passed
@mcbouslog mcbouslog deleted the lib-user-recent-projects branch June 14, 2024 21:58
@coveralls
Copy link

Coverage Status

coverage: 79.189% (-0.01%) from 79.201%
when pulling 4035c12 on lib-user-recent-projects
into 1a9e6c2 on master.

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 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants