Skip to content
Merged
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
2 changes: 2 additions & 0 deletions changelogs/fragments/10975.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix hideTimeColumn and isShortDots ([#10975](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10975))
10 changes: 5 additions & 5 deletions src/plugins/explore/public/helpers/data_table_helper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('data_table_helper', () => {
it('should return column properties without time field when hideTimeField is true', () => {
const columns = ['field1', 'field2'];

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);
const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);

expect(result).toHaveLength(2);
expect(result[0]).toEqual({
Expand Down Expand Up @@ -172,23 +172,23 @@ describe('data_table_helper', () => {
sortable: false,
});

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);
const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);

expect(result[0].isSortable).toBe(false); // Should use field.sortable when osdFieldOverrides.sortable is undefined
});

it('should handle _source column removability correctly', () => {
const columns = ['_source'];

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);
const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true); // hide time column

expect(result[0].isRemoveable).toBe(false); // _source is not removeable when it's the only column
});

it('should make _source column removeable when there are multiple columns', () => {
const columns = ['_source', 'field1'];

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);
const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);

expect(result[0].isRemoveable).toBe(true); // _source is removeable when there are other columns
expect(result[1].isRemoveable).toBe(true);
Expand All @@ -205,7 +205,7 @@ describe('data_table_helper', () => {
'spanId',
];

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);
const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Human-readable names test is correct; nearby _source test needs adjustment

The human‑readable names test now calls

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);

which appropriately sets isShortDots=false and hideTimeField=true, so the time column does not interfere with the expected display names.

However, in the nearby test “should handle _source column removability correctly” (Lines 180–186), you currently have:

const columns = ['_source'];

const result = getLegacyDisplayedColumns(columns, mockIndexPattern, true, false);

expect(result[0].isRemoveable).toBe(false); // _source is not removeable when it's the only column

With the new signature (columns, indexPattern, isShortDots, hideTimeField), the call true, false means isShortDots=true and hideTimeField=false. Because hideTimeField is false and timeFieldName is set, getLegacyDisplayedColumns will prepend the time column, so _source is no longer “the only column”. The assertion also indexes result[0] without checking name, which may now be asserting against the time column instead of _source.

I recommend tightening this test so that it truly covers the intended behavior:

it('should handle _source column removability correctly', () => {
  const columns = ['_source'];

  // isShortDots=false, hideTimeField=true: only `_source` is rendered
  const result = getLegacyDisplayedColumns(columns, mockIndexPattern, false, true);

  const sourceCol = result.find((col) => col.name === '_source');
  expect(sourceCol?.isRemoveable).toBe(false); // _source is not removeable when it's the only column
});
🤖 Prompt for AI Agents
In src/plugins/explore/public/helpers/data_table_helper.test.tsx around line
208, the nearby test for “should handle _source column removability correctly”
calls getLegacyDisplayedColumns(columns, mockIndexPattern, true, false) which
makes hideTimeField=false so a time column may be prepended and the test then
asserts result[0] which can target the time column; change the call to
getLegacyDisplayedColumns(columns, mockIndexPattern, false, true) so
isShortDots=false and hideTimeField=true (ensuring only _source is rendered),
then locate the `_source` column via result.find(col => col.name === '_source')
and assert that its isRemoveable is false instead of indexing result[0].


expect(result[0].displayName).toBe('Service Identifier');
expect(result[1].displayName).toBe('Duration');
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/explore/public/helpers/data_table_helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function getColumnDisplayName(column: string): string {
export function getLegacyDisplayedColumns(
columns: string[],
indexPattern: IndexPattern | Dataset,
hideTimeField: boolean,
isShortDots: boolean
isShortDots: boolean,
hideTimeField: boolean
): LegacyDisplayedColumn[] {
if (!Array.isArray(columns) || !indexPattern || !indexPattern.getFieldByName) {
return [];
Expand Down
Loading