Skip to content

Commit

Permalink
Merge branch 'main' into docker/ubi9
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Jul 7, 2022
2 parents 6d9eaba + 8655730 commit 3fe3c31
Show file tree
Hide file tree
Showing 104 changed files with 1,981 additions and 949 deletions.
2 changes: 1 addition & 1 deletion docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ system for the {kib} UI notification center. Set to `false` to disable the
newsfeed system. *Default: `true`*

`node.roles`::
Indicates which roles to configure the {kib} process with, which will effectively
experimental[] Indicates which roles to configure the {kib} process with, which will effectively
run {kib} in different modes. Valid options are `background_tasks` and `ui`,
or `*` to select all roles. *Default: `*`*

Expand Down
5 changes: 5 additions & 0 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export const discoverServiceMock = {
http: {
basePath: '/',
},
dataViewEditor: {
userPermissions: {
editDataView: () => true,
},
},
dataViewFieldEditor: {
openEditor: jest.fn(),
userPermissions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
anchorStatus={fetchedState.anchorStatus.value}
predecessorsStatus={fetchedState.predecessorsStatus.value}
successorsStatus={fetchedState.successorsStatus.value}
onFieldEdited={fetchAllRows}
/>
</EuiPageContent>
</EuiPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ContextAppContentProps {
isLegacy: boolean;
setAppState: (newState: Partial<AppState>) => void;
addFilter: DocViewFilterFn;
onFieldEdited: () => void;
}

const controlColumnIds = ['openDetails'];
Expand Down Expand Up @@ -72,6 +73,7 @@ export function ContextAppContent({
isLegacy,
setAppState,
addFilter,
onFieldEdited,
}: ContextAppContentProps) {
const { uiSettings: config } = useDiscoverServices();

Expand Down Expand Up @@ -160,6 +162,7 @@ export function ContextAppContent({
onAddColumn={onAddColumn}
onRemoveColumn={onRemoveColumn}
onSetColumns={onSetColumns}
onFieldEdited={onFieldEdited}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function mountComponent(fetchStatus: FetchStatus, hits: EsHitRecord[]) {
state: { columns: [] },
stateContainer: { setAppState: () => {} } as unknown as GetStateReturn,
navigateTo: jest.fn(),
onFieldEdited: jest.fn(),
};

return mountWithIntl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function DiscoverDocumentsComponent({
setExpandedDoc,
state,
stateContainer,
onFieldEdited,
}: {
documents$: DataDocuments$;
expandedDoc?: DataTableRecord;
Expand All @@ -60,6 +61,7 @@ function DiscoverDocumentsComponent({
setExpandedDoc: (doc?: DataTableRecord) => void;
state: AppState;
stateContainer: GetStateReturn;
onFieldEdited: () => void;
}) {
const { capabilities, indexPatterns, uiSettings } = useDiscoverServices();
const useNewFieldsApi = useMemo(() => !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE), [uiSettings]);
Expand Down Expand Up @@ -188,6 +190,7 @@ function DiscoverDocumentsComponent({
useNewFieldsApi={useNewFieldsApi}
rowHeightState={state.rowHeight}
onUpdateRowHeight={onUpdateRowHeight}
onFieldEdited={onFieldEdited}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function DiscoverLayout({
[filterManager, indexPattern, indexPatterns, trackUiMetric, capabilities]
);

const onEditRuntimeField = useCallback(() => {
const onFieldEdited = useCallback(() => {
savedSearchRefetch$.next('reset');
}, [savedSearchRefetch$]);

Expand Down Expand Up @@ -239,7 +239,7 @@ export function DiscoverLayout({
updateQuery={onUpdateQuery}
resetSavedSearch={resetSavedSearch}
onChangeIndexPattern={onChangeIndexPattern}
onEditRuntimeField={onEditRuntimeField}
onFieldEdited={onFieldEdited}
/>
<EuiPageBody className="dscPageBody" aria-describedby="savedSearchTitle">
<SavedSearchURLConflictCallout
Expand All @@ -262,7 +262,7 @@ export function DiscoverLayout({
isClosed={isSidebarClosed}
trackUiMetric={trackUiMetric}
useNewFieldsApi={useNewFieldsApi}
onEditRuntimeField={onEditRuntimeField}
onFieldEdited={onFieldEdited}
viewMode={viewMode}
onDataViewCreated={onDataViewCreated}
availableFields$={savedSearchData$.availableFields$}
Expand Down Expand Up @@ -346,6 +346,7 @@ export function DiscoverLayout({
setExpandedDoc={setExpandedDoc}
state={state}
stateContainer={stateContainer}
onFieldEdited={onFieldEdited}
/>
) : (
<FieldStatisticsTableMemoized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { UiCounterMetricType } from '@kbn/analytics';
import classNames from 'classnames';
import { FieldButton, FieldIcon } from '@kbn/react-field';
import type { DataViewField, DataView } from '@kbn/data-views-plugin/public';
import { getFieldCapabilities } from '../../../../utils/get_field_capabilities';
import { getTypeForFieldIcon } from '../../../../utils/get_type_for_field_icon';
import { DiscoverFieldDetails } from './discover_field_details';
import { FieldDetails } from './types';
Expand Down Expand Up @@ -317,10 +318,9 @@ function DiscoverFieldComponent({
);
}

const isRuntimeField = Boolean(indexPattern.getFieldByName(field.name)?.runtimeField);
const isUnknownField = field.type === 'unknown' || field.type === 'unknown_selected';
const canEditField = onEditField && (!isUnknownField || isRuntimeField);
const canDeleteField = onDeleteField && isRuntimeField;
const { canEdit, canDelete } = getFieldCapabilities(indexPattern, field);
const canEditField = onEditField && canEdit;
const canDeleteField = onDeleteField && canDelete;
const popoverTitle = (
<EuiPopoverTitle style={{ textTransform: 'none' }} className="eui-textBreakWord">
<EuiFlexGroup responsive={false} gutterSize="s">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function getCompProps(): DiscoverSidebarProps {
trackUiMetric: jest.fn(),
fieldFilter: getDefaultFieldFilter(),
setFieldFilter: jest.fn(),
onEditRuntimeField: jest.fn(),
onFieldEdited: jest.fn(),
editField: jest.fn(),
viewMode: VIEW_MODE.DOCUMENT_LEVEL,
createNewDataView: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function DiscoverSidebarComponent({
setFieldFilter,
trackUiMetric,
useNewFieldsApi = false,
onEditRuntimeField,
onFieldEdited,
onChangeIndexPattern,
setFieldEditorRef,
closeFlyout,
Expand Down Expand Up @@ -271,7 +271,7 @@ export function DiscoverSidebarComponent({
},
fieldName,
onDelete: async () => {
onEditRuntimeField();
onFieldEdited();
},
});
if (setFieldEditorRef) {
Expand All @@ -287,7 +287,7 @@ export function DiscoverSidebarComponent({
editField,
setFieldEditorRef,
closeFlyout,
onEditRuntimeField,
onFieldEdited,
dataViewFieldEditor,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getCompProps(): DiscoverSidebarResponsiveProps {
selectedIndexPattern: indexPattern,
state: {},
trackUiMetric: jest.fn(),
onEditRuntimeField: jest.fn(),
onFieldEdited: jest.fn(),
viewMode: VIEW_MODE.DOCUMENT_LEVEL,
onDataViewCreated: jest.fn(),
useNewFieldsApi: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface DiscoverSidebarResponsiveProps {
/**
* callback to execute on edit runtime field
*/
onEditRuntimeField: () => void;
onFieldEdited: () => void;
/**
* callback to execute on create dataview
*/
Expand All @@ -115,7 +115,7 @@ export interface DiscoverSidebarResponsiveProps {
*/
export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps) {
const services = useDiscoverServices();
const { selectedIndexPattern, onEditRuntimeField, onDataViewCreated } = props;
const { selectedIndexPattern, onFieldEdited, onDataViewCreated } = props;
const [fieldFilter, setFieldFilter] = useState(getDefaultFieldFilter());
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
/**
Expand Down Expand Up @@ -218,7 +218,7 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
},
fieldName,
onSave: async () => {
onEditRuntimeField();
onFieldEdited();
},
});
if (setFieldEditorRef) {
Expand All @@ -235,7 +235,7 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
dataViewFieldEditor,
selectedIndexPattern,
setFieldEditorRef,
onEditRuntimeField,
onFieldEdited,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getProps(savePermissions = true): DiscoverTopNavProps {
onOpenInspector: jest.fn(),
searchSource: {} as ISearchSource,
resetSavedSearch: () => {},
onEditRuntimeField: jest.fn(),
onFieldEdited: jest.fn(),
onChangeIndexPattern: jest.fn(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type DiscoverTopNavProps = Pick<
stateContainer: GetStateReturn;
resetSavedSearch: () => void;
onChangeIndexPattern: (indexPattern: string) => void;
onEditRuntimeField: () => void;
onFieldEdited: () => void;
};

export const DiscoverTopNav = ({
Expand All @@ -41,7 +41,7 @@ export const DiscoverTopNav = ({
savedSearch,
resetSavedSearch,
onChangeIndexPattern,
onEditRuntimeField,
onFieldEdited,
}: DiscoverTopNavProps) => {
const history = useHistory();
const showDatePicker = useMemo(
Expand Down Expand Up @@ -93,13 +93,13 @@ export const DiscoverTopNav = ({
},
fieldName,
onSave: async () => {
onEditRuntimeField();
onFieldEdited();
},
});
}
}
: undefined,
[canEditDataView, indexPattern?.id, data.dataViews, dataViewFieldEditor, onEditRuntimeField]
[canEditDataView, indexPattern?.id, data.dataViews, dataViewFieldEditor, onFieldEdited]
);

const addField = useMemo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { EuiListGroupItem, EuiListGroupItemProps } from '@elastic/eui';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import React from 'react';
import { buildDataViewMock } from '../../__mocks__/index_pattern';
import { discoverServiceMock } from '../../__mocks__/services';
import { buildEditFieldButton } from './build_edit_field_button';

const dataView = buildDataViewMock({
name: 'test-index-view',
fields: [
{
name: '_source',
type: '_source',
},
{
name: 'unknown_field',
type: 'unknown',
},
{
name: 'unknown_selected_field',
type: 'unknown',
},
{
name: 'bytes',
type: 'number',
},
{
name: 'runtime_field',
type: 'unknown',
runtimeField: {
type: 'unknown',
script: {
source: "emit('hello world')",
},
},
},
] as DataView['fields'],
});

describe('buildEditFieldButton', () => {
it('should return null if the field is not editable', () => {
const field = dataView.getFieldByName('unknown_field') as DataViewField;
const button = buildEditFieldButton({
services: discoverServiceMock,
dataView,
field,
editField: jest.fn(),
});
expect(button).toBeNull();
});

it('should return null if the data view is not editable', () => {
jest
.spyOn(discoverServiceMock.dataViewEditor.userPermissions, 'editDataView')
.mockReturnValueOnce(false);
const field = dataView.getFieldByName('bytes') as DataViewField;
const button = buildEditFieldButton({
services: discoverServiceMock,
dataView,
field,
editField: jest.fn(),
});
expect(button).toBeNull();
});

it('should return null if passed the _source field', () => {
const field = dataView.getFieldByName('_source') as DataViewField;
const button = buildEditFieldButton({
services: discoverServiceMock,
dataView,
field,
editField: jest.fn(),
});
expect(button).toBeNull();
});

it('should return EuiListGroupItemProps if the field and data view are editable', () => {
const field = dataView.getFieldByName('bytes') as DataViewField;
const button = buildEditFieldButton({
services: discoverServiceMock,
dataView,
field,
editField: jest.fn(),
});
expect(button).not.toBeNull();
expect(button).toMatchInlineSnapshot(`
Object {
"data-test-subj": "gridEditFieldButton",
"iconProps": Object {
"size": "m",
},
"iconType": "pencil",
"label": <FormattedMessage
defaultMessage="Edit data view field"
id="discover.grid.editFieldButton"
values={Object {}}
/>,
"onClick": [Function],
"size": "xs",
}
`);
});

it('should call editField when onClick is triggered', () => {
const field = dataView.getFieldByName('bytes') as DataViewField;
const editField = jest.fn();
const buttonProps = buildEditFieldButton({
services: discoverServiceMock,
dataView,
field,
editField,
}) as EuiListGroupItemProps;
const listItem = mountWithIntl(<EuiListGroupItem {...buttonProps} />);
listItem.find('button').simulate('click');
expect(editField).toHaveBeenCalledTimes(1);
expect(editField).toHaveBeenCalledWith('bytes');
});
});
Loading

0 comments on commit 3fe3c31

Please sign in to comment.