Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into np/watcher/ou…
Browse files Browse the repository at this point in the history
…t-of-legacy

* 'master' of github.com:elastic/kibana:
  [Watcher] Add support for additional watch action statuses (elastic#55092)
  [ML] Fix entity controls update. (elastic#55524)
  [ML] Fixing ML's watcher integration (elastic#55439)
  [ML] Fixes permissions checks for data visualizer create job links (elastic#55431)
  [SearchProfiler] Move out of legacy (elastic#55331)

# Conflicts:
#	x-pack/plugins/watcher/server/models/action_status/action_status.js
  • Loading branch information
jloleysens committed Jan 22, 2020
2 parents 7f14e02 + 7b145bf commit 98fc0f8
Show file tree
Hide file tree
Showing 114 changed files with 581 additions and 571 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@
/x-pack/legacy/plugins/license_management/ @elastic/es-ui
/x-pack/legacy/plugins/remote_clusters/ @elastic/es-ui
/x-pack/legacy/plugins/rollup/ @elastic/es-ui
/x-pack/legacy/plugins/searchprofiler/ @elastic/es-ui
/x-pack/plugins/searchprofiler/ @elastic/es-ui
/x-pack/legacy/plugins/snapshot_restore/ @elastic/es-ui
/x-pack/plugins/watcher/ @elastic/es-ui
4 changes: 2 additions & 2 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"xpack.ml": "legacy/plugins/ml",
"xpack.monitoring": "legacy/plugins/monitoring",
"xpack.remoteClusters": "legacy/plugins/remote_clusters",
"xpack.reporting": [ "plugins/reporting", "legacy/plugins/reporting" ],
"xpack.reporting": ["plugins/reporting", "legacy/plugins/reporting"],
"xpack.rollupJobs": "legacy/plugins/rollup",
"xpack.searchProfiler": "legacy/plugins/searchprofiler",
"xpack.searchProfiler": "plugins/searchprofiler",
"xpack.security": ["legacy/plugins/security", "plugins/security"],
"xpack.server": "legacy/server",
"xpack.siem": "legacy/plugins/siem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { NavigationMenu } from '../../components/navigation_menu';
import { ML_JOB_FIELD_TYPES } from '../../../../common/constants/field_types';
import { SEARCH_QUERY_LANGUAGE } from '../../../../common/constants/search';
import { isFullLicense } from '../../license/check_license';
import { checkPermission } from '../../privilege/check_privilege';
import { mlNodesAvailable } from '../../ml_nodes_check/check_ml_nodes';
import { FullTimeRangeSelector } from '../../components/full_time_range_selector';
import { mlTimefilterRefresh$ } from '../../services/timefilter_refresh_service';
import { useKibanaContext, SavedSearchQuery } from '../../contexts/kibana';
Expand Down Expand Up @@ -130,9 +132,11 @@ export const Page: FC = () => {

const defaults = getDefaultPageState();

const [showActionsPanel] = useState(
isFullLicense() && currentIndexPattern.timeFieldName !== undefined
);
const showActionsPanel =
isFullLicense() &&
checkPermission('canCreateJob') &&
mlNodesAvailable() &&
currentIndexPattern.timeFieldName !== undefined;

const [searchString, setSearchString] = useState(defaults.searchString);
const [searchQuery, setSearchQuery] = useState(defaults.searchQuery);
Expand Down Expand Up @@ -613,7 +617,9 @@ export const Page: FC = () => {
)}
</EuiPageContentHeader>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ width: wizardPanelWidth }} />
{showActionsPanel === true && (
<EuiFlexItem grow={false} style={{ width: wizardPanelWidth }} />
)}
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiPageContentBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FormattedMessage, injectI18n } from '@kbn/i18n/react';

import { parseInterval } from '../../../../../../common/util/parse_interval';
import { ml } from '../../../../services/ml_api_service';
import { SelectSeverity } from '../../../../components/controls/select_severity/select_severity';
import { SelectSeverity } from './select_severity';
import { mlCreateWatchService } from './create_watch_service';
const STATUS = mlCreateWatchService.STATUS;

Expand Down Expand Up @@ -111,19 +111,6 @@ export const CreateWatch = injectI18n(

render() {
const { intl } = this.props;
const mlSelectSeverityService = {
state: {
set: (name, threshold) => {
this.onThresholdChange(threshold);
return {
changed: () => {},
};
},
get: () => {
return this.config.threshold;
},
},
};
const { status } = this.state;

if (status === null || status === STATUS.SAVING || status === STATUS.SAVE_FAILED) {
Expand Down Expand Up @@ -164,10 +151,7 @@ export const CreateWatch = injectI18n(
</label>
</div>
<div className="dropdown-group">
<SelectSeverity
id="selectSeverity"
mlSelectSeverityService={mlSelectSeverityService}
/>
<SelectSeverity onChange={this.onThresholdChange} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/*
* React component for rendering a select element with threshold levels.
* This is basically a copy of SelectSeverity in public/application/components/controls/select_severity
* but which stores its state internally rather than in the appState
*/
import React, { Fragment, FC, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { EuiHealth, EuiSpacer, EuiSuperSelect, EuiText } from '@elastic/eui';

import { getSeverityColor } from '../../../../../../common/util/anomaly_utils';

const warningLabel = i18n.translate('xpack.ml.controls.selectSeverity.warningLabel', {
defaultMessage: 'warning',
});
const minorLabel = i18n.translate('xpack.ml.controls.selectSeverity.minorLabel', {
defaultMessage: 'minor',
});
const majorLabel = i18n.translate('xpack.ml.controls.selectSeverity.majorLabel', {
defaultMessage: 'major',
});
const criticalLabel = i18n.translate('xpack.ml.controls.selectSeverity.criticalLabel', {
defaultMessage: 'critical',
});

const optionsMap = {
[warningLabel]: 0,
[minorLabel]: 25,
[majorLabel]: 50,
[criticalLabel]: 75,
};

interface TableSeverity {
val: number;
display: string;
color: string;
}

export const SEVERITY_OPTIONS: TableSeverity[] = [
{
val: 0,
display: warningLabel,
color: getSeverityColor(0),
},
{
val: 25,
display: minorLabel,
color: getSeverityColor(25),
},
{
val: 50,
display: majorLabel,
color: getSeverityColor(50),
},
{
val: 75,
display: criticalLabel,
color: getSeverityColor(75),
},
];

function optionValueToThreshold(value: number) {
// Get corresponding threshold object with required display and val properties from the specified value.
let threshold = SEVERITY_OPTIONS.find(opt => opt.val === value);

// Default to warning if supplied value doesn't map to one of the options.
if (threshold === undefined) {
threshold = SEVERITY_OPTIONS[0];
}

return threshold;
}

const TABLE_SEVERITY_DEFAULT = SEVERITY_OPTIONS[0];

const getSeverityOptions = () =>
SEVERITY_OPTIONS.map(({ color, display, val }) => ({
value: display,
inputDisplay: (
<Fragment>
<EuiHealth color={color} style={{ lineHeight: 'inherit' }}>
{display}
</EuiHealth>
</Fragment>
),
dropdownDisplay: (
<Fragment>
<EuiHealth color={color} style={{ lineHeight: 'inherit' }}>
{display}
</EuiHealth>
<EuiSpacer size="xs" />
<EuiText size="xs" color="subdued">
<p className="euiTextColor--subdued">
<FormattedMessage
id="xpack.ml.controls.selectSeverity.scoreDetailsDescription"
defaultMessage="score {value} and above"
values={{ value: val }}
/>
</p>
</EuiText>
</Fragment>
),
}));

interface Props {
onChange: (sev: TableSeverity) => void;
}

export const SelectSeverity: FC<Props> = ({ onChange }) => {
const [severity, setSeverity] = useState(TABLE_SEVERITY_DEFAULT);

const onSeverityChange = (valueDisplay: string) => {
const option = optionValueToThreshold(optionsMap[valueDisplay]);
setSeverity(option);
onChange(option);
};

return (
<EuiSuperSelect
hasDividers
options={getSeverityOptions()}
valueOfSelected={severity.display}
onChange={onSeverityChange}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export function http(options: any) {

fetch(url, payload)
.then(resp => {
resp.json().then(resp.ok === true ? resolve : reject);
resp
.json()
.then(resp.ok === true ? resolve : reject)
.catch(resp.ok === true ? resolve : reject);
})
.catch(resp => {
reject(resp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isEqual } from 'lodash';
import React, { Component } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -47,8 +48,8 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
};

componentDidUpdate(prevProps: EntityControlProps) {
const { entity, forceSelection, isLoading, options } = this.props;
const { selectedOptions } = this.state;
const { entity, forceSelection, isLoading, options: propOptions } = this.props;
const { options: stateOptions, selectedOptions } = this.state;

const { fieldValue } = entity;

Expand All @@ -68,11 +69,16 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
if (prevProps.isLoading === true && isLoading === false) {
this.setState({
isLoading: false,
options,
selectedOptions: selectedOptionsUpdate,
});
}

if (!isEqual(propOptions, stateOptions)) {
this.setState({
options: propOptions,
});
}

if (forceSelection && this.inputRef) {
this.inputRef.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ function getEntityControlOptions(fieldValues) {
return [];
}

fieldValues.sort();

return fieldValues.map(value => {
return { label: value };
});
Expand Down Expand Up @@ -163,7 +165,6 @@ export class TimeSeriesExplorer extends React.Component {
selectedDetectorIndex: PropTypes.number,
selectedEntities: PropTypes.object,
selectedForecastId: PropTypes.string,
setGlobalState: PropTypes.func.isRequired,
tableInterval: PropTypes.string,
tableSeverity: PropTypes.number,
zoom: PropTypes.object,
Expand Down
26 changes: 0 additions & 26 deletions x-pack/legacy/plugins/searchprofiler/README.md

This file was deleted.

47 changes: 5 additions & 42 deletions x-pack/legacy/plugins/searchprofiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
*/

import { resolve } from 'path';
import Boom from 'boom';

import { CoreSetup } from 'src/core/server';
import { Server } from 'src/legacy/server/kbn_server';
import { LegacySetup } from './server/np_ready/types';
import { plugin } from './server/np_ready';
// TODO:
// Until we can process SCSS in new platform, this part of Searchprofiler
// legacy must remain here.

export const searchprofiler = (kibana: any) => {
const publicSrc = resolve(__dirname, 'public');
Expand All @@ -22,43 +20,8 @@ export const searchprofiler = (kibana: any) => {
publicDir: publicSrc,

uiExports: {
// NP Ready
devTools: [`${publicSrc}/legacy`],
styleSheetPaths: `${publicSrc}/np_ready/application/index.scss`,
// Legacy
home: ['plugins/searchprofiler/register_feature'],
},
init(server: Server) {
const serverPlugin = plugin();
const thisPlugin = this;

const commonRouteConfig = {
pre: [
function forbidApiAccess() {
const licenseCheckResults = server.plugins.xpack_main.info
.feature(thisPlugin.id)
.getLicenseCheckResults();
if (licenseCheckResults.showAppLink && licenseCheckResults.enableAppLink) {
return null;
} else {
throw Boom.forbidden(licenseCheckResults.message);
}
},
],
};

const legacySetup: LegacySetup = {
route: (args: Parameters<typeof server.route>[0]) => server.route(args),
plugins: {
__LEGACY: {
thisPlugin,
xpackMain: server.plugins.xpack_main,
elasticsearch: server.plugins.elasticsearch,
commonRouteConfig,
},
},
};
serverPlugin.setup({} as CoreSetup, legacySetup);
styleSheetPaths: `${publicSrc}/index.scss`,
},
init() {},
});
};
Loading

0 comments on commit 98fc0f8

Please sign in to comment.