Skip to content

Commit

Permalink
🐛 Make update overwrite an optional prop owned by each plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Sep 8, 2023
1 parent d9b0427 commit 6c1c096
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ function getClientForType(
);
}

function getAdditionalOptionsForUpdate(
type: string,
typesService: TypesStart,
method: 'update' | 'create'
) {
const visAliases = typesService.getAliases();
const aliasType = visAliases.find((v) => v.appExtensions?.visualizations.docTypes.includes(type));
if (!aliasType) {
return { overwrite: true };
}
return aliasType?.appExtensions?.visualizations?.clientOptions?.[method];
}

export const updateBasicSoAttributes = async (
soId: string,
type: string,
Expand Down Expand Up @@ -73,8 +86,8 @@ export const updateBasicSoAttributes = async (
...attributes,
},
options: {
overwrite: true,
references,
...getAdditionalOptionsForUpdate(type, dependencies.typesService, 'update'),
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export interface VisualizationClient<
export interface VisualizationsAppExtension {
docTypes: string[];
searchFields?: string[];
/** let each visualization client pass its own custom options if required */
clientOptions?: {
update?: { overwrite?: boolean; [otherOption: string]: unknown };
create?: { [otherOption: string]: unknown };
};
client: (contentManagement: ContentManagementPublicStart) => VisualizationClient;
toListItem: (savedObject: SimpleSavedObject<any>) => VisualizationListItem;
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/vis_type_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const getLensAliasConfig = (): VisTypeAlias => ({
visualizations: {
docTypes: ['lens'],
searchFields: ['title^3'],
clientOptions: { update: { overwrite: true } },
client: getLensClient,
toListItem(savedObject) {
const { id, type, updatedAt, attributes } = savedObject;
Expand Down

0 comments on commit 6c1c096

Please sign in to comment.