Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Always show unmapped fields #91735

Merged
merged 5 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,19 +675,10 @@ function discoverController($route, $scope, Promise) {
history.push('/');
};

const showUnmappedFieldsDefaultValue = $scope.useNewFieldsApi && !!$scope.opts.savedSearch.pre712;
let showUnmappedFields = showUnmappedFieldsDefaultValue;

const onChangeUnmappedFields = (value) => {
showUnmappedFields = value;
$scope.unmappedFieldsConfig.showUnmappedFields = value;
$scope.fetch();
};
const showUnmappedFields = $scope.useNewFieldsApi;

$scope.unmappedFieldsConfig = {
showUnmappedFieldsDefaultValue,
showUnmappedFields,
onChangeUnmappedFields,
};

$scope.updateDataSource = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,4 @@ describe('DiscoverFieldSearch', () => {
popover = component.find(EuiPopover);
expect(popover.prop('isOpen')).toBe(false);
});

test('unmapped fields', () => {
const onChangeUnmappedFields = jest.fn();
const componentProps = {
...defaultProps,
showUnmappedFields: true,
useNewFieldsApi: false,
onChangeUnmappedFields,
};
const component = mountComponent(componentProps);
const btn = findTestSubject(component, 'toggleFieldFilterButton');
btn.simulate('click');
const unmappedFieldsSwitch = findTestSubject(component, 'unmappedFieldsSwitch');
act(() => {
unmappedFieldsSwitch.simulate('click');
});
expect(onChangeUnmappedFields).toHaveBeenCalledWith(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
EuiOutsideClickDetector,
EuiFilterButton,
EuiSpacer,
EuiIcon,
EuiToolTip,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

Expand All @@ -37,7 +35,6 @@ export interface State {
aggregatable: string;
type: string;
missing: boolean;
unmappedFields: boolean;
[index: string]: string | boolean;
}

Expand All @@ -61,31 +58,13 @@ export interface Props {
* use new fields api
*/
useNewFieldsApi?: boolean;

/**
* callback funtion to change the value of unmapped fields switch
* @param value new value to set
*/
onChangeUnmappedFields?: (value: boolean) => void;

/**
* should unmapped fields switch be rendered
*/
showUnmappedFields?: boolean;
}

/**
* Component is Discover's side bar to search of available fields
* Additionally there's a button displayed that allows the user to show/hide more filter fields
*/
export function DiscoverFieldSearch({
onChange,
value,
types,
useNewFieldsApi,
showUnmappedFields,
onChangeUnmappedFields,
}: Props) {
export function DiscoverFieldSearch({ onChange, value, types, useNewFieldsApi }: Props) {
const searchPlaceholder = i18n.translate('discover.fieldChooser.searchPlaceHolder', {
defaultMessage: 'Search field names',
});
Expand All @@ -111,7 +90,6 @@ export function DiscoverFieldSearch({
aggregatable: 'any',
type: 'any',
missing: true,
unmappedFields: !!showUnmappedFields,
});

if (typeof value !== 'string') {
Expand Down Expand Up @@ -181,14 +159,6 @@ export function DiscoverFieldSearch({
handleValueChange('missing', missingValue);
};

const handleUnmappedFieldsChange = (e: EuiSwitchEvent) => {
const unmappedFieldsValue = e.target.checked;
handleValueChange('unmappedFields', unmappedFieldsValue);
if (onChangeUnmappedFields) {
onChangeUnmappedFields(unmappedFieldsValue);
}
};

const buttonContent = (
<EuiFilterButton
aria-label={filterBtnAriaLabel}
Expand Down Expand Up @@ -262,46 +232,19 @@ export function DiscoverFieldSearch({
};

const footer = () => {
if (!showUnmappedFields && useNewFieldsApi) {
if (useNewFieldsApi) {
return null;
}
return (
<EuiPopoverFooter>
{showUnmappedFields ? (
<EuiFlexGroup>
<EuiFlexItem component="span">
<EuiSwitch
label={i18n.translate('discover.fieldChooser.filter.showUnmappedFields', {
defaultMessage: 'Show unmapped fields',
})}
checked={values.unmappedFields}
onChange={handleUnmappedFieldsChange}
data-test-subj="unmappedFieldsSwitch"
/>
</EuiFlexItem>
<EuiFlexItem component="span" grow={false}>
<EuiToolTip
position="right"
content={i18n.translate('discover.fieldChooser.filter.unmappedFieldsWarning', {
defaultMessage:
'Unmapped fields will be deprecated and removed in a future release.',
})}
>
<EuiIcon type="alert" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
) : null}
{useNewFieldsApi ? null : (
<EuiSwitch
label={i18n.translate('discover.fieldChooser.filter.hideMissingFieldsLabel', {
defaultMessage: 'Hide missing fields',
})}
checked={values.missing}
onChange={handleMissingChange}
data-test-subj="missingSwitch"
/>
)}
<EuiSwitch
label={i18n.translate('discover.fieldChooser.filter.hideMissingFieldsLabel', {
defaultMessage: 'Hide missing fields',
})}
checked={values.missing}
onChange={handleMissingChange}
data-test-subj="missingSwitch"
/>
</EuiPopoverFooter>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ export function DiscoverSidebar({
value={fieldFilter.name}
types={fieldTypes}
useNewFieldsApi={useNewFieldsApi}
onChangeUnmappedFields={unmappedFieldsConfig?.onChangeUnmappedFields}
showUnmappedFields={unmappedFieldsConfig?.showUnmappedFieldsDefaultValue}
/>
</form>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ describe('discover responsive sidebar', function () {
});
it('renders sidebar with unmapped fields config', function () {
const unmappedFieldsConfig = {
onChangeUnmappedFields: jest.fn(),
showUnmappedFields: false,
showUnmappedFieldsDefaultValue: false,
};
const componentProps = { ...props, unmappedFieldsConfig };
const component = mountWithIntl(<DiscoverSidebarResponsive {...componentProps} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,13 @@ export interface DiscoverSidebarResponsiveProps {
useNewFieldsApi?: boolean;

/**
* an object containing properties for proper handling of unmapped fields in the UI
* an object containing properties for proper handling of unmapped fields
*/
unmappedFieldsConfig?: {
/**
* callback function to change the value of `showUnmappedFields` flag
* @param value new value to set
*/
onChangeUnmappedFields: (value: boolean) => void;
/**
* determines whether to display unmapped fields
* configurable through the switch in the UI
*/
showUnmappedFields: boolean;
/**
* determines if we should display an option to toggle showUnmappedFields value in the first place
* this value is not configurable through the UI
*/
showUnmappedFieldsDefaultValue: boolean;
};
}

Expand Down
13 changes: 1 addition & 12 deletions src/plugins/discover/public/application/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,12 @@ export interface DiscoverProps {
*/
timeRange?: { from: string; to: string };
/**
* An object containing properties for proper handling of unmapped fields in the UI
* An object containing properties for unmapped fields behavior
*/
unmappedFieldsConfig?: {
/**
* determines whether to display unmapped fields
* configurable through the switch in the UI
*/
showUnmappedFields: boolean;
/**
* determines if we should display an option to toggle showUnmappedFields value in the first place
* this value is not configurable through the UI
*/
showUnmappedFieldsDefaultValue: boolean;
/**
* callback function to change the value of `showUnmappedFields` flag
* @param value new value to set
*/
onChangeUnmappedFields: (value: boolean) => void;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class SearchEmbeddable
const useNewFieldsApi = !this.services.uiSettings.get(SEARCH_FIELDS_FROM_SOURCE, false);
if (!this.searchScope) return;

const { searchSource, pre712 } = this.savedSearch;
const { searchSource } = this.savedSearch;

// Abort any in-progress requests
if (this.abortController) this.abortController.abort();
Expand All @@ -308,10 +308,7 @@ export class SearchEmbeddable
);
if (useNewFieldsApi) {
searchSource.removeField('fieldsFromSource');
const fields: Record<string, string> = { field: '*' };
if (pre712) {
fields.include_unmapped = 'true';
}
const fields: Record<string, string> = { field: '*', include_unmapped: 'true' };
searchSource.setField('fields', [fields]);
} else {
searchSource.removeField('fields');
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/discover/public/saved_searches/_saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
grid: 'object',
sort: 'keyword',
version: 'integer',
pre712: 'boolean',
};
// Order these fields to the top, the rest are alphabetical
public static fieldOrder = ['title', 'description'];
Expand All @@ -42,7 +41,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
grid: 'object',
sort: 'keyword',
version: 'integer',
pre712: 'boolean',
},
searchSource: true,
defaults: {
Expand All @@ -52,7 +50,6 @@ export function createSavedSearchClass(savedObjects: SavedObjectsStart) {
hits: 0,
sort: [],
version: 1,
pre712: false,
},
});
this.showInRecentlyAccessed = true;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/discover/public/saved_searches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface SavedSearch {
save: (saveOptions: SavedObjectSaveOpts) => Promise<string>;
lastSavedTitle?: string;
copyOnSave?: boolean;
pre712?: boolean;
hideChart?: boolean;
}
export interface SavedSearchLoader {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/discover/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const searchSavedObjectType: SavedObjectsType = {
title: { type: 'text' },
grid: { type: 'object', enabled: false },
version: { type: 'integer' },
pre712: { type: 'boolean' },
},
},
migrations: searchMigrations as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,41 +350,4 @@ Object {
testMigrateMatchAllQuery(migrationFn);
});
});

describe('7.12.0', () => {
const migrationFn = searchMigrations['7.12.0'];

describe('migrateExistingSavedSearch', () => {
it('should add a new flag to existing saved searches', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {},
},
},
savedObjectMigrationContext
);
const migratedPre712Flag = migratedDoc.attributes.pre712;

expect(migratedPre712Flag).toEqual(true);
});

it('should not modify a flag if it already exists', () => {
const migratedDoc = migrationFn(
{
type: 'search',
attributes: {
kibanaSavedObjectMeta: {},
pre712: false,
},
},
savedObjectMigrationContext
);
const migratedPre712Flag = migratedDoc.attributes.pre712;

expect(migratedPre712Flag).toEqual(false);
});
});
});
});
19 changes: 0 additions & 19 deletions src/plugins/discover/server/saved_objects/search_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,9 @@ const migrateSearchSortToNestedArray: SavedObjectMigrationFn<any, any> = (doc) =
};
};

const migrateExistingSavedSearch: SavedObjectMigrationFn<any, any> = (doc) => {
if (!doc.attributes) {
return doc;
}
const pre712 = doc.attributes.pre712;
// pre712 already has a value
if (pre712 !== undefined) {
return doc;
}
return {
...doc,
attributes: {
...doc.attributes,
pre712: true,
},
};
};

export const searchMigrations = {
'6.7.2': flow(migrateMatchAllQuery),
'7.0.0': flow(setNewReferences),
'7.4.0': flow(migrateSearchSortToNestedArray),
'7.9.3': flow(migrateMatchAllQuery),
'7.12.0': flow(migrateExistingSavedSearch),
};
Loading