[8.13] [DataView] Show previously selected no time field setting (#177221) (#177683)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[DataView] Show previously selected no time field setting
(#177221)](https://github.com/elastic/kibana/pull/177221)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2024-02-23T09:45:55Z","message":"[DataView]
Show previously selected no time field setting (#177221)\n\n- Closes
https://github.com/elastic/kibana/issues/177001\r\n\r\n##
Summary\r\n\r\nWhen editing a data view, previously selected time field
value will be\r\nchosen in the form.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"bd593149dbd37771a0e88381ee00f73055c73c3e","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:Data
Views","Team:DataDiscovery","backport:prev-minor","v8.14.0"],"number":177221,"url":"https://github.com/elastic/kibana/pull/177221","mergeCommit":{"message":"[DataView]
Show previously selected no time field setting (#177221)\n\n- Closes
https://github.com/elastic/kibana/issues/177001\r\n\r\n##
Summary\r\n\r\nWhen editing a data view, previously selected time field
value will be\r\nchosen in the form.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"bd593149dbd37771a0e88381ee00f73055c73c3e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.14.0","labelRegex":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/177221","number":177221,"mergeCommit":{"message":"[DataView]
Show previously selected no time field setting (#177221)\n\n- Closes
https://github.com/elastic/kibana/issues/177001\r\n\r\n##
Summary\r\n\r\nWhen editing a data view, previously selected time field
value will be\r\nchosen in the form.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"bd593149dbd37771a0e88381ee00f73055c73c3e"}}]}]
BACKPORT-->
This commit is contained in:
Julia Rechkunova 2024-03-05 00:09:51 +01:00 committed by GitHub
parent 6db81183b6
commit c28a129f1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 8 deletions

View file

@ -34,6 +34,8 @@ import { FlyoutPanels } from './flyout_panels';
import { removeSpaces } from '../lib';
import { noTimeFieldLabel, noTimeFieldValue } from '../lib/extract_time_fields';
import {
DataViewEditorContext,
RollupIndicesCapsResponse,
@ -109,7 +111,9 @@ const IndexPatternEditorFlyoutContentComponent = ({
id: editData.id,
name: editData.name,
allowHidden: editData.getAllowHidden(),
...(editData.timeFieldName
...(editData.timeFieldName === noTimeFieldValue
? { timestampField: { label: noTimeFieldLabel, value: noTimeFieldValue } }
: editData.timeFieldName
? {
timestampField: { label: editData.timeFieldName, value: editData.timeFieldName },
}

View file

@ -10,6 +10,14 @@ import { i18n } from '@kbn/i18n';
import { DataViewField } from '@kbn/data-views-plugin/public';
import { TimestampOption } from '../types';
export const noTimeFieldLabel = i18n.translate(
'indexPatternEditor.createIndexPattern.stepTime.noTimeFieldOptionLabel',
{
defaultMessage: "--- I don't want to use the time filter ---",
}
);
export const noTimeFieldValue = '';
export function extractTimeFields(
fields: DataViewField[],
requireTimestampField: boolean = false
@ -20,15 +28,9 @@ export function extractTimeFields(
return [];
}
const noTimeFieldLabel = i18n.translate(
'indexPatternEditor.createIndexPattern.stepTime.noTimeFieldOptionLabel',
{
defaultMessage: "--- I don't want to use the time filter ---",
}
);
const noTimeFieldOption = {
display: noTimeFieldLabel,
fieldName: '',
fieldName: noTimeFieldValue,
};
const timeFields = dateFields.map((field) => ({

View file

@ -185,6 +185,55 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.getVisibleText('indexPatternTitle')).to.contain(`Index Star`);
});
});
it('prefills the form with previously saved values', async () => {
await PageObjects.settings.editIndexPattern('logs*', 'utc_time', 'Logs UTC', true);
await PageObjects.settings.clickEditIndexButton();
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.waitFor('time field', async () => {
const timeFieldInput = await PageObjects.settings.getTimeFieldNameField();
return (await timeFieldInput.getAttribute('value')) === 'utc_time';
});
expect(await (await PageObjects.settings.getNameField()).getAttribute('value')).to.be(
'Logs UTC'
);
expect(
await (await PageObjects.settings.getIndexPatternField()).getAttribute('value')
).to.be('logs*');
await testSubjects.click('closeFlyoutButton');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await testSubjects.getVisibleText('currentIndexPatternTimeField')).to.be('utc_time');
await PageObjects.settings.editIndexPattern(
'logstash-*',
PageObjects.settings.noTimeFieldOption,
'Just logs',
true
);
await PageObjects.settings.clickEditIndexButton();
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.waitFor('time field', async () => {
const timeFieldInput = await PageObjects.settings.getTimeFieldNameField();
return (
(await timeFieldInput.getAttribute('value')) === PageObjects.settings.noTimeFieldOption
);
});
expect(await (await PageObjects.settings.getNameField()).getAttribute('value')).to.be(
'Just logs'
);
expect(
await (await PageObjects.settings.getIndexPatternField()).getAttribute('value')
).to.be('logstash-*');
await testSubjects.click('closeFlyoutButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.missingOrFail('currentIndexPatternTimeField');
});
});
describe('index pattern edit', function () {

View file

@ -152,6 +152,13 @@ export class SettingsPageObject extends FtrService {
return this.testSubjects.find('createIndexPatternTitleInput');
}
async getTimeFieldNameField() {
const wrapperElement = await this.testSubjects.find('timestampField');
return wrapperElement.findByTestSubject('comboBoxSearchInput');
}
noTimeFieldOption = "--- I don't want to use the time filter ---";
async selectTimeFieldOption(selection: string) {
const testSubj = 'timestampField';
const timefield = await this.testSubjects.find(testSubj);