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

[Discover] Default Columns do not always apply with switching Data Views #168581

Closed
kertal opened this issue Oct 11, 2023 · 1 comment · Fixed by #168994
Closed

[Discover] Default Columns do not always apply with switching Data Views #168581

kertal opened this issue Oct 11, 2023 · 1 comment · Fixed by #168994
Labels
bug Fixes for quality problems that affect the customer experience :DataDiscovery/fix-it-week Feature:Discover Discover Application impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.

Comments

@kertal
Copy link
Member

kertal commented Oct 11, 2023

Kibana version:
main, 8.11, 8.10, ....

Describe the bug:
When switching Data Views in Discover, the Advanced Setting "Default Columns" does not always apply.

Steps to reproduce:

  1. Add Kibana Sample Data Logs and Kibana Sample eCommerce Data of our Sample data
  2. In Advanced settings / Discover / Default Columns enter timestamp, message, agent and save this setting
  3. Navigate to Discover
  4. Select Kibana Sample Data Logs of the data view picker
  5. Now you should be able to see the configured columns
  6. Select Kibana Sample eCommerce Data of the data view picker
  7. Now you should be able to see timestamp, Document as columns, this is expected, unless you configured discover:modifyColumnsOnSwitch to Off, which prevents modifying the columns on switching
  8. Select Kibana Sample Data Logs of the data view picker, again
  9. Now the columns are still timestamp, Document

Expected behavior:
When switching back to Kibana Sample Data Logs, the configured Default Columns should be displayed

** Recording **

Kapture.2023-10-11.at.12.27.33.mp4

Context
Here's the code responsible for the next state when switching data views:

export function getDataViewAppState(
currentDataView: DataView,
nextDataView: DataView,
currentColumns: string[],
currentSort: SortOrder[],
modifyColumns: boolean = true,
sortDirection: string = 'desc',
query?: Query | AggregateQuery
) {
const nextColumns = modifyColumns
? currentColumns.filter(
(column) =>
nextDataView.fields.getByName(column) || !currentDataView.fields.getByName(column)
)
: currentColumns;
let columns = nextColumns.length ? nextColumns : [];
if (query && isOfAggregateQueryType(query)) {
columns = [];
}
// when switching from an data view with timeField to an data view without timeField
// filter out sorting by timeField in case it is set. data views without timeField don't
// prepend this field in the table, so in legacy grid you would need to add this column to
// remove sorting
let nextSort = getSortArray(currentSort, nextDataView).filter((value) => {
return nextDataView.timeFieldName || value[0] !== currentDataView.timeFieldName;
});
if (nextDataView.isTimeBased() && !nextSort.length) {
// set default sorting if it was not set
nextSort = [[nextDataView.timeFieldName, sortDirection]];
} else if (
nextDataView.isTimeBased() &&
currentDataView.isTimeBased() &&
nextDataView.timeFieldName !== currentDataView.timeFieldName
) {
// switch time fields
nextSort = nextSort.map((cur) =>
cur[0] === currentDataView.timeFieldName ? [nextDataView.timeFieldName, cur[1]] : cur
);
}
return {
index: nextDataView.id,
columns,
sort: nextSort,
};
}

Additional info
Reported by @sophiec20

@kertal kertal added bug Fixes for quality problems that affect the customer experience Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. :DataDiscovery/fix-it-week labels Oct 11, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@kertal kertal added loe:small Small Level of Effort impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. labels Oct 31, 2023
jughosta added a commit that referenced this issue Nov 16, 2023
…#168994)

- Closes #168581

## Summary

This PR re-adds default columns when changing data views. Only columns
which are present in the data view will be re-added.

For testing: configure some fields for `defaultColumns` on Advanced
Settings page and test switching data views on Discover page.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience :DataDiscovery/fix-it-week Feature:Discover Discover Application impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants