Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jan 15, 2020
1 parent 7281471 commit 032b30c
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const PLUGIN = {
ID: 'painless_playground',
};

export const ROUTES = {
API_ROOT: '/api/painless_playground',
};

This file was deleted.

This file was deleted.

7 changes: 3 additions & 4 deletions x-pack/legacy/plugins/painless_playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { resolve } from 'path';
import { PLUGIN } from './common/constants';

import { registerLicenseChecker } from './server/lib/register_license_checker';
import { registerPainlessPlaygroundSimulateRoute } from './server/routes/api/register_painless_playground_simulate_route';
import { registerLicenseChecker } from './server/register_license_checker';
import { registerSimulateRoute } from './server/register_simulate_route';

export const painlessPlayground = (kibana: any) =>
new kibana.Plugin({
Expand All @@ -23,10 +23,9 @@ export const painlessPlayground = (kibana: any) =>
},
uiExports: {
devTools: [resolve(__dirname, 'public/register')],
home: [resolve(__dirname, 'public/register_feature')],
},
init: (server: any) => {
registerLicenseChecker(server);
registerPainlessPlaygroundSimulateRoute(server);
registerSimulateRoute(server);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { CodeEditor } from '../../../../../../src/plugins/kibana_react/public';

interface Props {
service: any;
executeCode: (payload: Record<string, unknown>) => Promise<any>;
}

interface State {
code: string;
request?: string;
response?: string;
responseObj: Record<string, any>;
responseObj: Record<string, any> | null;
}
export function PainlessPlayground(props: Props) {
const [state, setState] = useState<State>({
code: '',
request: '',
response: '',
responseObj: null,
});

const submit = async () => {
Expand All @@ -41,7 +42,7 @@ export function PainlessPlayground(props: Props) {
},
};
try {
const response = await props.service.simulate(request);
const response = await props.executeCode(request);
setState({
code: state.code,
request: JSON.stringify(request, null, 2),
Expand Down Expand Up @@ -112,7 +113,7 @@ export function PainlessPlayground(props: Props) {
<EuiFormRow
label={
<FormattedMessage
id="xpack.painlessPlayground.outputLabel"
id="xpack.painlessPlayground.responseLabel"
defaultMessage="Response"
/>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { ROUTES } from '../../common/constants';

export async function executeCode(http: any, payload: Record<string, any>) {
try {
return await http.post(`${ROUTES.API_ROOT}/simulate`, {
body: JSON.stringify(payload),
});
} catch (e) {
return e;
}
}
15 changes: 15 additions & 0 deletions x-pack/legacy/plugins/painless_playground/public/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ import { i18n } from '@kbn/i18n';
import { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
import { npSetup, npStart } from 'ui/new_platform';
import { registerPainless } from './register_painless';
import { FeatureCatalogueCategory } from '../../../../../src/plugins/home/public';

npSetup.plugins.home.featureCatalogue.register({
id: 'painless_playground',
title: i18n.translate('xpack.painlessPlayground.registryProviderTitle', {
defaultMessage: 'Painless Playground',
}),
description: i18n.translate('xpack.painlessPlayground.registryProviderDescription', {
defaultMessage: 'Simulate and debug painless code',
}),
icon: '',
path: '/app/kibana#/dev_tools/painless_playground',
showOnHomePage: false,
category: FeatureCatalogueCategory.ADMIN,
});

npSetup.plugins.dev_tools.register({
order: 7,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { I18nProvider } from '@kbn/i18n/react';
import { PainlessPlayground } from './components/painless_playground';
import { PainlessPlaygroundService } from './services/painless_playground_service';
import { createKibanaReactContext } from '../../../../../src/plugins/kibana_react/public';
import { executeCode } from './lib/execute_code';

export function renderApp(element: any, npStart: any) {
const { Provider: KibanaReactContextProvider } = createKibanaReactContext({
Expand All @@ -18,7 +18,7 @@ export function renderApp(element: any, npStart: any) {
render(
<KibanaReactContextProvider>
<I18nProvider>
<PainlessPlayground service={new PainlessPlaygroundService(npStart.core.http)} />
<PainlessPlayground executeCode={payload => executeCode(npStart.core.http, payload)} />
</I18nProvider>
</KibanaReactContextProvider>,
element
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import Boom from 'boom';
import { ServerFacade } from '../../../types';
import { PLUGIN } from '../../../common/constants';
import { PLUGIN } from '../../common/constants';
import { ServerFacade } from '../../../index_management';

export const licensePreRoutingFactory = (server: ServerFacade) => {
const xpackMainPlugin = server.plugins.xpack_main;
Expand Down
Loading

0 comments on commit 032b30c

Please sign in to comment.