feat: drag to reorder help center articles across pages (#14910)
This commit is contained in:
@@ -157,11 +157,13 @@ export const actions = {
|
||||
// Update positions in the store immediately so subsequent mutations preserve correct positions
|
||||
commit(types.SET_ARTICLE_POSITIONS, reorderedGroup);
|
||||
try {
|
||||
await articlesAPI.reorderArticles({
|
||||
const { data } = await articlesAPI.reorderArticles({
|
||||
portalSlug,
|
||||
reorderedGroup,
|
||||
categorySlug,
|
||||
});
|
||||
// Adopt the backend's re-spaced positions so the next reorder isn't computed from stale local values.
|
||||
if (data?.positions) commit(types.SET_ARTICLE_POSITIONS, data.positions);
|
||||
} catch (error) {
|
||||
commit(types.SET_ARTICLE_POSITIONS, oldPositions);
|
||||
throw error;
|
||||
|
||||
@@ -314,6 +314,25 @@ describe('#actions', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('adopts the backend re-spaced positions when the response returns them', async () => {
|
||||
const serverPositions = { 1: 10, 2: 30, 3: 20 };
|
||||
axios.post.mockResolvedValue({ data: { positions: serverPositions } });
|
||||
|
||||
await actions.reorder(
|
||||
{ commit, state },
|
||||
{
|
||||
portalSlug: 'test-portal',
|
||||
categorySlug: 'test-category',
|
||||
reorderedGroup: { 3: 25 },
|
||||
}
|
||||
);
|
||||
|
||||
expect(commit).toHaveBeenCalledWith(
|
||||
types.default.SET_ARTICLE_POSITIONS,
|
||||
serverPositions
|
||||
);
|
||||
});
|
||||
|
||||
it('rolls back positions and throws when API call fails', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Network error' });
|
||||
const reorderedGroup = { 1: 1, 2: 2 };
|
||||
|
||||
Reference in New Issue
Block a user