Skip to content

Commit

Permalink
[8.17] [Controls] Persist `runPastTimeout` setting (#208611) (
Browse files Browse the repository at this point in the history
#208764)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Controls] Persist `runPastTimeout` setting
(#208611)](#208611)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-01-29T14:46:29Z","message":"[Controls]
Persist `runPastTimeout` setting (#208611)\n\nCloses
https://github.com/elastic/kibana/issues/206459\r\n\r\n##
Summary\r\n\r\nThis PR ensures that the `runPastTimeout` setting is
persisted for\r\noptions list controls and the UI reflects the value of
this setting. The\r\nroot cause of this bug is that we weren't sending
in the behavior\r\nsubject for `runPastTimeout# Backport

This will backport the following commits from `main` to `8.17`:
- [[Controls] Persist &#x60;runPastTimeout&#x60; setting
(#208611)](#208611)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT to the data control's `editorStateManager`\r\nwhen
initializing the options list control, which meant that its
value\r\ncould not be set by the options list's `CustomOptionsComponent`
- this\r\nPR fixes
that.\r\n\r\n**Before**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/2c9eeab8-67d9-46bc-938e-4d7cb91e435f\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d06b6ffa-b1e9-4ecd-b732-69bd69a8aee9\r\n\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\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"da41b8be52609ae62b1baad13fcdbc04f5d1b9a9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","regression","release_note:fix","Feature:Input
Control","Team:Presentation","loe:small","impact:high","v9.0.0","Project:Controls","backport:prev-major","project:embeddableRebuild"],"title":"[Controls]
Persist `runPastTimeout`
setting","number":208611,"url":"https://github.com/elastic/kibana/pull/208611","mergeCommit":{"message":"[Controls]
Persist `runPastTimeout` setting (#208611)\n\nCloses
https://github.com/elastic/kibana/issues/206459\r\n\r\n##
Summary\r\n\r\nThis PR ensures that the `runPastTimeout` setting is
persisted for\r\noptions list controls and the UI reflects the value of
this setting. The\r\nroot cause of this bug is that we weren't sending
in the behavior\r\nsubject for `runPastTimeout# Backport

This will backport the following commits from `main` to `8.17`:
- [[Controls] Persist &#x60;runPastTimeout&#x60; setting
(#208611)](#208611)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT to the data control's `editorStateManager`\r\nwhen
initializing the options list control, which meant that its
value\r\ncould not be set by the options list's `CustomOptionsComponent`
- this\r\nPR fixes
that.\r\n\r\n**Before**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/2c9eeab8-67d9-46bc-938e-4d7cb91e435f\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d06b6ffa-b1e9-4ecd-b732-69bd69a8aee9\r\n\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\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"da41b8be52609ae62b1baad13fcdbc04f5d1b9a9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208611","number":208611,"mergeCommit":{"message":"[Controls]
Persist `runPastTimeout` setting (#208611)\n\nCloses
https://github.com/elastic/kibana/issues/206459\r\n\r\n##
Summary\r\n\r\nThis PR ensures that the `runPastTimeout` setting is
persisted for\r\noptions list controls and the UI reflects the value of
this setting. The\r\nroot cause of this bug is that we weren't sending
in the behavior\r\nsubject for `runPastTimeout# Backport

This will backport the following commits from `main` to `8.17`:
- [[Controls] Persist &#x60;runPastTimeout&#x60; setting
(#208611)](#208611)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT to the data control's `editorStateManager`\r\nwhen
initializing the options list control, which meant that its
value\r\ncould not be set by the options list's `CustomOptionsComponent`
- this\r\nPR fixes
that.\r\n\r\n**Before**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/2c9eeab8-67d9-46bc-938e-4d7cb91e435f\r\n\r\n**After**\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d06b6ffa-b1e9-4ecd-b732-69bd69a8aee9\r\n\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\r\n- [x] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"da41b8be52609ae62b1baad13fcdbc04f5d1b9a9"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
  • Loading branch information
kibanamachine and Heenawter authored Jan 29, 2025
1 parent 5a3d1fb commit c71c9c0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,27 @@ describe('Options list sorting button', () => {
return component;
};

test('run past timeout', async () => {
const component = mountComponent({
initialState: getMockedState({ runPastTimeout: false }),
field: { type: 'string' } as DataViewField,
describe('run past timeout', () => {
test('can toggle the setting', async () => {
const component = mountComponent({
initialState: getMockedState({ runPastTimeout: false }),
field: { type: 'string' } as DataViewField,
});
const toggle = component.getByTestId('optionsListControl__runPastTimeoutAdditionalSetting');
expect(toggle.getAttribute('aria-checked')).toBe('false');
await userEvent.click(toggle);
expect(updateState).toBeCalledWith({ runPastTimeout: true });
expect(toggle.getAttribute('aria-checked')).toBe('true');
});

test('setting is persisted', async () => {
const component = mountComponent({
initialState: getMockedState({ runPastTimeout: true }),
field: { type: 'string' } as DataViewField,
});
const toggle = component.getByTestId('optionsListControl__runPastTimeoutAdditionalSetting');
expect(toggle.getAttribute('aria-checked')).toBe('true');
});
const toggle = component.getByTestId('optionsListControl__runPastTimeoutAdditionalSetting');
expect(toggle.getAttribute('aria-checked')).toBe('false');
await userEvent.click(toggle);
expect(updateState).toBeCalledWith({ runPastTimeout: true });
expect(toggle.getAttribute('aria-checked')).toBe('true');
});

test('selection options', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ import React from 'react';

import { DataView } from '@kbn/data-views-plugin/common';
import { createStubDataView } from '@kbn/data-views-plugin/common/data_view.stub';
import { act, render, waitFor } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { coreServices, dataViewsService } from '../../../services/kibana_services';
import { getMockedBuildApi, getMockedControlGroupApi } from '../../mocks/control_mocks';
import * as initializeControl from '../initialize_data_control';
import { getOptionsListControlFactory } from './get_options_list_control_factory';

describe('Options List Control Api', () => {
const uuid = 'myControl1';
const controlGroupApi = getMockedControlGroupApi();

const waitOneTick = () => act(() => new Promise((resolve) => setTimeout(resolve, 0)));

dataViewsService.get = jest.fn().mockImplementation(async (id: string): Promise<DataView> => {
if (id !== 'myDataViewId') {
throw new Error(`Simulated error: no data view found for id ${id}`);
Expand Down Expand Up @@ -198,10 +197,13 @@ describe('Options List Control Api', () => {

expect(control.getByTestId('optionsList-control-selection-exists')).toBeChecked();
const option = control.getByTestId('optionsList-control-selection-woof');

await userEvent.click(option);
await waitOneTick();
await waitFor(async () => {
expect(option).toBeChecked();
});

expect(control.getByTestId('optionsList-control-selection-exists')).not.toBeChecked();
expect(option).toBeChecked();
});

test('clicking "Exists" unselects all other selections', async () => {
Expand Down Expand Up @@ -229,8 +231,10 @@ describe('Options List Control Api', () => {
expect(control.getByTestId('optionsList-control-selection-meow')).not.toBeChecked();

await userEvent.click(existsOption);
await waitOneTick();
expect(existsOption).toBeChecked();
await waitFor(async () => {
expect(existsOption).toBeChecked();
});

expect(control.getByTestId('optionsList-control-selection-woof')).not.toBeChecked();
expect(control.getByTestId('optionsList-control-selection-bark')).not.toBeChecked();
expect(control.getByTestId('optionsList-control-selection-meow')).not.toBeChecked();
Expand Down Expand Up @@ -260,8 +264,10 @@ describe('Options List Control Api', () => {
expect(control.queryByTestId('optionsList-control-selection-meow')).toBeNull();

await userEvent.click(control.getByTestId('optionsList-control-selection-bark'));
await waitOneTick();
expect(control.getByTestId('optionsList-control-selection-woof')).toBeChecked();
await waitFor(async () => {
expect(control.getByTestId('optionsList-control-selection-woof')).toBeChecked();
});

expect(control.queryByTestId('optionsList-control-selection-bark')).toBeNull();
expect(control.queryByTestId('optionsList-control-selection-meow')).toBeNull();

Expand Down Expand Up @@ -316,9 +322,12 @@ describe('Options List Control Api', () => {
expect(control.getByTestId('optionsList-control-selection-woof')).toBeChecked();
expect(control.queryByTestId('optionsList-control-selection-bark')).not.toBeChecked();
expect(control.queryByTestId('optionsList-control-selection-meow')).not.toBeChecked();

await userEvent.click(control.getByTestId('optionsList-control-selection-bark'));
await waitOneTick();
expect(control.getByTestId('optionsList-control-selection-woof')).not.toBeChecked();
await waitFor(async () => {
expect(control.getByTestId('optionsList-control-selection-woof')).not.toBeChecked();
});

expect(control.queryByTestId('optionsList-control-selection-bark')).toBeChecked();
expect(control.queryByTestId('optionsList-control-selection-meow')).not.toBeChecked();

Expand All @@ -337,4 +346,35 @@ describe('Options List Control Api', () => {
]);
});
});

test('ensure initialize data control contains all editor state', async () => {
const initializeSpy = jest.spyOn(initializeControl, 'initializeDataControl');
const initialState = {
dataViewId: 'myDataViewId',
fieldName: 'myFieldName',
runPastTimeout: true,
};
await factory.buildControl(
{
dataViewId: 'myDataViewId',
fieldName: 'myFieldName',
runPastTimeout: true,
},
getMockedBuildApi(uuid, factory, controlGroupApi),
uuid,
controlGroupApi
);
expect(initializeSpy).toHaveBeenCalledWith(
uuid,
'optionsListControl',
'optionsListDataView',
initialState,
{
searchTechnique: expect.anything(),
singleSelect: expect.anything(),
runPastTimeout: expect.anything(),
},
controlGroupApi
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ export const getOptionsListControlFactory = (): DataControlFactory<
const totalCardinality$ = new BehaviorSubject<number>(0);

const dataControl = initializeDataControl<
Pick<OptionsListControlState, 'searchTechnique' | 'singleSelect'>
Pick<OptionsListControlState, 'searchTechnique' | 'singleSelect' | 'runPastTimeout'>
>(
uuid,
OPTIONS_LIST_CONTROL,
'optionsListDataView',
initialState,
{ searchTechnique: searchTechnique$, singleSelect: singleSelect$ },
{
searchTechnique: searchTechnique$,
singleSelect: singleSelect$,
runPastTimeout: runPastTimeout$,
},
controlGroupApi
);

Expand Down

0 comments on commit c71c9c0

Please sign in to comment.