-
Notifications
You must be signed in to change notification settings - Fork 63
Move useLoadMore functionality in the Load More component #1238
Conversation
3d37398
to
77df68b
Compare
For me when I go to |
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.
Also noticed that if you enable a file extension filter that results in 0 results (like mp3 for galah audio search) and then toggle it back off, it still shows no results.
The reason for failures described here is the fact that instead of using the store state from the server, we are re-initializing it on the client, for all the Pinia stores. |
88820ea
to
446a130
Compare
446a130
to
86f01f7
Compare
# Conflicts: # src/composables/use-fetch-state.ts # src/locales/po-files/openverse.pot # test/unit/specs/components/related-images.spec.js
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 already an improvement as the page doesn't crash, at least, but there is still something wrong with the load more logic.
When I visit http://localhost:8443/search/audio?q=galah
on this branch the page doesn't crash and remains interactive. However there is a load more button (even though there's only a single result). If I click it, then a "no results" page will show.
} | ||
const isFetching = computed(() => mediaStore.fetchState.isFetching) | ||
|
||
const buttonLabel = computed(() => i18n.t('browse-page.load')) |
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 see that it was already this way, but why does this need to be a computed
? 🤔
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.
No it doesn't 😆 I think I wrote it that way when I was only starting to learn the way Composition API worked.
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.
+1 to putting this directly on the template 🙂
it('renders images without load more button', () => { | ||
render(VImageGrid, options) | ||
expect(screen.queryAllByRole('img').length).toEqual(propsData.images.length) | ||
expect(screen.queryAllByRole('figure').length).toEqual( | ||
propsData.images.length | ||
) | ||
const loadMoreButton = screen.queryByTestId('load-more') | ||
expect(loadMoreButton).toBeVisible() | ||
expect(loadMoreButton).toHaveTextContent(messages['browse-page'].load) | ||
expect(screen.queryByTestId('load-more')).not.toBeVisible() |
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 test file now misses the other side of it, when the load more button does show.
Also I think there are three branches to test for when load more shows or not, ideally we'd test those in a VLoadMore specific test file:
searchStore.searchTerm !== '' &&
mediaStore.fetchState.canFetch &&
mediaStore.resultCount > 0
Each of those is a distinct branch we'd want to test 😕
Then the image-grid
and audio-grid
tests can just confirm that the load more component is actually rendered (whether the button displays or not is now irrelevant to the grid as it's handled by the button itself, thank goodness!)
:disabled="isFetching" | ||
data-testid="load-more" |
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.
Is this necessary or could we test just using the label? Generally it's preferable to avoid introducing test id's if possible, in this case a getByText
should be okay, I think.
Sorry for not stating it clearly, but this PR should only work after the media PR is merged. |
# Conflicts: # src/locales/po-files/openverse.pot
# Conflicts: # src/locales/po-files/openverse.pot
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.
LGTM! Massive improvement 🎉
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.
LGTM! It would just be nice to cover more cases in the tests in the future as @sarayourfriend mentioned, but it's nice to fix this obvious bug!
Fixes
Fixes #1235 by @obulat
Fixes #1301 by @sarayourfriend
Replacement of #1236
Description
This PR moves all the logic for
VLoadMore
button to theVLoadMore
component, and heavily uses the data available in the media store.This solves the problem where because of an error in
VLoadMore
, there was a server-client mismatch, and the whole app was re-rendering, and was not interactive on SSR-ed search results.This branch is based on
type_base_components
because it uses TS andVButton
. It is, therefore, blocked by #1233.Testing Instructions
Go to localhost:8443/search/audio/?q=galah
You should see a single result, but other than that, the page should be interactive (search type button in the header should work), and the waveform should be displayed.
Compare it with the behavior on main by going to https://search-staging/search/audio/?q=galah
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin