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

[Bug][Table Visualization] Fix first column sort issue #2828

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Nov 8, 2022

Description

Currently, the first column of table vis won't sort. This PR fixes the bug.

Issues Resolved

#2827

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@ananzh ananzh requested a review from a team as a code owner November 8, 2022 17:37
@ananzh ananzh self-assigned this Nov 8, 2022
@ananzh ananzh added bug Something isn't working v2.4.0 'Issues and PRs related to version v2.4.0' backport 2.x backport 2.4 tableVis table visualization labels Nov 8, 2022
Comment on lines 41 to 45
return uiState.sort.colIndex !== null && uiState.sort.direction
? orderBy(rows, columns[uiState.sort.colIndex]?.id, uiState.sort.direction)
: rows;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Copy link
Collaborator

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.

AMoo-Miki
AMoo-Miki previously approved these changes Nov 8, 2022
Comment on lines 41 to 45
return uiState.sort.colIndex !== null && uiState.sort.direction
? orderBy(rows, columns[uiState.sort.colIndex]?.id, uiState.sort.direction)
: rows;
Copy link
Collaborator

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.

Comment on lines 41 to 45
return uiState.sort.colIndex !== null && uiState.sort.direction
? orderBy(rows, columns[uiState.sort.colIndex].id, uiState.sort.direction)
: rows;
Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Member Author

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}

Copy link
Member Author

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

Copy link
Collaborator

@AMoo-Miki AMoo-Miki Nov 8, 2022

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.

Copy link
Member Author

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-commenter
Copy link

Codecov Report

Merging #2828 (f1b868b) into main (5608f82) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           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     
Impacted Files Coverage Δ
...rce/components/edit_form/edit_data_source_form.tsx 91.45% <0.00%> (ø)
...ts/update_password_modal/update_password_modal.tsx 95.83% <0.00%> (ø)
...components/create_form/create_data_source_form.tsx 98.36% <0.00%> (ø)
...ic/application/models/sense_editor/sense_editor.ts 64.88% <0.00%> (+0.88%) ⬆️
packages/osd-optimizer/src/node/cache.ts 52.63% <0.00%> (+2.63%) ⬆️
...s/osd-optimizer/src/node/node_auto_tranpilation.ts 87.75% <0.00%> (+4.08%) ⬆️

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>
@ananzh ananzh merged commit f12fa98 into opensearch-project:main Nov 9, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 9, 2022
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
opensearch-trigger-bot bot pushed a commit that referenced this pull request Nov 9, 2022
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
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Nov 9, 2022
Update 2.4 release note to include:
opensearch-project#2828

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Nov 9, 2022
Update 2.4 release note to include:
opensearch-project#2828

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
ananzh pushed a commit that referenced this pull request Nov 9, 2022
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>
ananzh pushed a commit that referenced this pull request Nov 9, 2022
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>
ananzh added a commit that referenced this pull request Nov 9, 2022
Update 2.4 release note to include:
#2828

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
AlexRuiz7 pushed a commit to wazuh/wazuh-dashboard that referenced this pull request Dec 14, 2022
…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>
AlexRuiz7 pushed a commit to wazuh/wazuh-dashboard that referenced this pull request Dec 14, 2022
…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>
sipopo pushed a commit to sipopo/OpenSearch-Dashboards that referenced this pull request Dec 16, 2022
…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>
Arpit-Bandejiya pushed a commit to Arpit-Bandejiya/OpenSearch-Dashboards that referenced this pull request Jan 13, 2023
…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>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
…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>
sikhote pushed a commit to sikhote/OpenSearch-Dashboards that referenced this pull request Apr 24, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x bug Something isn't working tableVis table visualization v2.4.0 'Issues and PRs related to version v2.4.0'
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants