Skip to content

Commit

Permalink
fix(RHINENG-3105): loading rows not showing on activity delete
Browse files Browse the repository at this point in the history
Description of Problem
There's a small bug in Tasks on the Activity table. When you're on any page other than 1 and you delete an activity, the table shows a No results empty state instead of loading rows.

How reproducible
Always

Steps to Reproduce
Go to Tasks
Click Activity Tab
Go to page 2+
Delete an activity via the kebab
Actual Behavior
Table shows a "No results" empty state.

Expected Behavior
Should show loading rows

Additional info
This happens because the table component receives an array of 5 loading row components. Then it tries to paginate that data, and the `page` is currently set to a page over page 1, so if you're looking at 10 per page and you're on page 2, the 5 items sent in get paginated out.

This fix will skip pagination if the table is in a loading state.
  • Loading branch information
Michael Johnson authored and johnsonm325 committed Nov 22, 2023
1 parent 29c599b commit 42dfa1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ import useRowsBuilder from '../useRowsBuilder';

describe('useRowsBuilder', () => {
it('returns a rows configuration', () => {
const paginator = jest.fn((items) => items);

const { result } = renderHook(() =>
useRowsBuilder(items, columns, {
rowTransformer: [undefined],
isTableLoading: false,
paginator: paginator,
})
);
expect(paginator).toHaveBeenCalled();
expect(result).toMatchSnapshot();
});

it('doesnt paginate when the table is loading', () => {
const paginator = jest.fn();
renderHook(() =>
useRowsBuilder(items, columns, {
rowTransformer: [undefined],
isTableLoading: true,
paginator: paginator,
})
);
expect(paginator).not.toHaveBeenCalled();
});
});
7 changes: 4 additions & 3 deletions src/Utilities/hooks/useTableTools/useRowsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const useRowsBuilder = (items, columns, options = {}) => {
? options.sorter(filteredItems)
: filteredItems;

const paginatedItems = options?.paginator
? options?.paginator(filteredItems)
: sortedItems;
const paginatedItems =
options?.paginator && !options?.isTableLoading
? options?.paginator(filteredItems)
: sortedItems;

let parentIndex = -1;
let row;
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/hooks/useTableTools/useTableTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const useTableTools = (
paginator,
filter,
sorter,
isTableLoading,
});

const toolbarProps = {
Expand Down

0 comments on commit 42dfa1a

Please sign in to comment.