Skip to content

Commit dfb2d08

Browse files
Corey Robertsonelasticmachine
andauthored
Handle timeouts on creating templates (#70635) (#70846)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 7cfe8ba commit dfb2d08

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

x-pack/plugins/canvas/public/components/workpad_templates/workpad_templates.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { EuiBasicTableColumn } from '@elastic/eui';
2424
import { Paginate, PaginateChildProps } from '../paginate';
2525
import { TagList } from '../tag_list';
2626
import { getTagsFilter } from '../../lib/get_tags_filter';
27-
// @ts-ignore untyped local
27+
// @ts-expect-error
2828
import { extractSearch } from '../../lib/extract_search';
2929
import { ComponentStrings } from '../../../i18n';
3030
import { CanvasTemplate } from '../../../types';
@@ -61,7 +61,7 @@ export class WorkpadTemplates extends React.PureComponent<
6161
WorkpadTemplatesState
6262
> {
6363
static propTypes = {
64-
createFromTemplate: PropTypes.func.isRequired,
64+
onCreateFromTemplate: PropTypes.func.isRequired,
6565
onClose: PropTypes.func.isRequired,
6666
templates: PropTypes.object,
6767
};

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ import { light } from './theme_light';
1313

1414
import { TEMPLATE_TYPE } from '../../common/lib/constants';
1515

16-
export const templates = [pitch, status, summary, dark, light];
16+
export const templates = [status, summary, dark, light, pitch];
1717

1818
export async function initializeTemplates(
19-
client: Pick<SavedObjectsRepository, 'bulkCreate' | 'find'>
19+
client: Pick<SavedObjectsRepository, 'bulkCreate' | 'create' | 'find'>
2020
) {
2121
const existingTemplates = await client.find({ type: TEMPLATE_TYPE, perPage: 1 });
2222

2323
if (existingTemplates.total === 0) {
24-
const templateObjects = templates.map((template) => ({
25-
id: template.id,
26-
type: TEMPLATE_TYPE,
27-
attributes: template,
28-
}));
29-
30-
client.bulkCreate(templateObjects);
24+
// Some devs were seeing timeouts that would cause an unhandled promise rejection
25+
// likely because the pitch template is so huge.
26+
// So, rather than doing a bulk create of templates, we're going to fire off individual
27+
// creates and catch and throw-away any errors that happen.
28+
// Once packages are ready, we should probably move that pitch that is so large to a package
29+
for (const template of templates) {
30+
client.create(TEMPLATE_TYPE, template, { id: template.id }).catch((err) => undefined);
31+
}
3132
}
3233
}

0 commit comments

Comments
 (0)