-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make learning path items drag resortable #3948
Conversation
@@ -131,84 +139,50 @@ test("useDeleteUserList invalidates all resource queries", async () => { | |||
}) | |||
|
|||
test("useAddToUserListItems invalidates userlist details and listing", async () => { |
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.
Several tests in this file broke when I changed useUserListItems
to an infinite paginated query.
I decided the way I was testing "correct stuff gets invalidated by mutation" was too fragile and re-wrote several of those tests:
- before: I was calling several of the data-fetching hooks, and checking that when
useAddToUserListItems
(or whatever mutation was under test) was causing some of those hooks to re-fetch. - now: I'm just checking that
invalidateQueries
is called with the correct keys.
It's a little less realistic, but should be much less fragile... don't mock / simulate as much data.
return useQuery<PaginatedUserListItems>(key, () => | ||
axios.get(url).then(res => res.data) | ||
) | ||
const useUserListItems = ( |
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 decided to change useUserListItems
to an infinite query (designed for infinite scrolling) because the old learn site uses an <InfiniteScroll />
UI for sorting list items.
I did not implement the InfiniteScroll UI, just set up the API hook to make it easy if we do. The old /learn
site uses InfiniteScroll for sorting items on the UserListDetailsPage
, but does not paginate the items in read-only mode on that page.
count: number, | ||
{ count, pageSize }: { count: number; pageSize?: number }, |
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.
makePaginatedFactory
takes a factory function and returns a factory that creates paginated results, { count, previous, next, results }
.
Previously count
and results.length
were always the same, which isn't flexible enough.
@@ -76,6 +76,7 @@ | |||
"stylelint": "^15.2.0", | |||
"stylelint-config-standard-scss": "^7.0.1", | |||
"swc-loader": "^0.2.3", | |||
"tiny-invariant": "^1.3.1", |
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 a very small package that is pretty widely used
- make assertions concisely
- typescript narrowing
It is similar to assertNotNil
and assertInstanceOf
, though I probably would not have written those functions if I was familiar with tiny-invariant
at the time.
assertNotNil(x) <---> invariant(x)
assertInstanceOf(x, SomeClass) <---> invariant(x instanceof SomeClass)
* We use the indices to update the UI immediately, and the positions to make | ||
* the API call. |
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.
In contrast, the old /learn
site uses indices to make API calls.
-
because our list item
position
field is not updated when list items are deleted, the positions can have gaps, which leads to bug like (open/learn) Re-ordering learning paths does not always work #3944 when re-ordering based on index. -
Even if we changed the API so that
position
field does not have gaps... it seems safer to useposition
field rather than indices to make the API call.On the other hand, that means that after making an API call to move an item, we need to either (A) optimistically update the list indices AND the position fields, or (B) make a second API call to re-fetch the list items. I opted for (B).
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
502b5e8
to
2353423
Compare
Pre-Flight checklist
What are the relevant tickets?
#3912
What's this PR do?
This PR makes learning paths drag re-sortable at
infinite/lists/<learning path id>
.How should this be manually tested?
/learn
but not on/infinite
.Screenshots (if appropriate)
Desktop:
sorting_userlists.mov
Mobile:
