Skip to content

Commit

Permalink
fix re-rendering with colums/data (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbetancur authored Aug 17, 2021
1 parent 2e7bfce commit 1b272dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-data-table-component",
"version": "7.0.0-rc4",
"version": "7.0.0-rc5",
"description": "A declarative react based data table",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -56,8 +56,8 @@
"@types/react": "^17.0.18",
"@types/react-dom": "^17.0.9",
"@types/styled-components": "^5.1.12",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"codecov": "^3.8.3",
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ function DataTable<T extends RowRecord>(props: TableProps<T>): JSX.Element {

dispatch({ type: 'SELECT_MULTIPLE_ROWS', keyField, selectedRows: preSelectedRows, rows: rows, mergeSelections });
}
// We only want to update the selectedRowState if the rows change
// We only want to update the selectedRowState if data changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rows]);
}, [data]);

const rowData = selectableRowsVisibleOnly ? tableRows : rows;
const showSelectAll = persistSelectedOnPageChange || selectableRowsSingle || selectableRowsNoSelectAll;
Expand Down
14 changes: 8 additions & 6 deletions src/hooks/useColumns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { decorateColumns, findColumnIndexById, getSortDirection } from '../DataTable/util';
import useDidUpdateEffect from '../hooks/useDidUpdateEffect';
import { SortDirection, TableColumn } from '../DataTable/types';

