Skip to content

Commit

Permalink
Expressions np (#47810)
Browse files Browse the repository at this point in the history
* refactor: πŸ’‘ generalize service getters and setters in expressio

* feat: 🎸 create NP-ready plugin for expressions

* refactor: πŸ’‘ flatten expressions plugin and remove service

* chore: πŸ€– re-export legacy expressions service dir for Lens

* refactor: πŸ’‘ don't import renderer registry statically

* test: πŸ’ mock expressions service renderers registry in Mocha

* refactor: πŸ’‘ clean-up NP expressions pugin

* refactor: πŸ’‘ move Expression fonts to NP

* refactor: πŸ’‘ register Interpreter entities explicitly

* refactor: πŸ’‘ move clog Expression function to NP

* refactor: πŸ’‘ move font function and style types to NP

* refactor: πŸ’‘ remove ui/chrome from kibana_context function

* feat: 🎸 add ability to consume start core from setup life-cycle

* refactor: πŸ’‘ move kibana_context function to NP

* feat: 🎸 improve naming and delete import of missing function

* refactor: πŸ’‘ register expression clog and font fn in NP

* chore: πŸ€– set AppArch as GitHub folder owners

* refactor: πŸ’‘ move Expression "kibana" function to NP

* refactor: πŸ’‘ move range function to visualizations plugin

* feat: 🎸 move visDimensions to visualizations plugin

* chore: πŸ€– delete unused files

* refactor: πŸ’‘ move expression type registration to NP

* refactor: πŸ’‘ move createHandlers() function to NP

* feat: 🎸 move Expression executor to NP

* refactor: πŸ’‘ re-implement function registry

* refactor: πŸ’‘ convert expression type to class

* fix: πŸ› correct TypeScript errors

* feat: 🎸 convert Expressions type registry to class

* feat: 🎸 convert render function registry to class

* fix: πŸ› fix TypeScript errors

* fix: πŸ› fix translations after refactor

* refactor: πŸ’‘ move Expression types to NP

* test: πŸ’ remove unused test

* fix: πŸ› fix Lens import after merge with master

* fix: πŸ› fix TypeScript errors

* refactor: πŸ’‘ update expression types

* test: πŸ’ fix renderer test
  • Loading branch information
streamich authored Oct 30, 2019
1 parent e665574 commit a38223d
Show file tree
Hide file tree
Showing 98 changed files with 1,676 additions and 1,337 deletions.
7 changes: 6 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

# App Architecture
/src/plugins/data/ @elastic/kibana-app-arch
/src/plugins/kibana_utils/ @elastic/kibana-app-arch
/src/plugins/embeddable/ @elastic/kibana-app-arch
/src/plugins/expressions/ @elastic/kibana-app-arch
/src/plugins/kibana_react/ @elastic/kibana-app-arch
/src/plugins/kibana_utils/ @elastic/kibana-app-arch
/src/plugins/navigation/ @elastic/kibana-app-arch
/src/plugins/ui_actions/ @elastic/kibana-app-arch
/src/plugins/visualizations/ @elastic/kibana-app-arch
/x-pack/plugins/advanced_ui_actions/ @elastic/kibana-app-arch

# APM
/x-pack/legacy/plugins/apm/ @elastic/apm-ui
Expand Down
2 changes: 2 additions & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"common.ui": "src/legacy/ui",
"data": ["src/legacy/core_plugins/data", "src/plugins/data"],
"expressions": "src/legacy/core_plugins/expressions",
"expressions_np": "src/plugins/expressions",
"kibana_react": "src/legacy/core_plugins/kibana_react",
"navigation": "src/legacy/core_plugins/navigation",
"server": "src/legacy/server",
Expand All @@ -29,6 +30,7 @@
"kbnESQuery": "packages/kbn-es-query",
"inspector": "src/plugins/inspector",
"kibana-react": "src/plugins/kibana_react",
"visualizations": "src/plugins/visualizations",
"telemetry": "src/legacy/core_plugins/telemetry",
"esUi": "src/plugins/es_ui_shared",
"uiActions": "src/plugins/ui_actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ExpressionDataHandler } from './execute';
import { fromExpression } from '@kbn/interpreter/common';
import { IInterpreterRenderHandlers } from './types';
import { Observable } from 'rxjs';
import { ExpressionAST } from '../../../../../../plugins/expressions/common';
import { ExpressionAST } from '../../../../../../plugins/expressions/public';

const element: HTMLElement = null as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const createExpressionsSetupMock = (): ExpressionsSetup => {
types: {
register: () => {},
} as any,
getExecutor: () => ({
interpreter: {
interpretAst: () => {},
},
}),
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

/* eslint-disable */
import { npSetup } from 'ui/new_platform';
import { ExpressionsSetupContract } from '../../../../../../plugins/expressions/public/expressions/expressions_service';
/* eslint-enable */

import { ExpressionsSetup } from '../../../../../../plugins/expressions/public';

import {
CoreSetup,
CoreStart,
Expand All @@ -32,7 +33,7 @@ import {
Start as InspectorStart,
Setup as InspectorSetup,
} from '../../../../../../plugins/inspector/public';
import { IInterpreter } from './types';
import { ExpressionInterpreter } from './types';
import { setInterpreter, setInspector, setRenderersRegistry } from './services';
import { ExpressionRendererImplementation } from './expression_renderer';
import { ExpressionLoader, loader } from './loader';
Expand All @@ -47,7 +48,7 @@ export interface ExpressionsStartDeps {
inspector: InspectorStart;
}

export type ExpressionsSetup = ExpressionsSetupContract;
export { ExpressionsSetup };
export type ExpressionsStart = ReturnType<ExpressionsPublicPlugin['start']>;

export class ExpressionsPublicPlugin
Expand All @@ -61,7 +62,7 @@ export class ExpressionsPublicPlugin
// eslint-disable-next-line
const { getInterpreter } = require('../../../../interpreter/public/interpreter');
getInterpreter()
.then(({ interpreter }: { interpreter: IInterpreter }) => {
.then(({ interpreter }: { interpreter: ExpressionInterpreter }) => {
setInterpreter(interpreter);
})
.catch((e: Error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ExpressionRenderHandler {
try {
// Rendering is asynchronous, completed by handlers.done()
getRenderersRegistry()
.get(data.as)
.get(data.as)!
.render(this.element, data.value, { ...this.handlers, ...extraHandlers });
} catch (e) {
this.renderSubject.next({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* under the License.
*/

import { ExpressionInterpreter } from './types';
import { createGetterSetter } from '../../../../../../plugins/kibana_utils/public';
import { IInterpreter } from './types';
import { Start as IInspector } from '../../../../../../plugins/inspector/public';
import { ExpressionsSetup } from './plugin';

export const [getInspector, setInspector] = createGetterSetter<IInspector>('Inspector');
export const [getInterpreter, setInterpreter] = createGetterSetter<IInterpreter>('Interpreter');
export const [getInterpreter, setInterpreter] = createGetterSetter<ExpressionInterpreter>(
'Interpreter'
);
export const [getRenderersRegistry, setRenderersRegistry] = createGetterSetter<
ExpressionsSetup['__LEGACY']['renderers']
>('Renderers registry');
Original file line number Diff line number Diff line change
Expand Up @@ -21,76 +21,6 @@ import { Filter } from '@kbn/es-query';
import { TimeRange } from '../../../../../../plugins/data/public';
import { Adapters } from '../../../../../../plugins/inspector/public';
import { Query } from '../../../../../../plugins/data/public';
import { ExpressionAST } from '../../../../../../plugins/expressions/common';

export { ExpressionAST, TimeRange, Adapters, Filter, Query };

export type RenderId = number;
export type Data = any;
export type event = any;
export type Context = object;

export interface SearchContext {
type: 'kibana_context';
filters?: Filter[];
query?: Query;
timeRange?: TimeRange;
}

export type IGetInitialContext = () => SearchContext | Context;

export interface IExpressionLoaderParams {
searchContext?: SearchContext;
context?: Context;
variables?: Record<string, any>;
disableCaching?: boolean;
customFunctions?: [];
customRenderers?: [];
extraHandlers?: Record<string, any>;
}

export interface IInterpreterHandlers {
getInitialContext: IGetInitialContext;
inspectorAdapters?: Adapters;
abortSignal?: AbortSignal;
}

export interface IInterpreterErrorResult {
type: 'error';
error: { message: string; name: string; stack: string };
}

export interface IInterpreterSuccessResult {
type: string;
as?: string;
value?: unknown;
error?: unknown;
}

export type IInterpreterResult = IInterpreterSuccessResult & IInterpreterErrorResult;

export interface IInterpreterRenderHandlers {
// Done increments the number of rendering successes
done: () => void;
onDestroy: (fn: () => void) => void;
reload: () => void;
update: (params: any) => void;
event: (event: event) => void;
}

export interface IInterpreterRenderFunction<T = unknown> {
name: string;
displayName: string;
help: string;
validate: () => void;
reuseDomNode: boolean;
render: (domNode: Element, data: T, handlers: IInterpreterRenderHandlers) => void | Promise<void>;
}

export interface IInterpreter {
interpretAst(
ast: ExpressionAST,
context: Context,
handlers: IInterpreterHandlers
): Promise<IInterpreterResult>;
}
export { TimeRange, Adapters, Filter, Query };
export * from '../../../../../../plugins/expressions/public';
3 changes: 2 additions & 1 deletion src/legacy/core_plugins/interpreter/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export {
PointSeriesColumn,
PointSeriesColumnName,
Render,
ExpressionTypeStyle,
Style,
Type,
} from '../../../../plugins/expressions/common';
} from '../../../../plugins/expressions/public';
export const API_ROUTE = '/api/interpreter';
134 changes: 2 additions & 132 deletions src/legacy/core_plugins/interpreter/common/lib/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,135 +17,5 @@
* under the License.
*/

/**
* This type contains a unions of all supported font labels, or the the name of
* the font the user would see in a UI.
*/
export type FontLabel = typeof fonts[number]['label'];

/**
* This type contains a union of all supported font values, equivalent to the CSS
* `font-value` property.
*/
export type FontValue = typeof fonts[number]['value'];

/**
* An interface representing a font in Canvas, with a textual label and the CSS
* `font-value`.
*/
export interface Font {
label: FontLabel;
value: FontValue;
}

// This function allows one to create a strongly-typed font for inclusion in
// the font collection. As a result, the values and labels are known to the
// type system, preventing one from specifying a non-existent font at build
// time.
function createFont<
RawFont extends { value: RawFontValue; label: RawFontLabel },
RawFontValue extends string,
RawFontLabel extends string
>(font: RawFont) {
return font;
}

export const americanTypewriter = createFont({
label: 'American Typewriter',
value: "'American Typewriter', 'Courier New', Courier, Monaco, mono",
});

export const arial = createFont({ label: 'Arial', value: 'Arial, sans-serif' });

export const baskerville = createFont({
label: 'Baskerville',
value: "Baskerville, Georgia, Garamond, 'Times New Roman', Times, serif",
});

export const bookAntiqua = createFont({
label: 'Book Antiqua',
value: "'Book Antiqua', Georgia, Garamond, 'Times New Roman', Times, serif",
});

export const brushScript = createFont({
label: 'Brush Script',
value: "'Brush Script MT', 'Comic Sans', sans-serif",
});

export const chalkboard = createFont({
label: 'Chalkboard',
value: "Chalkboard, 'Comic Sans', sans-serif",
});

export const didot = createFont({
label: 'Didot',
value: "Didot, Georgia, Garamond, 'Times New Roman', Times, serif",
});

export const futura = createFont({
label: 'Futura',
value: 'Futura, Impact, Helvetica, Arial, sans-serif',
});

export const gillSans = createFont({
label: 'Gill Sans',
value:
"'Gill Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Helvetica, Arial, sans-serif",
});

export const helveticaNeue = createFont({
label: 'Helvetica Neue',
value: "'Helvetica Neue', Helvetica, Arial, sans-serif",
});

export const hoeflerText = createFont({
label: 'Hoefler Text',
value: "'Hoefler Text', Garamond, Georgia, 'Times New Roman', Times, serif",
});

export const lucidaGrande = createFont({
label: 'Lucida Grande',
value: "'Lucida Grande', 'Lucida Sans Unicode', Lucida, Verdana, Helvetica, Arial, sans-serif",
});

export const myriad = createFont({
label: 'Myriad',
value: 'Myriad, Helvetica, Arial, sans-serif',
});

export const openSans = createFont({
label: 'Open Sans',
value: "'Open Sans', Helvetica, Arial, sans-serif",
});

export const optima = createFont({
label: 'Optima',
value: "Optima, 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Helvetica, Arial, sans-serif",
});

export const palatino = createFont({
label: 'Palatino',
value: "Palatino, 'Book Antiqua', Georgia, Garamond, 'Times New Roman', Times, serif",
});

/**
* A collection of supported fonts.
*/
export const fonts = [
americanTypewriter,
arial,
baskerville,
bookAntiqua,
brushScript,
chalkboard,
didot,
futura,
gillSans,
helveticaNeue,
hoeflerText,
lucidaGrande,
myriad,
openSans,
optima,
palatino,
];
// eslint-disable-next-line
export * from '../../../../../plugins/expressions/public/fonts';
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/interpreter/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { register, registryFactory, Registry, Fn } from '@kbn/interpreter/common
// @ts-ignore
import { routes } from './server/routes';

import { typeSpecs as types } from '../../../plugins/expressions/common';
import { typeSpecs as types } from '../../../plugins/expressions/public';

import { Type } from './common';
import { Legacy } from '../../../../kibana';
Expand Down
18 changes: 2 additions & 16 deletions src/legacy/core_plugins/interpreter/public/functions/clog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,5 @@
* under the License.
*/

import { ExpressionFunction } from '../../types';

const name = 'clog';

type Context = any;
type ClogExpressionFunction = ExpressionFunction<typeof name, Context, {}, Context>;

export const clog = (): ClogExpressionFunction => ({
name,
args: {},
help: 'Outputs the context to the console',
fn: context => {
console.log(context); // eslint-disable-line no-console
return context;
},
});
// eslint-disable-next-line
export * from '../../../../../plugins/expressions/public/functions/clog';
Loading

0 comments on commit a38223d

Please sign in to comment.