Skip to content

Commit

Permalink
Merge branch 'main' into 154841-remove-legacy-field-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta authored Apr 21, 2023
2 parents 9385108 + 376c48a commit e6d09ae
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ const setEvaluationResults = (response: Array<Record<string, Evaluation>>) => {
jest.requireMock('./lib/evaluate_rule').evaluateRule.mockImplementation(() => response);
};

describe('The metric threshold alert type', () => {
// FAILING: https://github.com/elastic/kibana/issues/155534
describe.skip('The metric threshold alert type', () => {
describe('querying the entire infrastructure', () => {
afterAll(() => clearInstances());
const instanceID = '*';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ type TestSubjects =
| 'stepTwo.submitButton'
| 'stepTwo.title'
| 'submitButton'
| 'codeEditor'
| 'title';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n';
import { merge } from 'lodash';
import { LocationDescriptorObject } from 'history';

import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { HttpSetup } from '@kbn/core/public';
import { coreMock, scopedHistoryMock } from '@kbn/core/public/mocks';
import { setUiMetricService, httpService } from '../../../public/application/services/http';
Expand Down Expand Up @@ -50,15 +51,21 @@ export const services = {

setUiMetricService(services.uiMetricService);

const core = coreMock.createStart();

const appDependencies = {
core: coreMock.createStart(),
core,
services,
config: {
slm_ui: { enabled: true },
},
plugins: {},
};

const kibanaContextDependencies = {
uiSettings: core.uiSettings,
};

export const setupEnvironment = () => {
breadcrumbService.setup(() => undefined);
textService.setup(i18n);
Expand Down Expand Up @@ -88,11 +95,13 @@ export const WithAppDependencies =
<AuthorizationContext.Provider
value={createAuthorizationContextValue(privileges as Privileges)}
>
<AppContextProvider value={merge(appDependencies, overrides) as any}>
<GlobalFlyoutProvider>
<Comp {...props} />
</GlobalFlyoutProvider>
</AppContextProvider>
<KibanaContextProvider services={kibanaContextDependencies}>
<AppContextProvider value={merge(appDependencies, overrides) as any}>
<GlobalFlyoutProvider>
<Comp {...props} />
</GlobalFlyoutProvider>
</AppContextProvider>
</KibanaContextProvider>
</AuthorizationContext.Provider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import React from 'react';
import { act } from 'react-dom/test-utils';

import { setupEnvironment, pageHelpers, nextTick, TestBed, getRandomString } from './helpers';
Expand All @@ -16,6 +17,23 @@ import { REPOSITORY_EDIT, REPOSITORY_NAME } from './helpers/constant';
const { setup } = pageHelpers.repositoryEdit;
const { setup: setupRepositoryAdd } = pageHelpers.repositoryAdd;

jest.mock('@kbn/kibana-react-plugin/public', () => {
const original = jest.requireActual('@kbn/kibana-react-plugin/public');
return {
...original,
// Mocking CodeEditor, which uses React Monaco under the hood
CodeEditor: (props: any) => (
<input
data-test-subj={props['data-test-subj'] || 'mockCodeEditor'}
data-currentvalue={props.value}
onChange={(e: any) => {
props.onChange(e.jsonContent);
}}
/>
),
};
});

describe('<RepositoryEdit />', () => {
let testBed: TestBed<RepositoryEditTestSubjects>;
let testBedRepositoryAdd: TestBed<RepositoryAddTestSubjects>;
Expand Down Expand Up @@ -211,8 +229,8 @@ describe('<RepositoryEdit />', () => {
);
expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly);

const codeEditor = testBed.component.find('EuiCodeEditor').at(1);
expect(JSON.parse(codeEditor.props().value as string)).toEqual({
const codeEditorValue = testBed.find('codeEditor').props()['data-currentvalue'];
expect(JSON.parse(codeEditorValue)).toEqual({
loadDefault: true,
conf1: 'foo',
conf2: 'bar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { createContext, useContext } from 'react';
import { i18n } from '@kbn/i18n';
import { Observable } from 'rxjs';

import { CoreStart, ScopedHistory, CoreTheme } from '@kbn/core/public';
import { CoreStart, ScopedHistory, CoreTheme, IUiSettingsClient } from '@kbn/core/public';
import { ClientConfigType } from '../types';
import { HttpService, UiMetricService } from './services';

Expand All @@ -18,6 +18,7 @@ const AppContext = createContext<AppDependencies | undefined>(undefined);
export interface AppDependencies {
core: CoreStart;
services: {
uiSettings: IUiSettingsClient;
httpService: HttpService;
uiMetricService: UiMetricService;
i18n: typeof i18n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
EuiTitle,
} from '@elastic/eui';

import { CodeEditor } from '@kbn/kibana-react-plugin/public';
import { HDFSRepository, Repository, SourceRepository } from '../../../../../common/types';
import { EuiCodeEditor } from '../../../../shared_imports';
import { RepositorySettingsValidation } from '../../../services/validation';
import { ChunkSizeField, MaxSnapshotsField, MaxRestoreField } from './common';

Expand Down Expand Up @@ -347,21 +347,16 @@ export const HDFSSettings: React.FunctionComponent<Props> = ({
/>
}
>
<EuiCodeEditor
mode="json"
theme="textmate"
width="100%"
<CodeEditor
languageId="json"
value={additionalConf}
setOptions={{
showLineNumbers: false,
data-test-subj="codeEditor"
height={250}
options={{
lineNumbers: 'off',
tabSize: 2,
maxLines: Infinity,
}}
editorProps={{
$blockScrolling: Infinity,
automaticLayout: true,
}}
showGutter={false}
minLines={6}
aria-label={i18n.translate(
'xpack.snapshotRestore.repositoryForm.typeHDFS.configurationAriaLabel',
{
Expand Down Expand Up @@ -391,7 +386,6 @@ export const HDFSSettings: React.FunctionComponent<Props> = ({
setIsConfInvalid(true);
}
}}
data-test-subj="codeEditor"
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
EuiLink,
EuiIcon,
EuiToolTip,
EuiCodeBlock,
} from '@elastic/eui';
import { serializeRestoreSettings } from '../../../../../common/lib';
import { EuiCodeEditor } from '../../../../shared_imports';
import { useServices } from '../../../app_context';
import { StepProps } from '.';
import { CollapsibleIndicesList } from '../../collapsible_lists';
Expand Down Expand Up @@ -285,18 +285,17 @@ export const RestoreSnapshotStepReview: React.FunctionComponent<StepProps> = ({
const renderJsonTab = () => (
<Fragment>
<EuiSpacer size="m" />
<EuiCodeEditor
mode="json"
theme="textmate"
isReadOnly
setOptions={{ maxLines: Infinity }}
value={JSON.stringify(serializedRestoreSettings, null, 2)}
editorProps={{ $blockScrolling: Infinity }}
<EuiCodeBlock
paddingSize="m"
language="json"
isCopyable
aria-label={i18n.translate(
'xpack.snapshotRestore.restoreForm.stepReview.jsonTab.jsonAriaLabel',
{ defaultMessage: 'Restore settings to be executed' }
)}
/>
>
{JSON.stringify(serializedRestoreSettings, null, 2)}
</EuiCodeBlock>
</Fragment>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
EuiLink,
EuiCallOut,
} from '@elastic/eui';
import { CodeEditor } from '@kbn/kibana-react-plugin/public';
import { RestoreSettings } from '../../../../../common/types';
import { EuiCodeEditor } from '../../../../shared_imports';
import { REMOVE_INDEX_SETTINGS_SUGGESTIONS } from '../../../constants';
import { useCore, useServices } from '../../../app_context';
import { StepProps } from '.';
Expand Down Expand Up @@ -190,22 +190,15 @@ export const RestoreSnapshotStepSettings: React.FunctionComponent<StepProps> = (
/>
}
>
<EuiCodeEditor
mode="json"
theme="textmate"
width="100%"
value={indexSettings}
setOptions={{
showLineNumbers: false,
<CodeEditor
languageId="json"
value={indexSettings!}
height={250}
options={{
lineNumbers: 'off',
tabSize: 2,
maxLines: Infinity,
automaticLayout: true,
}}
editorProps={{
$blockScrolling: Infinity,
}}
showGutter={false}
minLines={6}
maxLines={15}
aria-label={i18n.translate(
'xpack.snapshotRestore.restoreForm.stepSettings.indexSettingsAriaLabel',
{ defaultMessage: 'Index settings to modify' }
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/snapshot_restore/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Router } from 'react-router-dom';
import { ScopedHistory } from '@kbn/core/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';

import { App } from './app';
import { AppProviders } from './app_providers';
Expand All @@ -26,9 +27,11 @@ const AppWithRouter = ({ history }: AppWithRouterProps) => (

export const renderApp = (elem: Element, dependencies: AppDependencies) => {
render(
<AppProviders appDependencies={dependencies}>
<AppWithRouter history={dependencies.services.history} />
</AppProviders>,
<KibanaContextProvider services={{ uiSettings: dependencies.services.uiSettings }}>
<AppProviders appDependencies={dependencies}>
<AppWithRouter history={dependencies.services.history} />
</AppProviders>
</KibanaContextProvider>,
elem
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function mountManagementSection(
core,
config,
services: {
uiSettings: coreSetup.uiSettings,
httpService,
uiMetricService: services.uiMetricService,
i18n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
EuiText,
EuiHorizontalRule,
EuiSpacer,
EuiCodeBlock,
} from '@elastic/eui';

import { reactRouterNavigate } from '@kbn/kibana-react-plugin/public';
import { SlmPolicy } from '../../../../../../../common/types';
import { EuiCodeEditor } from '../../../../../../shared_imports';
import { FormattedDateTime } from '../../../../../components';
import { linkToSnapshot } from '../../../../../services/navigation';
import { useServices } from '../../../../../app_context';
Expand Down Expand Up @@ -148,31 +148,20 @@ export const TabHistory: React.FunctionComponent<Props> = ({ policy }) => {
</EuiDescriptionListTitle>
<EuiSpacer size="s" />
<EuiDescriptionListDescription className="eui-textBreakWord" data-test-subj="value">
<EuiCodeEditor
mode="json"
theme="textmate"
width="100%"
isReadOnly
value={JSON.stringify(details, null, 2)}
setOptions={{
showLineNumbers: false,
tabSize: 2,
}}
editorProps={{
$blockScrolling: Infinity,
}}
minLines={6}
maxLines={12}
wrapEnabled={true}
showGutter={false}
<EuiCodeBlock
paddingSize="m"
language="json"
isCopyable
aria-label={i18n.translate(
'xpack.snapshotRestore.policyDetails.lastFailure.detailsAriaLabel',
{
defaultMessage: `Last failure details for policy '{name}'`,
values: { name },
}
)}
/>
>
{JSON.stringify(details, null, 2)}
</EuiCodeBlock>
</EuiDescriptionListDescription>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
* 2.0.
*/

import 'react-ace';
import 'brace/theme/textmate';
import React, { Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiSpacer, EuiTitle } from '@elastic/eui';
import { EuiCodeBlock, EuiSpacer, EuiTitle } from '@elastic/eui';

import { Repository } from '../../../../../../../common/types';
import { EuiCodeEditor } from '../../../../../../shared_imports';

interface Props {
repository: Repository;
Expand All @@ -35,22 +32,10 @@ export const DefaultDetails: React.FunctionComponent<Props> = ({

<EuiSpacer size="s" />

<EuiCodeEditor
mode="json"
theme="textmate"
width="100%"
isReadOnly
value={JSON.stringify(settings, null, 2)}
setOptions={{
showLineNumbers: false,
tabSize: 2,
maxLines: Infinity,
}}
editorProps={{
$blockScrolling: Infinity,
}}
showGutter={false}
minLines={6}
<EuiCodeBlock
paddingSize="m"
language="json"
isCopyable
aria-label={i18n.translate(
'xpack.snapshotRestore.repositoryDetails.genericSettingsDescription',
{
Expand All @@ -60,7 +45,9 @@ export const DefaultDetails: React.FunctionComponent<Props> = ({
},
}
)}
/>
>
{JSON.stringify(settings, null, 2)}
</EuiCodeBlock>
</Fragment>
);
};
1 change: 0 additions & 1 deletion x-pack/plugins/snapshot_restore/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export {
useAuthorizationContext,
useRequest,
WithPrivileges,
EuiCodeEditor,
AuthorizationContext,
GlobalFlyout,
} from '@kbn/es-ui-shared-plugin/public';
Expand Down
Loading

0 comments on commit e6d09ae

Please sign in to comment.