-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into lens/click-telemetry
- Loading branch information
Showing
70 changed files
with
1,047 additions
and
1,375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
x-pack/legacy/plugins/canvas/i18n/templates/apply_strings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
46 changes: 46 additions & 0 deletions
46
x-pack/legacy/plugins/canvas/i18n/templates/template_strings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
x-pack/legacy/plugins/canvas/i18n/templates/template_strings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
}, | ||
}); |
Oops, something went wrong.