mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Time to Visualize] Small Attribute Service Fixes (#82072)
* Removed some dashboard-centric wording from the Attribute Service & removed type argument from save method
This commit is contained in:
parent
2f504a05a7
commit
8c1b2157df
7 changed files with 14 additions and 36 deletions
|
@ -133,16 +133,12 @@ export class BookEmbeddableFactoryDefinition
|
|||
return { ...savedObject.attributes };
|
||||
}
|
||||
|
||||
private async saveMethod(
|
||||
type: string,
|
||||
attributes: BookSavedObjectAttributes,
|
||||
savedObjectId?: string
|
||||
) {
|
||||
private async saveMethod(attributes: BookSavedObjectAttributes, savedObjectId?: string) {
|
||||
const { savedObjectsClient } = await this.getStartServices();
|
||||
if (savedObjectId) {
|
||||
return savedObjectsClient.update(type, savedObjectId, attributes);
|
||||
return savedObjectsClient.update(this.type, savedObjectId, attributes);
|
||||
}
|
||||
return savedObjectsClient.create(type, attributes);
|
||||
return savedObjectsClient.create(this.type, attributes);
|
||||
}
|
||||
|
||||
private async checkForDuplicateTitleMethod(props: OnSaveProps): Promise<true> {
|
||||
|
|
|
@ -64,15 +64,11 @@ export const createEditBookAction = (getStartServices: () => Promise<StartServic
|
|||
execute: async ({ embeddable }: ActionContext) => {
|
||||
const { openModal, getAttributeService, savedObjectsClient } = await getStartServices();
|
||||
const attributeService = getAttributeService<BookSavedObjectAttributes>(BOOK_SAVED_OBJECT, {
|
||||
saveMethod: async (
|
||||
type: string,
|
||||
attributes: BookSavedObjectAttributes,
|
||||
savedObjectId?: string
|
||||
) => {
|
||||
saveMethod: async (attributes: BookSavedObjectAttributes, savedObjectId?: string) => {
|
||||
if (savedObjectId) {
|
||||
return savedObjectsClient.update(type, savedObjectId, attributes);
|
||||
return savedObjectsClient.update(BOOK_EMBEDDABLE, savedObjectId, attributes);
|
||||
}
|
||||
return savedObjectsClient.create(type, attributes);
|
||||
return savedObjectsClient.create(BOOK_EMBEDDABLE, attributes);
|
||||
},
|
||||
checkForDuplicateTitle: (props: OnSaveProps) => {
|
||||
return new Promise(() => {
|
||||
|
|
|
@ -39,7 +39,6 @@ describe('attributeService', () => {
|
|||
let byValueInput: TestByValueInput;
|
||||
let byReferenceInput: { id: string; savedObjectId: string };
|
||||
const defaultSaveMethod = (
|
||||
type: string,
|
||||
testAttributes: TestAttributes,
|
||||
savedObjectId?: string
|
||||
): Promise<{ id: string }> => {
|
||||
|
@ -166,7 +165,7 @@ describe('attributeService', () => {
|
|||
expect(await attributeService.wrapAttributes(attributes, true, byReferenceInput)).toEqual(
|
||||
byReferenceInput
|
||||
);
|
||||
expect(saveMethod).toHaveBeenCalledWith(defaultTestType, attributes, '123');
|
||||
expect(saveMethod).toHaveBeenCalledWith(attributes, '123');
|
||||
});
|
||||
|
||||
it('uses custom save method when given an id', async () => {
|
||||
|
@ -179,11 +178,7 @@ describe('attributeService', () => {
|
|||
expect(await attributeService.wrapAttributes(attributes, true, byReferenceInput)).toEqual(
|
||||
byReferenceInput
|
||||
);
|
||||
expect(saveMethod).toHaveBeenCalledWith(
|
||||
defaultTestType,
|
||||
attributes,
|
||||
byReferenceInput.savedObjectId
|
||||
);
|
||||
expect(saveMethod).toHaveBeenCalledWith(attributes, byReferenceInput.savedObjectId);
|
||||
});
|
||||
|
||||
it('uses custom save method given no id', async () => {
|
||||
|
@ -196,7 +191,7 @@ describe('attributeService', () => {
|
|||
expect(await attributeService.wrapAttributes(attributes, true)).toEqual({
|
||||
savedObjectId: '678',
|
||||
});
|
||||
expect(saveMethod).toHaveBeenCalledWith(defaultTestType, attributes, undefined);
|
||||
expect(saveMethod).toHaveBeenCalledWith(attributes, undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -42,7 +42,6 @@ export const ATTRIBUTE_SERVICE_KEY = 'attributes';
|
|||
|
||||
export interface AttributeServiceOptions<A extends { title: string }> {
|
||||
saveMethod: (
|
||||
type: string,
|
||||
attributes: A,
|
||||
savedObjectId?: string
|
||||
) => Promise<{ id?: string } | { error: Error }>;
|
||||
|
@ -106,7 +105,7 @@ export class AttributeService<
|
|||
return { [ATTRIBUTE_SERVICE_KEY]: newAttributes } as ValType;
|
||||
}
|
||||
try {
|
||||
const savedItem = await this.options.saveMethod(this.type, newAttributes, savedObjectId);
|
||||
const savedItem = await this.options.saveMethod(newAttributes, savedObjectId);
|
||||
if ('id' in savedItem) {
|
||||
return { ...originalInput, savedObjectId: savedItem.id } as RefType;
|
||||
}
|
||||
|
@ -114,12 +113,12 @@ export class AttributeService<
|
|||
} catch (error) {
|
||||
this.toasts.addDanger({
|
||||
title: i18n.translate('embeddableApi.attributeService.saveToLibraryError', {
|
||||
defaultMessage: `Panel was not saved to the library. Error: {errorMessage}`,
|
||||
defaultMessage: `An error occurred while saving. Error: {errorMessage}`,
|
||||
values: {
|
||||
errorMessage: error.message,
|
||||
},
|
||||
}),
|
||||
'data-test-subj': 'saveDashboardFailure',
|
||||
'data-test-subj': 'attributeServiceSaveFailure',
|
||||
});
|
||||
return Promise.reject({ error });
|
||||
}
|
||||
|
|
|
@ -187,10 +187,7 @@ export class VisualizeEmbeddableFactory
|
|||
}
|
||||
}
|
||||
|
||||
private async saveMethod(
|
||||
type: string,
|
||||
attributes: VisualizeSavedObjectAttributes
|
||||
): Promise<{ id: string }> {
|
||||
private async saveMethod(attributes: VisualizeSavedObjectAttributes): Promise<{ id: string }> {
|
||||
try {
|
||||
const { title, savedVis } = attributes;
|
||||
const visObj = attributes.vis;
|
||||
|
|
|
@ -47,7 +47,6 @@ const savedVis: Document = {
|
|||
visualizationType: '',
|
||||
};
|
||||
const defaultSaveMethod = (
|
||||
type: string,
|
||||
testAttributes: LensSavedObjectAttributes,
|
||||
savedObjectId?: string
|
||||
): Promise<{ id: string }> => {
|
||||
|
|
|
@ -32,11 +32,7 @@ export function getLensAttributeService(
|
|||
LensByValueInput,
|
||||
LensByReferenceInput
|
||||
>(DOC_TYPE, {
|
||||
saveMethod: async (
|
||||
type: string,
|
||||
attributes: LensSavedObjectAttributes,
|
||||
savedObjectId?: string
|
||||
) => {
|
||||
saveMethod: async (attributes: LensSavedObjectAttributes, savedObjectId?: string) => {
|
||||
const savedDoc = await savedObjectStore.save({
|
||||
...attributes,
|
||||
savedObjectId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue