Skip to content

Commit

Permalink
Merge branch 'main' into versioning-all-ml-apis
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic authored May 17, 2023
2 parents 7b1c693 + 0bd0463 commit a5bc2cc
Show file tree
Hide file tree
Showing 21 changed files with 457 additions and 329 deletions.
2 changes: 1 addition & 1 deletion config/serverless.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Disable APM and Uptime, enable Enterprise Search
xpack.apm.enabled: false
xpack.uptime.enabled: false
enterpriseSearch.enabled: true
enterpriseSearch.enabled: false

## Enable the Serverless Search plugin
xpack.serverless.search.enabled: true
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pageLoadAssetSize:
securitySolution: 66738
serverless: 16573
serverlessObservability: 30000
serverlessSearch: 25600
serverlessSearch: 26000
serverlessSecurity: 41807
sessionView: 77750
share: 71239
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ export const ControlEditor = ({

const controlGroup = useControlGroupContainer();
const editorConfig = controlGroup.select((state) => state.componentState.editorConfig);
const customFilterPredicate = controlGroup.select(
(state) => state.componentState.fieldFilterPredicate
);

const [defaultTitle, setDefaultTitle] = useState<string>();
const [currentTitle, setCurrentTitle] = useState(title ?? '');
Expand Down Expand Up @@ -200,7 +197,7 @@ export const ControlEditor = ({
<EuiFormRow label={ControlGroupStrings.manageControl.getFieldTitle()}>
<FieldPicker
filterPredicate={(field: DataViewField) => {
const customPredicate = customFilterPredicate ? customFilterPredicate(field) : true;
const customPredicate = controlGroup.fieldFilterPredicate?.(field) ?? true;
return Boolean(fieldRegistry?.[field.name]) && customPredicate;
}}
selectedFieldName={selectedField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ControlPanelState,
ControlsPanels,
CONTROL_GROUP_TYPE,
FieldFilterPredicate,
} from '../types';
import {
cachedChildEmbeddableOrder,
Expand Down Expand Up @@ -98,11 +99,14 @@ export class ControlGroupContainer extends Container<
public onFiltersPublished$: Subject<Filter[]>;
public onControlRemoved$: Subject<string>;

public fieldFilterPredicate: FieldFilterPredicate | undefined;

constructor(
reduxToolsPackage: ReduxToolsPackage,
initialInput: ControlGroupInput,
parent?: Container,
settings?: ControlGroupSettings
settings?: ControlGroupSettings,
fieldFilterPredicate?: FieldFilterPredicate
) {
super(
initialInput,
Expand Down Expand Up @@ -141,6 +145,8 @@ export class ControlGroupContainer extends Container<
this.setupSubscriptions();
this.initialized$.next(true);
});

this.fieldFilterPredicate = fieldFilterPredicate;
}

private setupSubscriptions = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import { Container, EmbeddableFactoryDefinition } from '@kbn/embeddable-plugin/p
import { lazyLoadReduxToolsPackage } from '@kbn/presentation-util-plugin/public';
import { EmbeddablePersistableStateService } from '@kbn/embeddable-plugin/common';

import { ControlGroupInput, ControlGroupSettings, CONTROL_GROUP_TYPE } from '../types';
import {
ControlGroupInput,
ControlGroupSettings,
CONTROL_GROUP_TYPE,
FieldFilterPredicate,
} from '../types';
import {
createControlGroupExtract,
createControlGroupInject,
Expand Down Expand Up @@ -52,10 +57,17 @@ export class ControlGroupContainerFactory implements EmbeddableFactoryDefinition
public create = async (
initialInput: ControlGroupInput,
parent?: Container,
settings?: ControlGroupSettings
settings?: ControlGroupSettings,
fieldFilterPredicate?: FieldFilterPredicate
) => {
const reduxEmbeddablePackage = await lazyLoadReduxToolsPackage();
const { ControlGroupContainer } = await import('./control_group_container');
return new ControlGroupContainer(reduxEmbeddablePackage, initialInput, parent, settings);
return new ControlGroupContainer(
reduxEmbeddablePackage,
initialInput,
parent,
settings,
fieldFilterPredicate
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('control group renderer', () => {
expect(mockControlGroupFactory.create).toHaveBeenCalledWith(
expect.objectContaining({ controlStyle: 'twoLine' }),
undefined,
undefined,
undefined
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const ControlGroupRenderer = forwardRef<AwaitingControlGroupAPI, ControlG
> & {
create: ControlGroupContainerFactory['create'];
};
const { initialInput, settings } =
const { initialInput, settings, fieldFilterPredicate } =
(await getCreationOptions?.(getDefaultControlGroupInput(), controlGroupInputBuilder)) ??
{};
const newControlGroup = (await factory?.create(
Expand All @@ -87,7 +87,8 @@ export const ControlGroupRenderer = forwardRef<AwaitingControlGroupAPI, ControlG
...initialInput,
},
undefined,
settings
settings,
fieldFilterPredicate
)) as ControlGroupContainer;

if (canceled) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/controls/public/control_group/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export type ControlGroupReduxState = ReduxEmbeddableState<
ControlGroupSettings
>;

export type FieldFilterPredicate = (f: DataViewField) => boolean;

export interface ControlGroupCreationOptions {
initialInput?: Partial<ControlGroupInput>;
settings?: ControlGroupSettings;
fieldFilterPredicate?: FieldFilterPredicate;
}

export interface ControlGroupSettings {
Expand All @@ -35,7 +38,6 @@ export interface ControlGroupSettings {
hideWidthSettings?: boolean;
hideAdditionalSettings?: boolean;
};
fieldFilterPredicate?: (field: DataViewField) => boolean;
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export const AgentDetailsJsonFlyout = memo<{ agent: Agent; onClose: () => void }
</p>
</EuiText>
<EuiSpacer />
<EuiCodeBlock language="json">{agentToJson}</EuiCodeBlock>
<EuiCodeBlock language="json" isCopyable>
{agentToJson}
</EuiCodeBlock>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
CONTROL_FRAMES,
CONTROL_FRAME_TITLE,
FILTER_GROUP_CHANGED_BANNER,
FILTER_GROUP_EDIT_CONTROL_PANEL_ITEMS,
FILTER_GROUP_SAVE_CHANGES_POPOVER,
OPTION_LIST_LABELS,
OPTION_LIST_VALUES,
OPTION_SELECTABLE,
FILTER_GROUP_CONTROL_ACTION_EDIT,
} from '../../screens/common/filter_group';
import { createRule } from '../../tasks/api_calls/rules';
import { cleanKibana } from '../../tasks/common';
Expand All @@ -37,6 +39,7 @@ import { navigateFromHeaderTo } from '../../tasks/security_header';
import { ALERTS, CASES } from '../../screens/security_header';
import {
addNewFilterGroupControlValues,
cancelFieldEditing,
deleteFilterGroupControl,
discardFilterGroupControls,
editFilterGroupControl,
Expand Down Expand Up @@ -280,6 +283,7 @@ describe('Detections : Page Filters', { testIsolation: false }, () => {

it('Custom filters from URLS are populated & changed banner is displayed', () => {
visitAlertsPageWithCustomFilters(customFilters);
waitForPageFilters();

assertFilterControlsWithFilterObject(customFilters);

Expand All @@ -288,22 +292,38 @@ describe('Detections : Page Filters', { testIsolation: false }, () => {

it('Changed banner should hide on saving changes', () => {
visitAlertsPageWithCustomFilters(customFilters);

waitForPageFilters();
cy.get(FILTER_GROUP_CHANGED_BANNER).should('be.visible');
saveFilterGroupControls();
cy.get(FILTER_GROUP_CHANGED_BANNER).should('not.exist');
});
it('Changed banner should hide on discarding changes', () => {
visitAlertsPageWithCustomFilters(customFilters);

waitForPageFilters();
cy.get(FILTER_GROUP_CHANGED_BANNER).should('be.visible');
discardFilterGroupControls();
cy.get(FILTER_GROUP_CHANGED_BANNER).should('not.exist');
});

it('Changed banner should hide on Reset', () => {
visitAlertsPageWithCustomFilters(customFilters);
waitForPageFilters();
resetFilters();
cy.get(FILTER_GROUP_CHANGED_BANNER).should('not.exist');
});

it('Number fields are not visible in field edit panel', () => {
const idx = 3;
const { FILTER_FIELD_TYPE, FIELD_TYPES } = FILTER_GROUP_EDIT_CONTROL_PANEL_ITEMS;
editFilterGroupControls();
cy.get(CONTROL_FRAME_TITLE).eq(idx).trigger('mouseover');
cy.get(FILTER_GROUP_CONTROL_ACTION_EDIT(idx)).trigger('click', { force: true });
cy.get(FILTER_FIELD_TYPE).should('be.visible').trigger('click');
cy.get(FIELD_TYPES.STRING).should('be.visible');
cy.get(FIELD_TYPES.BOOLEAN).should('be.visible');
cy.get(FIELD_TYPES.IP).should('be.visible');
cy.get(FIELD_TYPES.NUMBER).should('not.exist');
cancelFieldEditing();
discardFilterGroupControls();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { getDataTestSubjectSelector } from '../../helpers/common';

export const FILTER_GROUP_LOADING = '[data-test-subj="filter-group__loading"]';
export const FILTER_GROUP_ITEMS = '[data-test-subj="filter-group__items"]';
export const FILTER_GROUP_CLEAR = '[data-test-subj="filter-group__clear"]';
Expand Down Expand Up @@ -67,6 +69,14 @@ export const FILTER_GROUP_EDIT_CONTROL_PANEL_ITEMS = {
FIELD_PICKER: (fieldName: string) => `[data-test-subj="field-picker-select-${fieldName}"]`,
FIELD_LABEL: '[data-test-subj="control-editor-title-input"]',
SAVE: '[data-test-subj="control-editor-save"]',
CANCEL: getDataTestSubjectSelector('control-editor-cancel'),
FILTER_FIELD_TYPE: getDataTestSubjectSelector('toggleFieldFilterButton'),
FIELD_TYPES: {
STRING: getDataTestSubjectSelector('typeFilter-string'),
BOOLEAN: getDataTestSubjectSelector('typeFilter-boolean'),
IP: getDataTestSubjectSelector('typeFilter-ip'),
NUMBER: getDataTestSubjectSelector('typeFilter-number'),
},
};

export const FILTER_GROUP_CONTROL_ACTION_DELETE = (idx: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const editFilterGroupControls = () => {
cy.get(FILTER_GROUP_CONTEXT_EDIT_CONTROLS).trigger('click');
};

export const cancelFieldEditing = () => {
cy.get(FILTER_GROUP_EDIT_CONTROLS_PANEL).should('be.visible');
cy.get(FILTER_GROUP_EDIT_CONTROL_PANEL_ITEMS.CANCEL).should('be.visible').trigger('click');
cy.get(FILTER_GROUP_EDIT_CONTROLS_PANEL).should('not.exist');
};

export const saveFilterGroupControls = () => {
cy.get(FILTER_GROUP_SAVE_CHANGES).trigger('click');
cy.get(FILTER_GROUP_SAVE_CHANGES).should('not.exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import type { Subscription } from 'rxjs';
import styled from 'styled-components';
import { cloneDeep, debounce, isEqual } from 'lodash';
import type { ControlGroupCreationOptions } from '@kbn/controls-plugin/public/control_group/types';
import type {
ControlGroupCreationOptions,
FieldFilterPredicate,
} from '@kbn/controls-plugin/public/control_group/types';
import { useInitializeUrlParam } from '../../utils/global_query_string';
import { URL_PARAM_KEY } from '../../hooks/use_url_state';
import type { FilterGroupProps, FilterItemObj } from './types';
Expand Down Expand Up @@ -298,6 +301,8 @@ const FilterGroupComponent = (props: PropsWithChildren<FilterGroupProps>) => {
return resultControls;
}, [initialUrlParam, initialControls, getStoredControlInput]);

const fieldFilterPredicate: FieldFilterPredicate = useCallback((f) => f.type !== 'number', []);

const getCreationOptions: ControlGroupRendererProps['getCreationOptions'] = useCallback(
async (
defaultInput: Partial<ControlGroupInput>,
Expand Down Expand Up @@ -334,7 +339,6 @@ const FilterGroupComponent = (props: PropsWithChildren<FilterGroupProps>) => {
return {
initialInput,
settings: {
fieldFilterPredicate: (f) => f.type !== 'number',
showAddButton: false,
staticDataViewId: dataViewId ?? '',
editorConfig: {
Expand All @@ -343,9 +347,18 @@ const FilterGroupComponent = (props: PropsWithChildren<FilterGroupProps>) => {
hideAdditionalSettings: true,
},
},
fieldFilterPredicate,
} as ControlGroupCreationOptions;
},
[dataViewId, timeRange, filters, chainingSystem, query, selectControlsWithPriority]
[
dataViewId,
timeRange,
filters,
chainingSystem,
query,
selectControlsWithPriority,
fieldFilterPredicate,
]
);

useFilterUpdatesToUrlSync({
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/serverless_search/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
],
"requiredPlugins": [
"serverless",
"enterpriseSearch",
"management"
],
"optionalPlugins": [],
Expand Down
Loading

0 comments on commit a5bc2cc

Please sign in to comment.