Skip to content

Commit

Permalink
Fix server side checked items getter and fix useRequest when paginati…
Browse files Browse the repository at this point in the history
…on is a dependency

Change-type: patch
Signed-off-by: Andrea Rosci <andrear@balena.io>
  • Loading branch information
JSReds committed Jan 25, 2023
1 parent e24fe03 commit ec3c4ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/components/Table/TableBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,22 @@ export class TableBase<T extends {}> extends React.Component<
);

private getSelectedRows = (selectedRows: T[]) => {
const { rowKey, data } = this.props;

const selectedKeys = this.$getSelectedIdentifiersSet(selectedRows, rowKey);
const checkedItems = this.$getValidatedCheckedItems(
data,
selectedKeys,
rowKey,
selectedRows,
);
const { rowKey, data, pagination } = this.props;
let checkedItems;
if (!pagination?.serverSide) {
const selectedKeys = this.$getSelectedIdentifiersSet(
selectedRows,
rowKey,
);
checkedItems = this.$getValidatedCheckedItems(
data,
selectedKeys,
rowKey,
selectedRows,
);
} else {
checkedItems = selectedRows;
}
const checkedState = this.howManyRowsChecked(checkedItems);

return { checkedItems, checkedState };
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/useRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface UseRequestOptions {
polling: boolean;
pollInterval?: number;
stopExecution?: boolean;
resetDataDependencies?: React.DependencyList;
}

type RequestError = Error | null | undefined;
Expand Down Expand Up @@ -103,8 +104,14 @@ export const useRequest = <
return;
}
setData(undefined);
}, [...(options?.resetDataDependencies ?? deps), polling]);

React.useEffect(() => {
if (!polling) {
return;
}
forcePoll();
}, [...deps, polling]);
}, [...deps]);

const result = [data, loading, error, forcePoll] as UseRequestResult<TResult>;
result.data = data;
Expand Down

0 comments on commit ec3c4ac

Please sign in to comment.