Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lens/click-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Oct 16, 2019
2 parents 5ef055f + f4cd288 commit 1836ed1
Show file tree
Hide file tree
Showing 70 changed files with 1,047 additions and 1,375 deletions.
2 changes: 1 addition & 1 deletion docs/developer/core/development-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Kibana exposes two clients on the server and browser for communicating with elasticsearch.
There is an 'admin' client which is used for managing Kibana's state, and a 'data' client for all
other requests. The clients use the {jsclient}/javascript-api/current/index.html[elasticsearch.js library].
other requests. The clients use the {jsclient-current}/index.html[elasticsearch.js library].

[float]
[[client-server]]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"@babel/register": "^7.5.5",
"@elastic/charts": "^13.5.1",
"@elastic/datemath": "5.0.2",
"@elastic/ems-client": "^1.0.2",
"@elastic/ems-client": "1.0.5",
"@elastic/eui": "14.5.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { applyTemplateStrings } from '../../i18n/templates';

const darkTemplate = require('./theme_dark.json');
const lightTemplate = require('./theme_light.json');
const pitchTemplate = require('./pitch_presentation.json');
const statusTemplate = require('./status_report.json');
const summaryTemplate = require('./summary_report.json');
import darkTemplate from './theme_dark.json';
import lightTemplate from './theme_light.json';
import pitchTemplate from './pitch_presentation.json';
import statusTemplate from './status_report.json';
import summaryTemplate from './summary_report.json';

