Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): fix inability to update sorting props externally #472

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const Table: ForwardRefRenderFunction<TableHandlers, Props> = (props, ref) => {
dispatch({ type: Actions.rowsChanged, payload: rows });
}, [rows]);

useEffect(() => {
const newSorting = {
column: sorting?.column,
isDescending: sorting?.isDescending,
};

dispatch({ type: Actions.sortingChanged, payload: newSorting });
}, [sorting]);

useEffect(() => {
onRowSelect && onRowSelect(selected);
}, [selected]);
Expand Down
40 changes: 40 additions & 0 deletions src/components/Table/__tests__/__snapshots__/Table.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ exports[`<Table> matches snapshot 1`] = `
<span>
Header1
</span>
<span
class="sorting-icon"
data-testid="header1-sorting"
>
<svg-file-stub
height="20"
/>
</span>
</th>
<th
class="header-cell header2 "
Expand All @@ -30,6 +38,14 @@ exports[`<Table> matches snapshot 1`] = `
<span>
Header2
</span>
<span
class="sorting-icon"
data-testid="header2-sorting"
>
<svg-file-stub
height="20"
/>
</span>
</th>
<th
class="header-cell header3 "
Expand All @@ -39,6 +55,14 @@ exports[`<Table> matches snapshot 1`] = `
<span>
Header3
</span>
<span
class="sorting-icon"
data-testid="header3-sorting"
>
<svg-file-stub
height="20"
/>
</span>
</th>
<th
class="header-cell header4 "
Expand All @@ -48,6 +72,14 @@ exports[`<Table> matches snapshot 1`] = `
<span>
Header4
</span>
<span
class="sorting-icon"
data-testid="header4-sorting"
>
<svg-file-stub
height="20"
/>
</span>
</th>
<th
class="header-cell header5 "
Expand All @@ -57,6 +89,14 @@ exports[`<Table> matches snapshot 1`] = `
<span>
Header5
</span>
<span
class="sorting-icon"
data-testid="header5-sorting"
>
<svg-file-stub
height="20"
/>
</span>
</th>
</tr>
</thead>
Expand Down
Loading