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

chore: Refactor publisher listing app #4859

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

steverydz
Copy link
Contributor

@steverydz steverydz commented Sep 25, 2024

Done

Currently the listing view uses data directly from the template. This will be problematic when moving to the publisher app as it would require the data for every view to be embedded into one template. This PR refactors the app so that the data comes from an API endpoint, /api/:snap_name/listing in this case.

This application is split into sections, one for each section of the listing page, e.g Listing details, Contact information and Additional information. Each one of these components contains sub-components that are only relevant to that component.

The data for the GET request has been formatted so it works out of the box with the form which uses React Hook Form. For the POST request, the store API requires the data in a specific format, for example all of the images (icon, banner, and screenshots) need to be present in an array, even if only one of them has changed. Therefore there are some utilities to identify changed fields and format the data so it can be saved.

React Query is used to manage the data requests. Each method has been separated into a hook to make reuse easier. The ListingForm component is a child component of the main App component, with the data passed to that component once it is available, in order to avoid the state where no data is available.

Once the form has saved successfully it makes a new GET request to get the latest data and then calls the reset method from React Hook Form with the new default values so the form is then in a reset state with the latest data.

The application makes use of shared components for the PageHeader and SaveAndPreview. These are used by the rest of the publisher app and it will make it easier to integrate the listing page into the publisher app once this PR is merged.

How to QA

Testing

  • This PR has tests
  • No testing required (explain why):

@webteam-app
Copy link

@steverydz steverydz force-pushed the refactor-listing-page-data-fetching branch from e8b453b to 78e4d2a Compare September 25, 2024 13:47
@steverydz steverydz force-pushed the refactor-listing-page-data-fetching branch 18 times, most recently from 1d6f97c to 4fa04a9 Compare October 1, 2024 10:29
@steverydz steverydz force-pushed the refactor-listing-page-data-fetching branch 2 times, most recently from a76dba9 to f63be2f Compare October 1, 2024 13:33
@steverydz steverydz force-pushed the refactor-listing-page-data-fetching branch from f63be2f to 3c18464 Compare October 1, 2024 13:39
@steverydz steverydz marked this pull request as ready for review October 2, 2024 08:16
Copy link
Contributor

@chillkang chillkang left a comment

Choose a reason for hiding this comment

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

I love that there is no more Function type :) It would be great if you could add more details about the PR like how you organized and grouped files?

Copy link
Contributor

@chillkang chillkang left a comment

Choose a reason for hiding this comment

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

LGTM👍

Copy link
Contributor

@ilayda-cp ilayda-cp left a comment

Choose a reason for hiding this comment

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

Great refactor! LGTM 🚀

@steverydz steverydz merged commit 898fa57 into main Oct 2, 2024
10 of 11 checks passed
@steverydz steverydz deleted the refactor-listing-page-data-fetching branch October 2, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants