forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG][Discover] Check if the timestamp is already included to remove …
…duplicate col (opensearch-project#6983) * check if the timestamp is already included to remove duplicate col --------- Signed-off-by: Anan Zhuang <ananzh@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
190dab0
commit 0db5848
Showing
4 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- [Discover] Check if the timestamp is already included to remove duplicate col ([#6983](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6983)) |
120 changes: 120 additions & 0 deletions
120
src/plugins/discover/public/application/components/default_discover_table/helper.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { getLegacyDisplayedColumns } from './helper'; | ||
import { IndexPattern } from '../../../opensearch_dashboards_services'; | ||
|
||
const mockGetFieldByName = jest.fn(); | ||
|
||
describe('getLegacyDisplayedColumns', () => { | ||
let indexPattern: IndexPattern; | ||
|
||
beforeEach(() => { | ||
indexPattern = ({ | ||
getFieldByName: mockGetFieldByName, | ||
timeFieldName: 'timestamp', | ||
} as unknown) as IndexPattern; | ||
mockGetFieldByName.mockReset(); | ||
}); | ||
|
||
it('should return correct column properties without time column', () => { | ||
mockGetFieldByName.mockReturnValue({ sortable: true }); | ||
const result = getLegacyDisplayedColumns(['column1'], indexPattern, true, false); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'column1', | ||
displayName: 'column1', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should prepend time column if not hidden, indexPattern has timeFieldName, and columns do not include timeFieldName', () => { | ||
mockGetFieldByName.mockReturnValue({ sortable: true }); | ||
const result = getLegacyDisplayedColumns(['column1'], indexPattern, false, false); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'timestamp', | ||
displayName: 'Time', | ||
isSortable: true, | ||
isRemoveable: false, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
{ | ||
name: 'column1', | ||
displayName: 'column1', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should not prepend time column if hideTimeField is true', () => { | ||
mockGetFieldByName.mockReturnValue({ sortable: true }); | ||
const result = getLegacyDisplayedColumns(['column1'], indexPattern, true, false); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'column1', | ||
displayName: 'column1', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should not prepend time column if timeFieldName is included in columns', () => { | ||
mockGetFieldByName.mockReturnValue({ sortable: true }); | ||
const result = getLegacyDisplayedColumns(['column1', 'timestamp'], indexPattern, false, false); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'column1', | ||
displayName: 'column1', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: -1, | ||
colRightIdx: 1, | ||
}, | ||
{ | ||
name: 'timestamp', | ||
displayName: 'timestamp', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: 0, | ||
colRightIdx: -1, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should shorten dotted string in displayName if isShortDots is true', () => { | ||
mockGetFieldByName.mockReturnValue({ sortable: true }); | ||
const result = getLegacyDisplayedColumns(['column.with.dots'], indexPattern, false, true); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'timestamp', | ||
displayName: 'Time', | ||
isSortable: true, | ||
isRemoveable: false, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
{ | ||
name: 'column.with.dots', | ||
displayName: 'c.w.dots', | ||
isSortable: true, | ||
isRemoveable: true, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters