Skip to content

Commit

Permalink
Sorted out title issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Aug 12, 2020
1 parent 3586923 commit ed0cb93
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions examples/embeddable_examples/public/book/book_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class BookEmbeddable extends Embeddable<BookEmbeddableInput, BookEmbeddab
});
}

public getTitle() {
return this.getOutput()?.title || this.getOutput().attributes?.title;
}

public destroy() {
super.destroy();
this.subscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
* into an embeddable input shape that contains that saved object's attributes by value.
*/
export class AttributeService<
SavedObjectAttributes,
SavedObjectAttributes extends { title: string },
ValType extends EmbeddableInput & { attributes: SavedObjectAttributes },
RefType extends SavedObjectEmbeddableInput
> {
Expand Down Expand Up @@ -128,10 +128,9 @@ export class AttributeService<
return new Promise<RefType>((resolve, reject) => {
const onSave = async (props: OnSaveProps): Promise<SaveResult> => {
try {
input.attributes.title = props.newTitle;
const wrappedInput = (await this.wrapAttributes(input.attributes, true)) as RefType;
wrappedInput.title = props.newTitle;
resolve(wrappedInput);
throw new Error();
return { id: wrappedInput.savedObjectId };
} catch (error) {
reject();
Expand All @@ -144,7 +143,7 @@ export class AttributeService<
<SavedObjectSaveModal
onSave={onSave}
onClose={() => reject()}
title={input.title || ''}
title={input.attributes.title}
showCopyOnSave={false}
objectType={this.type}
showDescription={false}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export interface DashboardStart {
dashboardFeatureFlagConfig: DashboardFeatureFlagConfig;
DashboardContainerByValueRenderer: ReturnType<typeof createDashboardContainerByValueRenderer>;
getAttributeService: <
A,
A extends { title: string },
V extends EmbeddableInput & { attributes: A },
R extends SavedObjectEmbeddableInput
>(
Expand Down

0 comments on commit ed0cb93

Please sign in to comment.