Skip to content

Commit

Permalink
Fix page index reset on refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Feb 13, 2025
1 parent a15943a commit 626f337
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/apps/dashboard/routes/devices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const getUserCell = (users: UsersRecords) => function UserCell({ renderedCellVal

export const Component = () => {
const { api } = useApi();
const { data: devices, isLoading: isDevicesLoading } = useDevices({});
const { data, isLoading: isDevicesLoading, isRefetching } = useDevices({});
const devices = useMemo(() => (
data?.Items || []
), [ data ]);
const { usersById: users, names: userNames, isLoading: isUsersLoading } = useUsersDetails();

const [ isDeleteConfirmOpen, setIsDeleteConfirmOpen ] = useState(false);
Expand Down Expand Up @@ -78,9 +81,9 @@ export const Component = () => {
}, []);

const onConfirmDeleteAll = useCallback(() => {
if (devices?.Items) {
if (devices) {
Promise
.all(devices.Items.map(item => {
.all(devices.map(item => {
if (api && item.Id && api.deviceInfo.id === item.Id) {
return deleteDevice.mutateAsync({ id: item.Id });
}
Expand All @@ -93,7 +96,7 @@ export const Component = () => {
onCloseDeleteAllConfirmDialog();
});
}
}, [ api, deleteDevice, devices?.Items, onCloseDeleteAllConfirmDialog ]);
}, [ api, deleteDevice, devices, onCloseDeleteAllConfirmDialog ]);

const UserCell = getUserCell(users);

Expand Down Expand Up @@ -138,7 +141,7 @@ export const Component = () => {
...DEFAULT_TABLE_OPTIONS,

columns,
data: devices?.Items || [],
data: devices,

// State
initialState: {
Expand All @@ -152,6 +155,9 @@ export const Component = () => {
isLoading
},

// Do not reset the page index when refetching data
autoResetPageIndex: !isRefetching,

// Editing device name
enableEditing: true,
onEditingRowSave: ({ table, row, values }) => {
Expand Down

0 comments on commit 626f337

Please sign in to comment.