Skip to content

Commit a9f72bc

Browse files
author
Corey Robertson
authored
[Canvas] Move Templates to be stored as Saved Objects (#69438)
* Moves Canvas templates to live server side * Adds Clone from template test * Fix url * Clean up * PR Feedback * i18n
1 parent 4784686 commit a9f72bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5096
-3646
lines changed

x-pack/plugins/canvas/canvas_plugin_src/plugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { modelSpecs } from './uis/models';
2424
import { initializeViews } from './uis/views';
2525
import { initializeArgs } from './uis/arguments';
2626
import { tagSpecs } from './uis/tags';
27-
import { templateSpecs } from './templates';
2827

2928
interface SetupDeps {
3029
canvas: CanvasSetup;
@@ -59,7 +58,6 @@ export class CanvasSrcPlugin implements Plugin<void, void, SetupDeps, StartDeps>
5958
plugins.canvas.addViewUIs(initializeViews(core, plugins));
6059
plugins.canvas.addArgumentUIs(initializeArgs(core, plugins));
6160
plugins.canvas.addTagUIs(tagSpecs);
62-
plugins.canvas.addTemplates(templateSpecs);
6361
plugins.canvas.addTransformUIs(transformSpecs);
6462
}
6563

x-pack/plugins/canvas/canvas_plugin_src/templates/index.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

x-pack/plugins/canvas/canvas_plugin_src/templates/status_report.json

Lines changed: 0 additions & 816 deletions
This file was deleted.

x-pack/plugins/canvas/canvas_plugin_src/templates/summary_report.json

Lines changed: 0 additions & 455 deletions
This file was deleted.

x-pack/plugins/canvas/canvas_plugin_src/templates/theme_dark.json

Lines changed: 0 additions & 335 deletions
This file was deleted.

x-pack/plugins/canvas/canvas_plugin_src/templates/theme_light.json

Lines changed: 0 additions & 342 deletions
This file was deleted.

x-pack/plugins/canvas/common/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SHAREABLE_RUNTIME_NAME } from '../../shareable_runtime/constants_static
88

99
export const CANVAS_TYPE = 'canvas-workpad';
1010
export const CUSTOM_ELEMENT_TYPE = 'canvas-element';
11+
export const TEMPLATE_TYPE = `${CANVAS_TYPE}-template`;
1112
export const CANVAS_APP = 'canvas';
1213
export const APP_ROUTE = '/app/canvas';
1314
export const APP_ROUTE_WORKPAD = `${APP_ROUTE}#/workpad`;
@@ -16,6 +17,7 @@ export const API_ROUTE_WORKPAD = `${API_ROUTE}/workpad`;
1617
export const API_ROUTE_WORKPAD_ASSETS = `${API_ROUTE}/workpad-assets`;
1718
export const API_ROUTE_WORKPAD_STRUCTURES = `${API_ROUTE}/workpad-structures`;
1819
export const API_ROUTE_CUSTOM_ELEMENT = `${API_ROUTE}/custom-element`;
20+
export const API_ROUTE_TEMPLATES = `${API_ROUTE}/templates`;
1921
export const LOCALSTORAGE_PREFIX = `kibana.canvas`;
2022
export const LOCALSTORAGE_CLIPBOARD = `${LOCALSTORAGE_PREFIX}.clipboard`;
2123
export const SESSIONSTORAGE_LASTPATH = 'lastPath:canvas';

x-pack/plugins/canvas/i18n/components.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,5 +1604,12 @@ export const ComponentStrings = {
16041604
i18n.translate('xpack.canvas.workpadTemplate.searchPlaceholder', {
16051605
defaultMessage: 'Find template',
16061606
}),
1607+
getCreatingTemplateLabel: (templateName: string) =>
1608+
i18n.translate('xpack.canvas.workpadTemplate.creatingTemplateLabel', {
1609+
defaultMessage: `Creating from template '{templateName}'`,
1610+
values: {
1611+
templateName,
1612+
},
1613+
}),
16071614
},
16081615
};

x-pack/plugins/canvas/i18n/templates/apply_strings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export const applyTemplateStrings = (templates: CanvasTemplate[]) => {
4545
});
4646
}
4747

48-
return () => template;
48+
return template;
4949
});
5050
};

x-pack/plugins/canvas/i18n/templates/template_strings.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import { getTemplateStrings } from './template_strings';
8-
import { templateSpecs } from '../../canvas_plugin_src/templates';
8+
import { templates } from '../../server/templates'; // eslint-disable-line
99

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

1212
describe('TemplateStrings', () => {
1313
const templateStrings = getTemplateStrings();
14-
const templateNames = templateSpecs.map((template) => template().name);
14+
const templateNames = templates.map((template) => template.name);
1515
const stringKeys = Object.keys(templateStrings);
1616

1717
test('All template names should exist in the strings definition', () => {
@@ -39,8 +39,8 @@ describe('TemplateStrings', () => {
3939
test('All templates should have tags that are defined', () => {
4040
const tagNames = Object.keys(TagStrings);
4141

42-
templateSpecs.forEach((template) => {
43-
template().tags.forEach((tagName: string) => expect(tagNames).toContain(tagName));
42+
templates.forEach((template) => {
43+
template.tags.forEach((tagName: string) => expect(tagNames).toContain(tagName));
4444
});
4545
});
4646
});

0 commit comments

Comments
 (0)