[data view] Data view management - persist count / popularity number (#188285)

## Summary

Fixes updating of data view field popularity value. Previously, the data
view field would be changed but it wouldn't save.

Closes https://github.com/elastic/kibana/issues/188202
This commit is contained in:
Matthew Kime 2024-07-17 10:12:43 -05:00 committed by GitHub
parent 1cae23769a
commit 39017342ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 38 additions and 3 deletions

View file

@ -126,6 +126,7 @@ export const buildDataViewMock = ({
return dataViewFields.find((field) => field.name === timeFieldName);
},
getRuntimeField: () => null,
setFieldCount: jest.fn(),
} as unknown as DataView;
dataView.isTimeBased = () => !!timeFieldName;

View file

@ -320,6 +320,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -564,6 +565,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -820,6 +822,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -1063,6 +1066,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -1351,6 +1355,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -1632,6 +1637,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -1795,6 +1801,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -1950,6 +1957,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -2152,6 +2160,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -2366,6 +2375,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -2566,6 +2576,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -2768,6 +2779,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -3007,6 +3019,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],
@ -3224,6 +3237,7 @@ Array [
"_score",
],
"name": "index-pattern-with-timefield",
"setFieldCount": [MockFunction],
"timeFieldName": "timestamp",
"title": "index-pattern-with-timefield-title",
"toMinimalSpec": [Function],

View file

@ -38,11 +38,13 @@ describe('Popularize field', () => {
});
test('do not updates saved object if data view is not persisted', async () => {
const field = { count: 0 };
const dataView = {
id: 'id',
fields: {
getByName: () => ({ count: 0 }),
getByName: () => field,
},
setFieldCount: jest.fn(),
isPersisted: () => false,
} as unknown as DataView;
const updateSavedObjectMock = jest.fn();
@ -62,6 +64,9 @@ describe('Popularize field', () => {
fields: {
getByName: () => field,
},
setFieldCount: jest.fn().mockImplementation((fieldName, count) => {
field.count = count;
}),
isPersisted: () => true,
} as unknown as DataView;
const fieldName = '@timestamp';
@ -84,6 +89,9 @@ describe('Popularize field', () => {
fields: {
getByName: () => field,
},
setFieldCount: jest.fn().mockImplementation((fieldName, count) => {
field.count = count;
}),
isPersisted: () => true,
} as unknown as DataView;
const fieldName = '@timestamp';

View file

@ -22,7 +22,7 @@ async function popularizeField(
return;
}
field.count++;
dataView.setFieldCount(fieldName, field.count + 1);
if (!dataView.isPersisted()) {
return;

View file

@ -187,7 +187,10 @@ export class PreviewController {
this.dataView.setFieldCustomLabel(updatedField.name, updatedField.customLabel);
this.dataView.setFieldCustomDescription(updatedField.name, updatedField.customDescription);
editedField.count = updatedField.popularity || 0;
if (updatedField.popularity !== undefined) {
this.dataView.setFieldCount(updatedField.name, updatedField.popularity || 0);
}
if (updatedField.format) {
this.dataView.setFieldFormat(updatedField.name, updatedField.format!);
} else {

View file

@ -442,6 +442,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await PageObjects.unifiedFieldList.getSidebarAriaDescription()).to.be(
'3 selected fields. 3 popular fields. 48 available fields. 5 empty fields. 4 meta fields.'
);
// verify popular fields were persisted
await browser.refresh();
await PageObjects.unifiedFieldList.waitUntilSidebarHasLoaded();
expect(await PageObjects.unifiedFieldList.getSidebarAriaDescription()).to.be(
'3 selected fields. 3 popular fields. 48 available fields. 5 empty fields. 4 meta fields.'
);
});
it('should show selected and available fields in ES|QL mode', async function () {

View file

@ -12,6 +12,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const log = getService('log');
const PageObjects = getPageObjects(['settings', 'common']);
@ -58,6 +59,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('can be saved', async function () {
// Saving the popularity change
await PageObjects.settings.controlChangeSave();
await browser.refresh();
await PageObjects.settings.openControlsByName(fieldName);
const popularity = await PageObjects.settings.getPopularity();
log.debug('popularity = ' + popularity);