-
Notifications
You must be signed in to change notification settings - Fork 885
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
[Bug][Table Visualization] Fix first column sort issue #2828
Conversation
return uiState.sort.colIndex !== null && uiState.sort.direction | ||
? orderBy(rows, columns[uiState.sort.colIndex]?.id, uiState.sort.direction) | ||
: rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return uiState.sort.colIndex !== null && uiState.sort.direction | |
? orderBy(rows, columns[uiState.sort.colIndex]?.id, uiState.sort.direction) | |
: rows; | |
return columns[uiState.sort?.colIndex]?.id | |
? orderBy(rows, columns[uiState.sort.colIndex].id, uiState.sort.direction || <whatever the default is>) | |
: rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ananzh confirmed that this is not directly user input.
return uiState.sort.colIndex !== null && uiState.sort.direction | ||
? orderBy(rows, columns[uiState.sort.colIndex]?.id, uiState.sort.direction) | ||
: rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ananzh confirmed that this is not directly user input.
return uiState.sort.colIndex !== null && uiState.sort.direction | ||
? orderBy(rows, columns[uiState.sort.colIndex].id, uiState.sort.direction) | ||
: rows; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still not comfortable that we are not checking the validity of id
before passing it to orderBy
.
PS, I would have preferred for lodash not even be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, from the description, it sounds like the bug was that colIndex === 0
evaluates falsey, which was not what you intended to check.
But I agree with @AMoo-Miki - what about the case where columns
is an empty array, or where the colIndex
is out of bounds? Seems like you also want to check columns[uiState.sort.colIndex].id
in your conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AMoo-Miki Sort is done on the frontend entirely. When click sort, component will be re-rendered with the new sort index and direction. The data (table.rows) is the same. But sortedRows will be re-calculated and then render in DataGrid --> entirely frontend. For example:
table. rows (always same)
:
Array(5)
0
:
{col-0-2: 'New York', col-1-1: 386}
1
:
{col-0-2: 'Dubai', col-1-1: 191}
2
:
{col-0-2: 'Cairo', col-1-1: 184}
3
:
{col-0-2: 'Marrakesh', col-1-1: 164}
4
:
{col-0-2: 'Cannes', col-1-1: 159}
sortedRows
:
Array(5)
0
:
{col-0-2: 'Cairo', col-1-1: 184}
1
:
{col-0-2: 'Cannes', col-1-1: 159}
2
:
{col-0-2: 'Dubai', col-1-1: 191}
3
:
{col-0-2: 'Marrakesh', col-1-1: 164}
4
:
{col-0-2: 'New York', col-1-1: 386}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshuarrrr From what I know, if there is no data, there are two cases:
- for
count
metric, table rows
0:
{col-0-1: 0}
- for other metric, table rows:
0:
{col-0-1: null}
So no matter what metric we use, we could sort. There is always a column. But if we think this is not 100% percent guaranteed, we could add more check
uiState.sort.colIndex !== null && columns[uiState.sort.colIndex].id && uiState.sort.direction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think uiState.sort.colIndex !== null && columns[uiState.sort.colIndex].id && uiState.sort.direction
would be the best.
I understand that there are simpler and more effective checks and TS is being stupid.
PS, is direction
really required? if sort is asked for and no direction is provided, it would be safer to just use a default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AMoo-Miki agree. I committed the change.
Codecov Report
@@ Coverage Diff @@
## main #2828 +/- ##
=======================================
Coverage 66.67% 66.68%
=======================================
Files 3219 3219
Lines 61445 61445
Branches 9417 9417
=======================================
+ Hits 40966 40972 +6
+ Misses 18232 18228 -4
+ Partials 2247 2245 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: #2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> (cherry picked from commit f12fa98) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: #2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> (cherry picked from commit f12fa98) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md
Update 2.4 release note to include: opensearch-project#2828 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Update 2.4 release note to include: opensearch-project#2828 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: #2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> (cherry picked from commit f12fa98) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: #2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> (cherry picked from commit f12fa98) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Update 2.4 release note to include: #2828 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Sergey Osipov <sipopo@yandex.ru>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: David Sinclair <david@sinclair.tech>
…oject#2828) Currently, the first column of table vis won't sort. This PR fixes the bug. Issue Resolved: opensearch-project#2827 Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: Anan Zhuang <ananzh@amazon.com> Signed-off-by: David Sinclair <david@sinclair.tech>
Description
Currently, the first column of table vis won't sort. This PR fixes the bug.
Issues Resolved
#2827
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr