Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace AssetType enum with union type #50696

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions x-pack/legacy/plugins/integrations_manager/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ export { Request, ResponseToolkit, Server, ServerRoute } from 'hapi';

export type InstallationStatus = Installed['status'] | NotInstalled['status'];

export enum AssetType {
config = 'config',
dashboard = 'dashboard',
visualization = 'visualization',
search = 'search',
ingestPipeline = 'ingest-pipeline',
indexPattern = 'index-pattern',
timelionSheet = 'timelion-sheet',
}
export type AssetType =
| 'config'
| 'dashboard'
| 'visualization'
| 'search'
| 'ingest-pipeline'
| 'index-pattern'
| 'timelion-sheet';

// Registry's response types
// from /search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export * from './handlers';
export type CallESAsCurrentUser = ScopedClusterClient['callAsCurrentUser'];

export const SAVED_OBJECT_TYPES = new Set<AssetType>([
AssetType.config,
AssetType.dashboard,
AssetType.indexPattern,
AssetType.search,
AssetType.timelionSheet,
AssetType.visualization,
'config',
'dashboard',
'index-pattern',
'search',
'timelion-sheet',
'visualization',
]);

export function getClusterAccessor(esClient: IClusterClient, req: Request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function installAssets(options: {

// Only install certain Kibana assets during package installation.
// All other asset types need special handling
const typesToInstall = [AssetType.visualization, AssetType.dashboard, AssetType.search];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting that this didn't cause a crash but mine did...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think accessing the enum is what caused the crash. This is removing them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I meant before they were removed.

const typesToInstall: AssetType[] = ['visualization', 'dashboard', 'search'];

const installationPromises = typesToInstall.map(async assetType =>
installKibanaSavedObjects({ savedObjectsClient, pkgkey, assetType })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export async function removeInstallation(options: {

// Delete the installed assets
const deletePromises = installedObjects.map(async ({ id, type }) => {
if (assetUsesObjects(type as AssetType)) {
savedObjectsClient.delete(type, id);
} else if (type === AssetType.ingestPipeline) {
const assetType = type as AssetType;
if (assetUsesObjects(assetType)) {
savedObjectsClient.delete(assetType, id);
} else if (assetType === 'ingest-pipeline') {
deletePipeline(callCluster, id);
}
});
Expand Down