type ColumnsHook<T> = {
Expand All @@ -20,19 +21,20 @@ function useColumns<T>(
defaultSortFieldId: string | number | null | undefined,
defaultSortAsc: boolean,
): ColumnsHook<T> {
// decorate columns with additional metadata required by RDT
const columnsMemo = React.useMemo(() => decorateColumns(columns), [columns]);

const [tableColumns, setCalculatedColumns] = React.useState(columnsMemo);
const [tableColumns, setTableColumns] = React.useState<TableColumn<T>[]>(() => decorateColumns(columns));
const [draggingColumnId, setDraggingColumn] = React.useState('');
const sourceColumnId = React.useRef('');

useDidUpdateEffect(() => {
setTableColumns(decorateColumns(columns));
}, [columns]);

const handleDragStart = (e: React.DragEvent<HTMLDivElement>) => {
const { attributes } = e.target as HTMLDivElement;
const id = attributes.getNamedItem('data-column-id')?.value;

if (id) {
sourceColumnId.current = columnsMemo[findColumnIndexById(columnsMemo, id)]?.id?.toString() || '';
sourceColumnId.current = tableColumns[findColumnIndexById(tableColumns, id)]?.id?.toString() || '';

setDraggingColumn(sourceColumnId.current);
}
Expand All @@ -50,7 +52,7 @@ function useColumns<T>(
reorderedCols[selectedColIndex] = tableColumns[targetColIndex];
reorderedCols[targetColIndex] = tableColumns[selectedColIndex];

setCalculatedColumns(reorderedCols);
setTableColumns(reorderedCols);

onColumnOrderChange(reorderedCols);
}
Expand Down
82 changes: 41 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3019,28 +3019,28 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^4.29.1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.1.tgz#808d206e2278e809292b5de752a91105da85860b"
integrity sha512-AHqIU+SqZZgBEiWOrtN94ldR3ZUABV5dUG94j8Nms9rQnHFc8fvDOue/58K4CFz6r8OtDDc35Pw9NQPWo0Ayrw==
"@typescript-eslint/eslint-plugin@^4.29.2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.2.tgz#f54dc0a32b8f61c6024ab8755da05363b733838d"
integrity sha512-x4EMgn4BTfVd9+Z+r+6rmWxoAzBaapt4QFqE+d8L8sUtYZYLDTK6VG/y/SMMWA5t1/BVU5Kf+20rX4PtWzUYZg==
dependencies:
"@typescript-eslint/experimental-utils" "4.29.1"
"@typescript-eslint/scope-manager" "4.29.1"
"@typescript-eslint/experimental-utils" "4.29.2"
"@typescript-eslint/scope-manager" "4.29.2"
debug "^4.3.1"
functional-red-black-tree "^1.0.1"
regexpp "^3.1.0"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/[email protected].1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.29.1.tgz#0af2b17b0296b60c6b207f11062119fa9c5a8994"
integrity sha512-kl6QG6qpzZthfd2bzPNSJB2YcZpNOrP6r9jueXupcZHnL74WiuSjaft7WSu17J9+ae9zTlk0KJMXPUj0daBxMw==
"@typescript-eslint/[email protected].2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.29.2.tgz#5f67fb5c5757ef2cb3be64817468ba35c9d4e3b7"
integrity sha512-P6mn4pqObhftBBPAv4GQtEK7Yos1fz/MlpT7+YjH9fTxZcALbiiPKuSIfYP/j13CeOjfq8/fr9Thr2glM9ub7A==
dependencies:
"@types/json-schema" "^7.0.7"
"@typescript-eslint/scope-manager" "4.29.1"
"@typescript-eslint/types" "4.29.1"
"@typescript-eslint/typescript-estree" "4.29.1"
"@typescript-eslint/scope-manager" "4.29.2"
"@typescript-eslint/types" "4.29.2"
"@typescript-eslint/typescript-estree" "4.29.2"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

Expand All @@ -3056,14 +3056,14 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^4.29.1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.29.1.tgz#17dfbb45c9032ffa0fe15881d20fbc2a4bdeb02d"
integrity sha512-3fL5iN20hzX3Q4OkG7QEPFjZV2qsVGiDhEwwh+EkmE/w7oteiOvUNzmpu5eSwGJX/anCryONltJ3WDmAzAoCMg==
"@typescript-eslint/parser@^4.29.2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.29.2.tgz#1c7744f4c27aeb74610c955d3dce9250e95c370a"
integrity sha512-WQ6BPf+lNuwteUuyk1jD/aHKqMQ9jrdCn7Gxt9vvBnzbpj7aWEf+aZsJ1zvTjx5zFxGCt000lsbD9tQPEL8u6g==
dependencies:
"@typescript-eslint/scope-manager" "4.29.1"
"@typescript-eslint/types" "4.29.1"
"@typescript-eslint/typescript-estree" "4.29.1"
"@typescript-eslint/scope-manager" "4.29.2"
"@typescript-eslint/types" "4.29.2"
"@typescript-eslint/typescript-estree" "4.29.2"
debug "^4.3.1"

"@typescript-eslint/[email protected]":
Expand All @@ -3074,23 +3074,23 @@
"@typescript-eslint/types" "4.22.0"
"@typescript-eslint/visitor-keys" "4.22.0"

"@typescript-eslint/[email protected].1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.29.1.tgz#f25da25bc6512812efa2ce5ebd36619d68e61358"
integrity sha512-Hzv/uZOa9zrD/W5mftZa54Jd5Fed3tL6b4HeaOpwVSabJK8CJ+2MkDasnX/XK4rqP5ZTWngK1ZDeCi6EnxPQ7A==
"@typescript-eslint/[email protected].2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.29.2.tgz#442b0f029d981fa402942715b1718ac7fcd5aa1b"
integrity sha512-mfHmvlQxmfkU8D55CkZO2sQOueTxLqGvzV+mG6S/6fIunDiD2ouwsAoiYCZYDDK73QCibYjIZmGhpvKwAB5BOA==
dependencies:
"@typescript-eslint/types" "4.29.1"
"@typescript-eslint/visitor-keys" "4.29.1"
"@typescript-eslint/types" "4.29.2"
"@typescript-eslint/visitor-keys" "4.29.2"

"@typescript-eslint/[email protected]":
version "4.22.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.22.0.tgz#0ca6fde5b68daf6dba133f30959cc0688c8dd0b6"
integrity sha512-sW/BiXmmyMqDPO2kpOhSy2Py5w6KvRRsKZnV0c4+0nr4GIcedJwXAq+RHNK4lLVEZAJYFltnnk1tJSlbeS9lYA==

"@typescript-eslint/[email protected].1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.29.1.tgz#94cce6cf7cc83451df03339cda99d326be2feaf5"
integrity sha512-Jj2yu78IRfw4nlaLtKjVaGaxh/6FhofmQ/j8v3NXmAiKafbIqtAPnKYrf0sbGjKdj0hS316J8WhnGnErbJ4RCA==
"@typescript-eslint/[email protected].2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.29.2.tgz#fc0489c6b89773f99109fb0aa0aaddff21f52fcd"
integrity sha512-K6ApnEXId+WTGxqnda8z4LhNMa/pZmbTFkDxEBLQAbhLZL50DjeY0VIDCml/0Y3FlcbqXZrABqrcKxq+n0LwzQ==

"@typescript-eslint/[email protected]":
version "4.22.0"
Expand All @@ -3105,13 +3105,13 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected].1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.29.1.tgz#7b32a25ff8e51f2671ccc6b26cdbee3b1e6c5e7f"
integrity sha512-lIkkrR9E4lwZkzPiRDNq0xdC3f2iVCUjw/7WPJ4S2Sl6C3nRWkeE1YXCQ0+KsiaQRbpY16jNaokdWnm9aUIsfw==
"@typescript-eslint/[email protected].2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.29.2.tgz#a0ea8b98b274adbb2577100ba545ddf8bf7dc219"
integrity sha512-TJ0/hEnYxapYn9SGn3dCnETO0r+MjaxtlWZ2xU+EvytF0g4CqTpZL48SqSNn2hXsPolnewF30pdzR9a5Lj3DNg==
dependencies:
"@typescript-eslint/types" "4.29.1"
"@typescript-eslint/visitor-keys" "4.29.1"
"@typescript-eslint/types" "4.29.2"
"@typescript-eslint/visitor-keys" "4.29.2"
debug "^4.3.1"
globby "^11.0.3"
is-glob "^4.0.1"
Expand All @@ -3126,12 +3126,12 @@
"@typescript-eslint/types" "4.22.0"
eslint-visitor-keys "^2.0.0"

"@typescript-eslint/[email protected].1":
version "4.29.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.29.1.tgz#0615be8b55721f5e854f3ee99f1a714f2d093e5d"
integrity sha512-zLqtjMoXvgdZY/PG6gqA73V8BjqPs4af1v2kiiETBObp+uC6gRYnJLmJHxC0QyUrrHDLJPIWNYxoBV3wbcRlag==
"@typescript-eslint/[email protected].2":
version "4.29.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.29.2.tgz#d2da7341f3519486f50655159f4e5ecdcb2cd1df"
integrity sha512-bDgJLQ86oWHJoZ1ai4TZdgXzJxsea3Ee9u9wsTAvjChdj2WLcVsgWYAPeY7RQMn16tKrlQaBnpKv7KBfs4EQag==
dependencies:
"@typescript-eslint/types" "4.29.1"
"@typescript-eslint/types" "4.29.2"
eslint-visitor-keys "^2.0.0"

"@webassemblyjs/[email protected]":
Expand Down

0 comments on commit 1b272dd

Please sign in to comment.