Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into kbn-107678-fail-sta…
Browse files Browse the repository at this point in the history
…rt-on-unknown-so-types
  • Loading branch information
pgayvallet committed Nov 15, 2021
2 parents ad4a3ff + 92f2312 commit ef6b335
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 152 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$dscOptionsPopoverWidth: $euiSizeL * 12;
$dscOptionsPopoverWidth: $euiSizeL * 14;

.dscOptionsPopover {
width: $dscOptionsPopoverWidth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { OptionsPopover } from './open_options_popover';
test('should display the correct text if datagrid is selected', () => {
const element = document.createElement('div');
const component = mountWithIntl(<OptionsPopover onClose={jest.fn()} anchorElement={element} />);
expect(findTestSubject(component, 'docTableMode').text()).toBe('New table');
expect(findTestSubject(component, 'docTableMode').text()).toBe('Document Explorer');
});

test('should display the correct text if legacy table is selected', () => {
Expand All @@ -45,5 +45,5 @@ test('should display the correct text if legacy table is selected', () => {
uiSettings.set('doc_table:legacy', true);
const element = document.createElement('div');
const component = mountWithIntl(<OptionsPopover onClose={jest.fn()} anchorElement={element} />);
expect(findTestSubject(component, 'docTableMode').text()).toBe('Classic table');
expect(findTestSubject(component, 'docTableMode').text()).toBe('Classic');
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export function OptionsPopover(props: OptionsPopoverProps) {
const isLegacy = uiSettings.get(DOC_TABLE_LEGACY);

const mode = isLegacy
? i18n.translate('discover.openOptionsPopover.legacyTableText', {
defaultMessage: 'Classic table',
? i18n.translate('discover.openOptionsPopover.classicDiscoverText', {
defaultMessage: 'Classic',
})
: i18n.translate('discover.openOptionsPopover.dataGridText', {
defaultMessage: 'New table',
: i18n.translate('discover.openOptionsPopover.documentExplorerText', {
defaultMessage: 'Document Explorer',
});

return (
Expand All @@ -60,8 +60,8 @@ export function OptionsPopover(props: OptionsPopoverProps) {
viewModeLabel: (
<strong>
<FormattedMessage
id="discover.topNav.optionsPopover.currentViewModeLabel"
defaultMessage="Current view mode"
id="discover.topNav.optionsPopover.discoverViewModeLabel"
defaultMessage="Discover view mode"
/>
</strong>
),
Expand All @@ -72,30 +72,42 @@ export function OptionsPopover(props: OptionsPopoverProps) {
</EuiText>
<EuiSpacer size="s" />
<EuiText color="subdued" size="s">
<FormattedMessage
id="discover.topNav.openOptionsPopover.description"
defaultMessage="Great news! Discover has better ways to sort data, drag and drop columns, and compare documents. Toggle 'Use classic table' in Advanced Settings to get started."
/>
{isLegacy ? (
<FormattedMessage
id="discover.topNav.openOptionsPopover.documentExplorerDisabledHint"
defaultMessage="Did you know Discover has a new Document Explorer with better data sorting, resizable columns,
and a full screen view? You can change the view mode in Advanced Settings."
/>
) : (
<FormattedMessage
id="discover.topNav.openOptionsPopover.documentExplorerEnabledHint"
defaultMessage="You can switch back to the classic Discover view in Advanced Settings."
/>
)}
</EuiText>
<EuiSpacer />
<EuiButton
iconType="tableDensityNormal"
fullWidth
href={addBasePath(`/app/management/kibana/settings?query=${DOC_TABLE_LEGACY}`)}
>
{i18n.translate('discover.openOptionsPopover.goToAdvancedSettings', {
defaultMessage: 'Get started',
})}
</EuiButton>
{isLegacy && (
<>
<EuiSpacer />
<EuiButton
iconType="tableDensityNormal"
fullWidth
href={addBasePath(`/app/management/kibana/settings?query=${DOC_TABLE_LEGACY}`)}
>
{i18n.translate('discover.openOptionsPopover.tryDocumentExplorer', {
defaultMessage: 'Try Document Explorer',
})}
</EuiButton>
</>
)}
<EuiHorizontalRule margin="s" />
<EuiTextAlign textAlign="center">
<EuiButtonEmpty
iconType="gear"
size="s"
href={addBasePath(`/app/management/kibana/settings?query=category:(discover)`)}
>
{i18n.translate('discover.openOptionsPopover.gotToAllSettings', {
defaultMessage: 'All Discover options',
{i18n.translate('discover.openOptionsPopover.gotToSettings', {
defaultMessage: 'View Discover settings',
})}
</EuiButtonEmpty>
</EuiTextAlign>
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/discover/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ export const getUiSettings: () => Record<string, UiSettingsParams> = () => ({
schema: schema.arrayOf(schema.string()),
},
[DOC_TABLE_LEGACY]: {
name: i18n.translate('discover.advancedSettings.docTableVersionName', {
defaultMessage: 'Use classic table',
name: i18n.translate('discover.advancedSettings.disableDocumentExplorer', {
defaultMessage: 'Document Explorer or classic view',
}),
value: true,
description: i18n.translate('discover.advancedSettings.docTableVersionDescription', {
description: i18n.translate('discover.advancedSettings.disableDocumentExplorerDescription', {
defaultMessage:
'Discover uses a new table layout that includes better data sorting, drag-and-drop columns, and a full screen view. ' +
'Turn on this option to use the classic table. Turn off to use the new table. ',
'To use the new Document Explorer instead of the classic view, turn off this option. ' +
'The Document Explorer offers better data sorting, resizable columns, and a full screen view.',
}),
category: ['discover'],
schema: schema.boolean(),
Expand Down
23 changes: 16 additions & 7 deletions test/functional/apps/visualize/_timelion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await monacoEditor.typeCodeEditorValue('.es(index=', 'timelionCodeEditor');
// wait for index patterns will be loaded
await common.sleep(500);
const suggestions = await timelion.getSuggestionItemsText();
expect(suggestions[0].includes('log')).to.eql(true);
// other suggestions might be shown for a short amount of time - retry until metric suggestions show up
await retry.try(async () => {
const suggestions = await timelion.getSuggestionItemsText();
expect(suggestions[0].includes('log')).to.eql(true);
});
});

it('should show field suggestions for timefield argument when index pattern set', async () => {
Expand All @@ -275,9 +278,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
'.es(index=logstash-*, timefield=',
'timelionCodeEditor'
);
const suggestions = await timelion.getSuggestionItemsText();
expect(suggestions.length).to.eql(4);
expect(suggestions[0].includes('@timestamp')).to.eql(true);
// other suggestions might be shown for a short amount of time - retry until metric suggestions show up
await retry.try(async () => {
const suggestions = await timelion.getSuggestionItemsText();
expect(suggestions.length).to.eql(4);
expect(suggestions[0].includes('@timestamp')).to.eql(true);
});
});

it('should show field suggestions for split argument when index pattern set', async () => {
Expand All @@ -288,9 +294,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
);
// wait for split fields to load
await common.sleep(300);
const suggestions = await timelion.getSuggestionItemsText();
// other suggestions might be shown for a short amount of time - retry until metric suggestions show up
await retry.try(async () => {
const suggestions = await timelion.getSuggestionItemsText();

expect(suggestions[0].includes('@message.raw')).to.eql(true);
expect(suggestions[0].includes('@message.raw')).to.eql(true);
});
});

it('should show field suggestions for metric argument when index pattern set', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@

import React, { FC, Fragment, useEffect, useMemo, useRef } from 'react';
import { debounce } from 'lodash';
import { EuiCallOut, EuiFieldText, EuiForm, EuiFormRow, EuiSpacer, EuiSwitch } from '@elastic/eui';
import {
EuiCallOut,
EuiFieldText,
EuiForm,
EuiFormRow,
EuiSpacer,
EuiSwitch,
EuiText,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';

import { useMlKibana } from '../../../../../contexts/kibana';
import { CodeEditor } from '../../../../../../../../../../src/plugins/kibana_react/public';
import { useNotifications } from '../../../../../contexts/kibana';
import { ml } from '../../../../../services/ml_api_service';
Expand All @@ -36,11 +45,22 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = (prop

const forceInput = useRef<HTMLInputElement | null>(null);
const { toasts } = useNotifications();
const {
services: {
application: { capabilities },
},
} = useMlKibana();

const onChange = (str: string) => {
setAdvancedEditorRawString(str);
};

const canCreateDataView = useMemo(
() =>
capabilities.savedObjectsManagement.edit === true || capabilities.indexPatterns.save === true,
[capabilities]
);

const debouncedJobIdCheck = useMemo(
() =>
debounce(async () => {
Expand Down Expand Up @@ -200,18 +220,34 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = (prop
{!isJobCreated && (
<Fragment>
<EuiFormRow
isInvalid={createIndexPattern && destinationIndexPatternTitleExists}
error={
createIndexPattern &&
destinationIndexPatternTitleExists && [
i18n.translate('xpack.ml.dataframe.analytics.create.dataViewAlreadyExistsError', {
defaultMessage: 'A data view with this title already exists.',
}),
]
isInvalid={
(createIndexPattern && destinationIndexPatternTitleExists) ||
canCreateDataView === false
}
error={[
...(canCreateDataView === false
? [
<EuiText size="xs" color="warning">
{i18n.translate(
'xpack.ml.dataframe.analytics.create.dataViewPermissionWarning',
{
defaultMessage: 'You need permission to create data views.',
}
)}
</EuiText>,
]
: []),
...(createIndexPattern && destinationIndexPatternTitleExists
? [
i18n.translate('xpack.ml.dataframe.analytics.create.dataViewExistsError', {
defaultMessage: 'A data view with this title already exists.',
}),
]
: []),
]}
>
<EuiSwitch
disabled={isJobCreated}
disabled={canCreateDataView === false}
name="mlDataFrameAnalyticsCreateIndexPattern"
label={i18n.translate('xpack.ml.dataframe.analytics.create.createDataViewLabel', {
defaultMessage: 'Create data view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export const DetailsStepForm: FC<CreateAnalyticsStepProps> = ({
setCurrentStep,
}) => {
const {
services: { docLinks, notifications },
services: {
docLinks,
notifications,
application: { capabilities },
},
} = useMlKibana();
const createIndexLink = docLinks.links.apis.createIndex;
const { setFormState } = actions;
Expand Down Expand Up @@ -71,6 +75,11 @@ export const DetailsStepForm: FC<CreateAnalyticsStepProps> = ({
(cloneJob !== undefined && resultsField === DEFAULT_RESULTS_FIELD)
);

const canCreateDataView = useMemo(
() =>
capabilities.savedObjectsManagement.edit === true || capabilities.indexPatterns.save === true,
[capabilities]
);
const forceInput = useRef<HTMLInputElement | null>(null);

const isStepInvalid =
Expand Down Expand Up @@ -149,6 +158,12 @@ export const DetailsStepForm: FC<CreateAnalyticsStepProps> = ({
}
}, [destIndexSameAsId, jobId]);

useEffect(() => {
if (canCreateDataView === false) {
setFormState({ createIndexPattern: false });
}
}, [capabilities]);

return (
<Fragment>
<EuiFormRow
Expand Down Expand Up @@ -347,9 +362,20 @@ export const DetailsStepForm: FC<CreateAnalyticsStepProps> = ({
<EuiFormRow
fullWidth
isInvalid={
(createIndexPattern && destinationIndexPatternTitleExists) || !createIndexPattern
(createIndexPattern && destinationIndexPatternTitleExists) ||
createIndexPattern === false ||
canCreateDataView === false
}
error={[
...(canCreateDataView === false
? [
<EuiText size="xs" color="warning">
{i18n.translate('xpack.ml.dataframe.analytics.create.dataViewPermissionWarning', {
defaultMessage: 'You need permission to create data views.',
})}
</EuiText>,
]
: []),
...(createIndexPattern && destinationIndexPatternTitleExists
? [
i18n.translate('xpack.ml.dataframe.analytics.create.dataViewExistsError', {
Expand All @@ -373,7 +399,7 @@ export const DetailsStepForm: FC<CreateAnalyticsStepProps> = ({
]}
>
<EuiSwitch
disabled={isJobCreated}
disabled={isJobCreated === true || canCreateDataView === false}
name="mlDataFrameAnalyticsCreateIndexPattern"
label={i18n.translate('xpack.ml.dataframe.analytics.create.createDataViewLabel', {
defaultMessage: 'Create data view',
Expand Down
Loading

0 comments on commit ef6b335

Please sign in to comment.