// Registry expects a function that returns a spec object
export const templateSpecs = [
export const templateSpecs = applyTemplateStrings([
darkTemplate,
lightTemplate,
pitchTemplate,
statusTemplate,
summaryTemplate,
].map(template => () => template);
]);
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const chart: TagFactory = () => ({ name: 'chart', color: '#FEB6DB' });
export const chart: TagFactory = () => ({
name: strings.chart(),
color: '#FEB6DB',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const filter: TagFactory = () => ({ name: 'filter', color: '#3185FC' });
export const filter: TagFactory = () => ({
name: strings.filter(),
color: '#3185FC',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const graphic: TagFactory = () => ({ name: 'graphic', color: '#E6C220' });
export const graphic: TagFactory = () => ({
name: strings.graphic(),
color: '#E6C220',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const presentation: TagFactory = () => ({ name: 'presentation', color: '#017D73' });
export const presentation: TagFactory = () => ({
name: strings.presentation(),
color: '#017D73',
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@

import { TagFactory } from '../../../public/lib/tag';

export const proportion: TagFactory = () => ({ name: 'proportion', color: '#490092' });
import { TagStrings as strings } from '../../../i18n';

export const proportion: TagFactory = () => ({
name: strings.proportion(),
color: '#490092',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const report: TagFactory = () => ({ name: 'report', color: '#DB1374' });
export const report: TagFactory = () => ({
name: strings.report(),
color: '#DB1374',
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
*/

import { TagFactory } from '../../../public/lib/tag';
import { TagStrings as strings } from '../../../i18n';

export const text: TagFactory = () => ({ name: 'text', color: '#D3DAE6' });
export const text: TagFactory = () => ({
name: strings.text(),
color: '#D3DAE6',
});
15 changes: 14 additions & 1 deletion x-pack/legacy/plugins/canvas/i18n/elements/apply_strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

import { ElementFactory } from '../../types';
import { getElementStrings } from './element_strings';
import { getElementStrings } from './index';

import { TagStrings } from '../../i18n';

/**
* This function takes a set of Canvas Element specification factories, runs them,
Expand All @@ -32,6 +34,17 @@ export const applyElementStrings = (elements: ElementFactory[]) => {
if (displayName) {
result.displayName = displayName;
}

// Set translated tags
if (result.tags) {
result.tags = result.tags.map(tag => {
if (tag in TagStrings) {
return TagStrings[tag]();
}

return tag;
});
}
}

return () => result;
Expand Down
13 changes: 13 additions & 0 deletions x-pack/legacy/plugins/canvas/i18n/elements/element_strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { getElementStrings } from './element_strings';
import { elementSpecs } from '../../canvas_plugin_src/elements';

import { TagStrings } from '../tags';

describe('ElementStrings', () => {
const elementStrings = getElementStrings();
const elementNames = elementSpecs.map(spec => spec().name);
Expand All @@ -33,4 +35,15 @@ describe('ElementStrings', () => {
expect(value).toHaveProperty('help');
});
});

test('All elements should have tags that are defined', () => {
const tagNames = Object.keys(TagStrings);

elementSpecs.forEach(spec => {
const element = spec();
if (element.tags) {
element.tags.forEach((tagName: string) => expect(tagNames).toContain(tagName));
}
});
});
});
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/canvas/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './elements';
export * from './functions';
export * from './renderers';
export * from './shortcuts';
export * from './tags';
export * from './transitions';
export * from './ui';
export * from './units';
Expand Down
38 changes: 38 additions & 0 deletions x-pack/legacy/plugins/canvas/i18n/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 TagStrings: { [key: string]: () => string } = {
chart: () =>
i18n.translate('xpack.canvas.tags.chartTag', {
defaultMessage: 'chart',
}),
filter: () =>
i18n.translate('xpack.canvas.tags.filterTag', {
defaultMessage: 'filter',
}),
graphic: () =>
i18n.translate('xpack.canvas.tags.graphicTag', {
defaultMessage: 'graphic',
}),
presentation: () =>
i18n.translate('xpack.canvas.tags.presentationTag', {
defaultMessage: 'presentation',
}),
proportion: () =>
i18n.translate('xpack.canvas.tags.proportionTag', {
defaultMessage: 'proportion',
}),
report: () =>
i18n.translate('xpack.canvas.tags.reportTag', {
defaultMessage: 'report',
}),
text: () =>
i18n.translate('xpack.canvas.tags.textTag', {
defaultMessage: 'text',
}),
};
50 changes: 50 additions & 0 deletions x-pack/legacy/plugins/canvas/i18n/templates/apply_strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { CanvasTemplate } from '../../types';
import { getTemplateStrings } from './template_strings';

import { TagStrings } from '../../i18n';

/**
* This function takes a set of Canvas templates
* replaces tag strings with the translated versions. We do this
* so the specifications themselves have no dependency on i18n, for clarity for both
* our and external plugin developers.
*/
export const applyTemplateStrings = (templates: CanvasTemplate[]) => {
const templateStrings = getTemplateStrings();

return templates.map(template => {
const { name: templateName } = template;
const strings = templateStrings[templateName];

// If we have registered strings for this spec, we should replace any that are available.
if (strings) {
const { name, help } = strings;
// If the function has a registered help string, replace it on the spec.
if (help) {
template.help = help;
}

if (name) {
template.name = name;
}
}

if (template.tags) {
template.tags = template.tags.map(tag => {
if (TagStrings[tag]) {
return TagStrings[tag]();
}

return tag;
});
}

return () => template;
});
};
8 changes: 8 additions & 0 deletions x-pack/legacy/plugins/canvas/i18n/templates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 * from './apply_strings';
export * from './template_strings';
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { getTemplateStrings } from './template_strings';
import { templateSpecs } from '../../canvas_plugin_src/templates';

import { TagStrings } from '../tags';

describe('TemplateStrings', () => {
const templateStrings = getTemplateStrings();
const templateNames = templateSpecs.map(template => template().name);
const stringKeys = Object.keys(templateStrings);

test('All template names should exist in the strings definition', () => {
templateNames.forEach((name: string) => expect(stringKeys).toContain(name));
});

test('All string definitions should correspond to an existing template', () => {
stringKeys.forEach(key => expect(templateNames).toContain(key));
});

const strings = Object.values(templateStrings);

test('All templates should have a name string defined', () => {
strings.forEach(value => {
expect(value).toHaveProperty('name');
});
});

test('All templates should have a help string defined', () => {
strings.forEach(value => {
expect(value).toHaveProperty('help');
});
});

test('All templates should have tags that are defined', () => {
const tagNames = Object.keys(TagStrings);

templateSpecs.forEach(template => {
template().tags.forEach((tagName: string) => expect(tagNames).toContain(tagName));
});
});
});
64 changes: 64 additions & 0 deletions x-pack/legacy/plugins/canvas/i18n/templates/template_strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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';

interface TemplateStrings {
name: string;
help: string;
}

interface TemplateStringDict {
[templateName: string]: TemplateStrings;
}

/**
* This function will return a dictionary of strings, organized by Canvas
* Element specification. This function requires that `i18nProvider` be
* properly initialized.
*/
export const getTemplateStrings = (): TemplateStringDict => ({
Dark: {
name: i18n.translate('xpack.canvas.templates.darkName', {
defaultMessage: 'Dark',
}),
help: i18n.translate('xpack.canvas.templates.darkHelp', {
defaultMessage: 'Dark color themed presentation deck',
}),
},
Light: {
name: i18n.translate('xpack.canvas.templates.lightName', {
defaultMessage: 'Light',
}),
help: i18n.translate('xpack.canvas.templates.lightHelp', {
defaultMessage: 'Light color themed presentation deck',
}),
},
Pitch: {
name: i18n.translate('xpack.canvas.templates.pitchName', {
defaultMessage: 'Pitch',
}),
help: i18n.translate('xpack.canvas.templates.pitchHelp', {
defaultMessage: 'Branded presentation with large photos"',
}),
},
Status: {
name: i18n.translate('xpack.canvas.templates.statusName', {
defaultMessage: 'Status',
}),
help: i18n.translate('xpack.canvas.templates.statusHelp', {
defaultMessage: 'Document-style report with live charts',
}),
},
Summary: {
name: i18n.translate('xpack.canvas.templates.summaryDisplayName', {
defaultMessage: 'Summary',
}),
help: i18n.translate('xpack.canvas.templates.summaryHelp', {
defaultMessage: 'Infographic-style report with live charts',
}),
},
});
Loading

0 comments on commit 1836ed1

Please sign in to comment.