Skip to content

Conversation

lunalzm
Copy link
Contributor

@lunalzm lunalzm commented Oct 19, 2025

Description

This PR addresses several critical issues with table visualizations in the Explore plugin:

  1. Field Order Issue: Table columns were being displayed in type-based order (numerical → categorical → date) instead of preserving the original field order from the query response.
  2. Column Visibility Issue: When running new queries, fields would be hidden by default.
  3. Fix pagination not working
  4. Changed the table cell default text alignment to left to mitigate the table cell text move issue

The fixes ensure that table visualizations now correctly respect the field order specified in queries and properly manage column visibility across query executions.

Screenshot

Field Order

Before

Screenshot 2025-10-20 at 01 04 31

After

Screenshot 2025-10-20 at 01 06 42

Column Visibility

Before

Screenshot 2025-10-20 at 01 08 27

After

image

Testing the changes

  1. Field Order Test:
    SOURCE = opensearch_dashboards_sample_data_logs | FIELDS @timestamp, extension, bytes, agent
    - Verify fields appear in order: @timestamp → extension → bytes → agent
    - Previously would show: bytes → @timestamp → extension → agent
  2. Column Visibility Test:
    SOURCE = opensearch_dashboards_sample_data_logs | FIELDS bytes, memory, referer, url, agent
    - Verify all fields are hidden

Changelog

  • fix: Fix table vis fields order not the same as fields order in the query
  • fix: table vis pagination not working due to unnecessary rerendering
  • fix: change the default table column alignment to left

Check List

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

opensearch-changeset-bot bot added a commit to lunalzm/OpenSearch-Dashboards that referenced this pull request Oct 19, 2025
@codecov
Copy link

codecov bot commented Oct 19, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.50%. Comparing base (46060ab) to head (ad6135e).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...blic/components/visualizations/table/table_vis.tsx 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10754      +/-   ##
==========================================
+ Coverage   60.47%   60.50%   +0.02%     
==========================================
  Files        4484     4485       +1     
  Lines      120115   120185      +70     
  Branches    19892    19910      +18     
==========================================
+ Hits        72641    72719      +78     
+ Misses      42431    42426       -5     
+ Partials     5043     5040       -3     
Flag Coverage Δ
Linux_1 26.58% <ø> (ø)
Linux_2 38.82% <ø> (ø)
Linux_3 39.07% <ø> (+<0.01%) ⬆️
Linux_4 33.29% <90.90%> (+0.06%) ⬆️
Windows_1 26.59% <ø> (ø)
Windows_2 38.79% <ø> (ø)
Windows_3 39.07% <ø> (+<0.01%) ⬆️
Windows_4 33.29% <90.90%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lunalzm lunalzm changed the title [Explore] Fix fields order issue [Explore Vis] Fix fields order issue Oct 20, 2025
}
}, [styleOptions?.showColumnFilter]);

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Could you leave a comment on this useEffect to describe the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Collaborator

Choose a reason for hiding this comment

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

is this just a replacement by new columns?

Copy link
Member

Choose a reason for hiding this comment

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

@lunalzm How do you reproduce the issue?

Copy link
Member

Choose a reason for hiding this comment

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

@Hailong-am @lunalzm I removed this useEffect, and pushed a commit that fix the column visibility issue from the root

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just read the comment for this method and didn't read the logic fully, so i think it just a replacement by new columns. There have different property in VisColumn interface, i see we are using id, name and column, not sure what's the difference.

const sortedColumns = useMemo(() => [...columns].sort((a, b) => a.id - b.id), [columns]);

const newColumnIds = sortedColumns.map(({ column }) => column);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This issue sometimes happens when I run a new query or refresh the page. Some columns get hidden by default.

Screen.Recording.2025-10-21.at.16.54.54.mov

@lunalzm lunalzm force-pushed the fix-table-fields-order branch from f1b57ff to 3a9c07d Compare October 20, 2025 07:44
...(visualizationData?.dateColumns ?? []),
];

return allColumns.sort((a, b) => a.id - b.id);
Copy link
Member

Choose a reason for hiding this comment

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

Can you also check explore_embeddable.tsx to see if the same logic should apply there? or perhaps move this logic to table_vis component?

@ruanyl ruanyl changed the title [Explore Vis] Fix fields order issue [Explore Vis] Fix table visualiztion issues Oct 21, 2025

export const TableVis = React.memo(
({ rows, columns, styleOptions, pageSizeOptions, showStyleSelector }: TableVisProps) => {
const sortedColumns = useMemo(() => columns.sort((a, b) => a.id - b.id), [columns]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort will update the original columns, I prefer to construct a new array for sorting.

Copy link
Member

Choose a reason for hiding this comment

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

good point, I will update

rows={visualizationData.transformedData ?? []}
columns={columns}
/>
<TableVis styleOptions={visConfig.styles as TableChartStyle} rows={rows} columns={columns} />
Copy link
Member

Choose a reason for hiding this comment

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

I changed it to rows which is defined as this, should be the same

  const rows = useMemo(() => {
    return visualizationData?.transformedData ?? [];
  }, [visualizationData?.transformedData]);

// If there are common fields, preserve existing visible columns and add any new ones
useEffect(() => {
const currentFieldNames = sortedColumns.map(({ name }) => name);
const prevFieldNames = prevFieldNamesRef.current;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to delete this ref, can we calculate the new columns based prevVisibleColumns in setVisibleColumns callback and sortedColumns?

Copy link
Member

Choose a reason for hiding this comment

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

The overall implementation has changed, this useEffect no longer exists now


const renderFooterCellValue = useCallback(
({ columnId, setCellProps }: EuiDataGridCellValueElementProps) => {
const alignment = styleOptions?.globalAlignment || 'auto';
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be left as well?

Copy link
Member

Choose a reason for hiding this comment

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

that's right


export const TableVis = React.memo(
({ rows, columns, styleOptions, pageSizeOptions, showStyleSelector }: TableVisProps) => {
const sortedColumns = useMemo(() => [...columns].sort((a, b) => a.id - b.id), [columns]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we can make the columns is ordered in props in parent component, that could reduce the change.

Copy link
Member

Choose a reason for hiding this comment

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

This component is used at different places, having the sorting here is to avoid having the same logic at multiple places

@ruanyl
Copy link
Member

ruanyl commented Oct 21, 2025

Checked the failed test is unrelated, merging now

@ruanyl ruanyl merged commit 3848a76 into opensearch-project:main Oct 21, 2025
101 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants