Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painless Playground PoC #54578

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fba34eb
Initial commit
kertal Jan 13, 2020
4cb4e5e
Migrate feature registration to NP
kertal Jan 13, 2020
c6e6712
Simplify code
kertal Jan 13, 2020
27fd28e
Add syntax highlighting
kertal Jan 14, 2020
7281471
Improve error response from server
kertal Jan 14, 2020
032b30c
Simplify code
kertal Jan 15, 2020
78d510c
Add Tabs to output
kertal Jan 15, 2020
a348fce
Add context API
kertal Jan 15, 2020
7055abe
Redesign
kertal Jan 15, 2020
eba55b3
Redesign
kertal Jan 16, 2020
b8a2064
Small Adaptions
kertal Jan 16, 2020
743d60d
Code improvements
kertal Jan 16, 2020
c1fd087
Code improvements
kertal Jan 16, 2020
f92dbaa
Change text
kertal Jan 16, 2020
9fa6a27
Fix translations
kertal Jan 16, 2020
02b37ef
Improve code
kertal Jan 16, 2020
987445f
Added feature flag
jloleysens Jan 17, 2020
4640b4d
A number of UI tweaks and updates
jloleysens Jan 17, 2020
6a4e8ca
Merge feedback PR by jloysenes
kertal Jan 20, 2020
c052211
Merge branch 'master' into kertal-pr-2020-01-13-painless-playground
elasticmachine Jan 21, 2020
39ee9e6
Fix types
kertal Jan 22, 2020
56a74a9
Split up components, restructure
kertal Jan 23, 2020
0554d13
Replace newline in results
kertal Jan 23, 2020
5a48070
Fix i18n
kertal Jan 23, 2020
6b270fb
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-01…
kertal Jan 23, 2020
7af0845
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-01…
kertal Jan 29, 2020
98f01f0
Improve issues found while preparing the demo
kertal Jan 30, 2020
8318b8c
Merge branch 'master' into kertal-pr-2020-01-13-painless-playground
elasticmachine Feb 6, 2020
4f7c9e2
Change dev_tools to devTools to accommodate change to plugin name.
cjcenizal Feb 6, 2020
7785ccd
Convert to 2-panel layout. Move Context tab into right panel. Use Eui…
cjcenizal Feb 7, 2020
27e5cac
Live-update output as the user enters input for a faster iteration lo…
cjcenizal Feb 8, 2020
fb3dc4b
Move response into a tab in the request flyout.
cjcenizal Feb 8, 2020
f9eb8c3
Remove unnecessary 'Test' button. Surface loading/success/error state…
cjcenizal Feb 8, 2020
8b09b7e
Add beta label to feature name in home registry and DevTools tab.
cjcenizal Feb 8, 2020
32a55b2
Refine Context tab form components and help text. Add doc links.
cjcenizal Feb 8, 2020
f9b53c4
Extract out parameters tab. Refactor output pane.
cjcenizal Feb 8, 2020
5191995
Add Help menu with links to docs and a button for resetting the script.
cjcenizal Feb 9, 2020
b7b12df
Improve parameters help text.
cjcenizal Feb 9, 2020
3165960
Make bottom bar smaller.
cjcenizal Feb 10, 2020
15e5064
Merge pull request #5 from cjcenizal/painless-playground-ui-suggestions
kertal Feb 13, 2020
fc41e51
Merge branch 'master' into kertal-pr-2020-01-13-painless-playground
cjcenizal Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface Props {
value: string;

/** Function invoked when text in editor is changed */
onChange: (value: string) => void;
onChange?: (value: string) => void;

/**
* Options for the Monaco Code Editor
Expand Down
2 changes: 2 additions & 0 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ml } from './legacy/plugins/ml';
import { tilemap } from './legacy/plugins/tilemap';
import { watcher } from './legacy/plugins/watcher';
import { grokdebugger } from './legacy/plugins/grokdebugger';
import { painlessPlayground } from './legacy/plugins/painless_playground';
import { dashboardMode } from './legacy/plugins/dashboard_mode';
import { logstash } from './legacy/plugins/logstash';
import { beats } from './legacy/plugins/beats_management';
Expand Down Expand Up @@ -56,6 +57,7 @@ module.exports = function(kibana) {
tilemap(kibana),
watcher(kibana),
grokdebugger(kibana),
painlessPlayground(kibana),
dashboardMode(kibana),
logstash(kibana),
beats(kibana),
Expand Down
13 changes: 13 additions & 0 deletions x-pack/legacy/plugins/painless_playground/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 const PLUGIN = {
ID: 'painless_playground',
};

export const ROUTES = {
API_ROOT: '/api/painless_playground',
};
31 changes: 31 additions & 0 deletions x-pack/legacy/plugins/painless_playground/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 { resolve } from 'path';
import { PLUGIN } from './common/constants';

import { registerLicenseChecker } from './server/register_license_checker';
import { registerExecuteRoute } from './server/register_execute_route';

export const painlessPlayground = (kibana: any) =>
new kibana.Plugin({
id: PLUGIN.ID,
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
configPrefix: 'xpack.painless_playground',
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
uiExports: {
devTools: [resolve(__dirname, 'public/register')],
},
init: (server: any) => {
registerLicenseChecker(server);
registerExecuteRoute(server);
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const painlessContextOptions = [
{
value: 'painless_test',
text: i18n.translate('tileMap.tooltipFormatter.latitudeLabel', {
defaultMessage: 'Default - Execute as it is',
}),
},
{
value: 'filter',
text: i18n.translate('tileMap.tooltipFormatter.latitudeLabel', {
defaultMessage: 'Filter - Execute like inside a filter query',
}),
},
{
value: 'score',
text: i18n.translate('tileMap.tooltipFormatter.latitudeLabel', {
defaultMessage: 'Score - Execute like inside a script query',
}),
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 { Request } from './types';

export function parseJSON(text: string) {
try {
return JSON.parse(text);
} catch (e) {
return {};
}
}

export function buildRequestPayload(
code: string,
context: string,
contextSetup: Record<string, string>
) {
const request: Request = {
script: {
source: code,
},
};
if (contextSetup.params) {
request.script.params = parseJSON(contextSetup?.params);
}
if (context === 'filter' || context === 'score') {
request.context = context;
request.context_setup = {
index: contextSetup.index,
document: parseJSON(contextSetup.doc),
};
return request;
}

return request;
}

export function getFromLocalStorage(key: string, defaultValue: any = '', parse = false) {
const value = localStorage.getItem(key);
if (value && parse) {
try {
return JSON.parse(value);
} catch (e) {
return defaultValue;
}
} else if (value) {
return value;
} else {
return defaultValue;
}
}

export function formatJson(json: any): string {
try {
return JSON.stringify(json, null, 2);
} catch (e) {
return `Invalid JSON ${String(json)}`;
}
}
Loading