[ESUI] Move XJson Mode to src/plugins/es_ui_shared (#62758)

* Move XJson to x-pack/es_ui_shared

Also convert files to TS and clean up use of @ts-ignore

* Move console_lang to public

* Proper use of mocks

* Globally mock out .ace.worker.js modules

Having worker code exported in `public` of es_ui_shared poisoned
a lot of Jest tests with the need to mock out the ace worker.

Instead of adding mocks everywhere we handle the importing in
Jest by adding an entry to module mapper.

* Remove manual imports of mocks

* Delete es_ui_shared/public/mocks for now

* Put useXJson code in single place

* Import and instantiate xJsonMode

* Remove language mocks imports

Besides the fact that these paths are wrong these are no longer
needed because we mock at use Jest module mapper

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2020-04-10 12:58:18 +02:00 committed by GitHub
parent 93971dbfab
commit d662cb5f45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 193 additions and 246 deletions

View file

@ -62,6 +62,7 @@ export default {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/src/dev/jest/mocks/file_mock.js',
'\\.(css|less|scss)$': '<rootDir>/src/dev/jest/mocks/style_mock.js',
'\\.ace\\.worker.js$': '<rootDir>/src/dev/jest/mocks/ace_worker_module_mock.js',
},
setupFiles: [
'<rootDir>/src/dev/jest/setup/babel_polyfill.js',

View file

@ -17,4 +17,4 @@
* under the License.
*/
export { XJsonMode } from './x_json_mode';
module.exports = '';

View file

@ -20,7 +20,7 @@
import { EuiScreenReaderOnly } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect, useRef } from 'react';
import { expandLiteralStrings } from '../../../../../../../es_ui_shared/console_lang/lib';
import { expandLiteralStrings } from '../../../../../../../es_ui_shared/public';
import {
useEditorReadContext,
useRequestReadContext,

View file

@ -18,7 +18,7 @@
*/
import { extractDeprecationMessages } from '../../../lib/utils';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/console_lang/lib';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/public';
// @ts-ignore
import * as es from '../../../lib/es/es';
import { BaseResponseType } from '../../../types';

View file

@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../legacy_core_editor.test.mocks';
const $ = require('jquery');
import RowParser from '../../../../lib/row_parser';
import ace from 'brace';

View file

@ -18,7 +18,7 @@
*/
const ace = require('brace');
import { addXJsonToRules } from '../../../../../../es_ui_shared/console_lang';
import { addXJsonToRules } from '../../../../../../es_ui_shared/public';
export function addEOL(tokens, reg, nextIfEOL, normalNext) {
if (typeof reg === 'object') {

View file

@ -19,7 +19,7 @@
const ace = require('brace');
import 'brace/mode/json';
import { addXJsonToRules } from '../../../../../../es_ui_shared/console_lang';
import { addXJsonToRules } from '../../../../../../es_ui_shared/public';
const oop = ace.acequire('ace/lib/oop');
const JsonHighlightRules = ace.acequire('ace/mode/json_highlight_rules').JsonHighlightRules;

View file

@ -18,7 +18,7 @@
*/
import ace from 'brace';
import { ScriptHighlightRules } from '../../../../../../es_ui_shared/console_lang';
import { ScriptHighlightRules } from '../../../../../../es_ui_shared/public';
const oop = ace.acequire('ace/lib/oop');
const TextMode = ace.acequire('ace/mode/text').Mode;

View file

@ -22,7 +22,7 @@ import $ from 'jquery';
import _ from 'lodash';
import { create } from '../create';
import { collapseLiteralStrings } from '../../../../../../es_ui_shared/console_lang/lib';
import { collapseLiteralStrings } from '../../../../../../es_ui_shared/public';
const editorInput1 = require('./editor_input1.txt');
describe('Editor', () => {

View file

@ -19,7 +19,7 @@
import _ from 'lodash';
import RowParser from '../../../lib/row_parser';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/console_lang/lib';
import { collapseLiteralStrings } from '../../../../../es_ui_shared/public';
import * as utils from '../../../lib/utils';
// @ts-ignore

View file

@ -18,10 +18,7 @@
*/
import _ from 'lodash';
import {
expandLiteralStrings,
collapseLiteralStrings,
} from '../../../../es_ui_shared/console_lang/lib';
import { expandLiteralStrings, collapseLiteralStrings } from '../../../../es_ui_shared/public';
export function textFromRequest(request: any) {
let data = request.data;

View file

@ -24,4 +24,4 @@ export {
addXJsonToRules,
} from './lexer_rules';
export { XJsonMode, installXJsonMode } from './x_json';
export { installXJsonMode, XJsonMode } from './x_json';

View file

@ -17,13 +17,13 @@
* under the License.
*/
const ace = require('brace');
import ace from 'brace';
const oop = ace.acequire('ace/lib/oop');
const { TextHighlightRules } = ace.acequire('ace/mode/text_highlight_rules');
const painlessKeywords =
'def|int|long|byte|String|float|double|char|null|if|else|while|do|for|continue|break|new|try|catch|throw|this|instanceof|return|ctx';
export function ScriptHighlightRules() {
export function ScriptHighlightRules(this: any) {
this.name = 'ScriptHighlightRules';
this.$rules = {
start: [

View file

@ -22,14 +22,14 @@ import ace from 'brace';
import 'brace/mode/json';
import { ElasticsearchSqlHighlightRules } from './elasticsearch_sql_highlight_rules';
const { ScriptHighlightRules } = require('./script_highlight_rules');
import { ScriptHighlightRules } from './script_highlight_rules';
const { JsonHighlightRules } = ace.acequire('ace/mode/json_highlight_rules');
const oop = ace.acequire('ace/lib/oop');
const jsonRules = function(root) {
const jsonRules = function(root: any) {
root = root ? root : 'json';
const rules = {};
const rules: any = {};
const xJsonRules = [
{
token: [
@ -135,7 +135,7 @@ const jsonRules = function(root) {
merge: false,
push: true,
},
].concat(xJsonRules);
].concat(xJsonRules as any);
rules.string_literal = [
{
@ -151,7 +151,7 @@ const jsonRules = function(root) {
return rules;
};
export function XJsonHighlightRules() {
export function XJsonHighlightRules(this: any) {
this.$rules = {
...jsonRules('start'),
};
@ -175,7 +175,7 @@ export function XJsonHighlightRules() {
oop.inherits(XJsonHighlightRules, JsonHighlightRules);
export function addToRules(otherRules, embedUnder) {
export function addToRules(otherRules: any, embedUnder: any) {
otherRules.$rules = _.defaultsDeep(otherRules.$rules, jsonRules(embedUnder));
otherRules.embedRules(ScriptHighlightRules, 'script-', [
{

View file

@ -0,0 +1,19 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { installXJsonMode, XJsonMode } from './x_json';

View file

@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// @ts-ignore
import src from '!!raw-loader!./x_json.ace.worker.js';
export const workerModule = {
id: 'ace/mode/json_worker',
src,
};

View file

@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Satisfy TS's requirements that the module be declared per './index.ts'.
declare module '!!raw-loader!./worker.js' {
const content: string;
// eslint-disable-next-line import/no-default-export
export default content;
}

View file

@ -18,23 +18,50 @@
*/
import ace from 'brace';
import { XJsonHighlightRules } from '../index';
import { workerModule } from './worker';
const { WorkerClient } = ace.acequire('ace/worker/worker_client');
const oop = ace.acequire('ace/lib/oop');
const { Mode: JSONMode } = ace.acequire('ace/mode/json');
const { Tokenizer: AceTokenizer } = ace.acequire('ace/tokenizer');
const { MatchingBraceOutdent } = ace.acequire('ace/mode/matching_brace_outdent');
const { CstyleBehaviour } = ace.acequire('ace/mode/behaviour/cstyle');
const { FoldMode: CStyleFoldMode } = ace.acequire('ace/mode/folding/cstyle');
export function XJsonMode(this: any) {
const ruleset: any = new XJsonHighlightRules();
const XJsonMode: any = function XJsonMode(this: any) {
const ruleset: any = new (XJsonHighlightRules as any)();
ruleset.normalizeRules();
this.$tokenizer = new AceTokenizer(ruleset.getRules());
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
this.foldingRules = new CStyleFoldMode();
}
};
oop.inherits(XJsonMode, JSONMode);
// Then clobber `createWorker` method to install our worker source. Per ace's wiki: https://github.com/ajaxorg/ace/wiki/Syntax-validation
(XJsonMode.prototype as any).createWorker = function(session: ace.IEditSession) {
const xJsonWorker = new WorkerClient(['ace'], workerModule, 'JsonWorker');
xJsonWorker.attachToDocument(session.getDocument());
xJsonWorker.on('annotate', function(e: { data: any }) {
session.setAnnotations(e.data);
});
xJsonWorker.on('terminate', function() {
session.clearAnnotations();
});
return xJsonWorker;
};
export { XJsonMode };
export function installXJsonMode(editor: ace.Editor) {
const session = editor.getSession();
session.setMode(new XJsonMode());
}

View file

@ -26,4 +26,7 @@ export {
XJsonHighlightRules,
addXJsonToRules,
XJsonMode,
installXJsonMode,
} from './ace/modes';
export { expandLiteralStrings, collapseLiteralStrings } from './lib';

View file

@ -36,6 +36,17 @@ export { indices } from './indices';
export { useUIAceKeyboardMode } from './use_ui_ace_keyboard_mode';
export {
installXJsonMode,
XJsonMode,
ElasticsearchSqlHighlightRules,
addXJsonToRules,
ScriptHighlightRules,
XJsonHighlightRules,
collapseLiteralStrings,
expandLiteralStrings,
} from './console_lang';
/** dummy plugin, we just want esUiShared to have its own bundle */
export function plugin() {
return new (class EsUiSharedPlugin {

View file

@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { useXJsonMode } from './use_x_json';

View file

@ -17,16 +17,22 @@
* under the License.
*/
import { Editor } from 'brace';
import { useState } from 'react';
import { XJsonMode, collapseLiteralStrings, expandLiteralStrings } from '../../../public';
export declare const ElasticsearchSqlHighlightRules: FunctionConstructor;
export declare const ScriptHighlightRules: FunctionConstructor;
export declare const XJsonHighlightRules: FunctionConstructor;
const xJsonMode = new XJsonMode();
export declare const XJsonMode: FunctionConstructor;
export const useXJsonMode = (json: Record<string, any> | string | null) => {
const [xJson, setXJson] = useState(() =>
json === null
? ''
: expandLiteralStrings(typeof json === 'string' ? json : JSON.stringify(json, null, 2))
);
/**
* @param otherRules Another Ace ruleset
* @param embedUnder The state name under which the rules will be embedded. Defaults to "json".
*/
export declare const addXJsonToRules: (otherRules: any, embedUnder?: string) => void;
return {
xJson,
setXJson,
xJsonMode,
convertToJson: collapseLiteralStrings,
};
};

View file

@ -28,6 +28,7 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': fileMockPath,
'\\.module.(css|scss)$': `${kibanaDirectory}/src/dev/jest/mocks/css_module_mock.js`,
'\\.(css|less|scss)$': `${kibanaDirectory}/src/dev/jest/mocks/style_mock.js`,
'\\.ace\\.worker.js$': `${kibanaDirectory}/src/dev/jest/mocks/ace_worker_module_mock.js`,
'^test_utils/enzyme_helpers': `${xPackKibanaDirectory}/test_utils/enzyme_helpers.tsx`,
'^test_utils/find_test_subject': `${xPackKibanaDirectory}/test_utils/find_test_subject.ts`,
'^test_utils/stub_web_worker': `${xPackKibanaDirectory}/test_utils/stub_web_worker.ts`,

View file

@ -1,7 +0,0 @@
/*
* 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.
*/
export { installXJsonMode, XJsonMode } from './x_json';

View file

@ -1,7 +0,0 @@
/*
* 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.
*/
export { installXJsonMode, XJsonMode } from './x_json';

View file

@ -1,13 +0,0 @@
/*
* 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.
*/
// @ts-ignore
import src from '!!raw-loader!./worker.js';
export const workerModule = {
id: 'ace/mode/json_worker',
src,
};

View file

@ -1,12 +0,0 @@
/*
* 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.
*/
// Satisfy TS's requirements that the module be declared per './index.ts'.
declare module '!!raw-loader!./worker.js' {
const content: string;
// eslint-disable-next-line import/no-default-export
export default content;
}

View file

@ -1,34 +0,0 @@
/*
* 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.
*/
import ace from 'brace';
import { XJsonMode } from '../../../../../../../src/plugins/es_ui_shared/console_lang';
import { workerModule } from './worker';
const { WorkerClient } = ace.acequire('ace/worker/worker_client');
// Then clobber `createWorker` method to install our worker source. Per ace's wiki: https://github.com/ajaxorg/ace/wiki/Syntax-validation
(XJsonMode.prototype as any).createWorker = function(session: ace.IEditSession) {
const xJsonWorker = new WorkerClient(['ace'], workerModule, 'JsonWorker');
xJsonWorker.attachToDocument(session.getDocument());
xJsonWorker.on('annotate', function(e: { data: any }) {
session.setAnnotations(e.data);
});
xJsonWorker.on('terminate', function() {
session.clearAnnotations();
});
return xJsonWorker;
};
export { XJsonMode };
export function installXJsonMode(editor: ace.Editor) {
const session = editor.getSession();
session.setMode(new (XJsonMode as any)());
}

View file

@ -1,7 +0,0 @@
/*
* 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.
*/
export { XJsonMode, installXJsonMode } from './ace/modes';

View file

@ -1,9 +0,0 @@
/*
* 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.
*/
jest.mock('./ace/modes/x_json/worker', () => ({
workerModule: { id: 'ace/mode/json_worker', src: '' },
}));

View file

@ -5,4 +5,3 @@
*/
export { usePartialState } from './use_partial_state';
export { useXJsonMode, xJsonMode } from './use_x_json_mode';

View file

@ -1,26 +0,0 @@
/*
* 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.
*/
import { useState } from 'react';
import {
collapseLiteralStrings,
expandLiteralStrings,
XJsonMode,
} from '../../../../shared_imports';
// @ts-ignore
export const xJsonMode = new XJsonMode();
export const useXJsonMode = (json: string) => {
const [xJson, setXJson] = useState(expandLiteralStrings(json));
return {
xJson,
setXJson,
xJsonMode,
convertToJson: collapseLiteralStrings,
};
};

View file

@ -18,8 +18,11 @@ import {
import { i18n } from '@kbn/i18n';
import { XJsonMode } from '../../../../../../../shared_imports';
const xJsonMode = new XJsonMode();
import { CreateAnalyticsFormProps } from '../../hooks/use_create_analytics_form';
import { xJsonMode } from '../../../../../components/custom_hooks';
export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = ({ actions, state }) => {
const { setAdvancedEditorRawString, setFormState } = actions;

View file

@ -11,7 +11,7 @@ import numeral from '@elastic/numeral';
import { isEmpty } from 'lodash';
import { isValidIndexName } from '../../../../../../../common/util/es_utils';
import { collapseLiteralStrings } from '../../../../../../../../../../src/plugins/es_ui_shared/console_lang/lib/json_xjson_translation_tools';
import { collapseLiteralStrings } from '../../../../../../../../../../src/plugins/es_ui_shared/public';
import { Action, ACTION } from './actions';
import { getInitialState, getJobConfigFromFormState, State } from './state';

View file

@ -7,10 +7,9 @@
import React, { FC } from 'react';
import { EuiCodeEditor, EuiCodeEditorProps } from '@elastic/eui';
import { expandLiteralStrings } from '../../../../../../shared_imports';
import { xJsonMode } from '../../../../components/custom_hooks';
import { expandLiteralStrings, XJsonMode } from '../../../../../../shared_imports';
export const ML_EDITOR_MODE = { TEXT: 'text', JSON: 'json', XJSON: xJsonMode };
export const ML_EDITOR_MODE = { TEXT: 'text', JSON: 'json', XJSON: new XJsonMode() };
interface MlJobEditorProps {
value: string;

View file

@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
export { XJsonMode } from '../../../src/plugins/es_ui_shared/console_lang/ace/modes/x_json';
export {
XJsonMode,
collapseLiteralStrings,
expandLiteralStrings,
} from '../../../src/plugins/es_ui_shared/console_lang/lib';
} from '../../../src/plugins/es_ui_shared/public';

View file

@ -6,8 +6,6 @@
import 'brace';
import 'brace/mode/json';
import '../../../../es_ui_shared/console_lang/mocks';
import { registerTestBed } from '../../../../../test_utils';
import { Editor, Props } from '.';

View file

@ -5,7 +5,7 @@
*/
import ace from 'brace';
import { installXJsonMode } from '../../../../es_ui_shared/console_lang';
import { installXJsonMode } from '../../../../../../src/plugins/es_ui_shared/public';
export function initializeEditor({
el,

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { collapseLiteralStrings } from '../../../../../../src/plugins/es_ui_shared/console_lang/lib';
import { collapseLiteralStrings } from '../../../../../../src/plugins/es_ui_shared/public';
export function checkForParseErrors(json: string) {
const sanitizedJson = collapseLiteralStrings(json);

View file

@ -1,20 +0,0 @@
/*
* 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.
*/
import { useState } from 'react';
import { collapseLiteralStrings, expandLiteralStrings, XJsonMode } from '../../shared_imports';
export const xJsonMode = new XJsonMode();
export const useXJsonMode = (json: string) => {
const [xJson, setXJson] = useState(expandLiteralStrings(json));
return {
xJson,
setXJson,
xJsonMode,
convertToJson: collapseLiteralStrings,
};
};

View file

@ -33,11 +33,12 @@ import {
QueryStringInput,
} from '../../../../../../../../../src/plugins/data/public';
import { useXJsonMode } from '../../../../../../../../../src/plugins/es_ui_shared/static/ace_x_json/hooks';
import { PivotPreview } from '../../../../components/pivot_preview';
import { useDocumentationLinks } from '../../../../hooks/use_documentation_links';
import { SavedSearchQuery, SearchItems } from '../../../../hooks/use_search_items';
import { useXJsonMode, xJsonMode } from '../../../../hooks/use_x_json_mode';
import { useToastNotifications } from '../../../../app_dependencies';
import { TransformPivotConfig } from '../../../../common';
import { dictionaryToArray, Dictionary } from '../../../../../../common/types/common';
@ -432,6 +433,7 @@ export const StepDefineForm: FC<Props> = React.memo(({ overrides = {}, onChange,
convertToJson,
setXJson: setAdvancedEditorConfig,
xJson: advancedEditorConfig,
xJsonMode,
} = useXJsonMode(stringifiedPivotConfig);
useEffect(() => {

View file

@ -5,11 +5,11 @@
*/
export { createSavedSearchesLoader } from '../../../../src/plugins/discover/public';
export { XJsonMode } from '../../es_ui_shared/console_lang/ace/modes/x_json';
export {
XJsonMode,
collapseLiteralStrings,
expandLiteralStrings,
} from '../../../../src/plugins/es_ui_shared/console_lang/lib';
} from '../../../../src/plugins/es_ui_shared/public';
export {
UseRequestConfig,

View file

@ -17,6 +17,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { useXJsonMode } from '../../../../../../../src/plugins/es_ui_shared/static/ace_x_json/hooks';
import {
ActionTypeModel,
ActionConnectorFieldsProps,
@ -31,7 +32,6 @@ import {
getIndexOptions,
getIndexPatterns,
} from '../../../common/index_controls';
import { useXJsonMode } from '../../lib/use_x_json_mode';
import { AddMessageVariables } from '../add_message_variables';
export function getActionType(): ActionTypeModel {

View file

@ -1,25 +0,0 @@
/*
* 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.
*/
import { useState } from 'react';
import { XJsonMode } from '../../../../../../src/plugins/es_ui_shared/console_lang/ace/modes/x_json';
import {
collapseLiteralStrings,
expandLiteralStrings,
} from '../../../../../../src/plugins/es_ui_shared/console_lang/lib';
// @ts-ignore
export const xJsonMode = new XJsonMode();
export const useXJsonMode = (json: Record<string, any> | null) => {
const [xJson, setXJson] = useState(
json === null ? '' : expandLiteralStrings(JSON.stringify(json, null, 2))
);
return {
xJson,
setXJson,
xJsonMode,
convertToJson: collapseLiteralStrings,
};
};

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../es_ui_shared/console_lang/mocks';
import { act } from 'react-dom/test-utils';
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';

View file

@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../es_ui_shared/console_lang/mocks';
import React from 'react';
import { act } from 'react-dom/test-utils';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

View file

@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../es_ui_shared/console_lang/mocks';
import { act } from 'react-dom/test-utils';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

View file

@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../es_ui_shared/console_lang/mocks';
import { act } from 'react-dom/test-utils';
import * as fixtures from '../../test/fixtures';

View file

@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import '../../../es_ui_shared/console_lang/mocks';
import { act } from 'react-dom/test-utils';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';

View file

@ -23,14 +23,13 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { serializeJsonWatch } from '../../../../../../common/lib/serialization';
import { ErrableFormRow, SectionError, Error as ServerError } from '../../../../components';
import { useXJsonMode } from '../../../../shared_imports';
import { onWatchSave } from '../../watch_edit_actions';
import { WatchContext } from '../../watch_context';
import { goToWatchList } from '../../../../lib/navigation';
import { RequestFlyout } from '../request_flyout';
import { useAppContext } from '../../../../app_context';
import { useXJsonMode } from './use_x_json_mode';
export const JsonWatchEditForm = () => {
const {
links: { putWatchApiUrl },

View file

@ -40,7 +40,7 @@ import { JsonWatchEditSimulateResults } from './json_watch_edit_simulate_results
import { getTimeUnitLabel } from '../../../../lib/get_time_unit_label';
import { useAppContext } from '../../../../app_context';
import { useXJsonMode } from './use_x_json_mode';
import { useXJsonMode } from '../../../../shared_imports';
const actionModeOptions = Object.keys(ACTION_MODES).map(mode => ({
text: ACTION_MODES[mode],

View file

@ -1,24 +0,0 @@
/*
* 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.
*/
import { useState } from 'react';
import { XJsonMode } from '../../../../../../../es_ui_shared/console_lang';
import {
collapseLiteralStrings,
expandLiteralStrings,
} from '../../../../../../../../../src/plugins/es_ui_shared/console_lang/lib';
export const xJsonMode = new XJsonMode();
export const useXJsonMode = (json: string) => {
const [xJson, setXJson] = useState(expandLiteralStrings(json));
return {
xJson,
setXJson,
xJsonMode,
convertToJson: collapseLiteralStrings,
};
};

View file

@ -11,3 +11,5 @@ export {
sendRequest,
useRequest,
} from '../../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
export { useXJsonMode } from '../../../../../src/plugins/es_ui_shared/static/ace_x_json/hooks';