Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ObjectType } from '@kbn/config-schema';
import type { ObjectType, Type } from '@kbn/config-schema';
import type { getDrilldownRegistry } from '../drilldowns/registry';
import type { EmbeddableServerDefinition } from './types';

export function getEmbeddableServerRegistry(
drilldownRegistry: ReturnType<typeof getDrilldownRegistry>
) {
const registry: { [key: string]: EmbeddableServerDefinition<any, any> } = {};
const schemaCache: Record<string, Type<object> | undefined> = {};

function getCachedSchema(type: string) {
if (schemaCache[type]) {
return schemaCache[type];
}

const { getSchema } = registry[type] ?? {};
const schema = getSchema?.(drilldownRegistry.getSchema);
schemaCache[type] = schema;
return schema;
}

return {
registerEmbeddableServerDefinition: (
Expand All @@ -30,7 +42,7 @@ export function getEmbeddableServerRegistry(
getAllEmbeddableSchemas: () => {
const schemas: { [key: string]: { schema: ObjectType; title: string } } = {};
Object.entries(registry).forEach(([type, definition]) => {
const schema = definition?.getSchema?.(drilldownRegistry.getSchema);
const schema = getCachedSchema(type);
if (schema) {
schemas[type] = {
schema: schema as ObjectType,
Expand All @@ -41,10 +53,11 @@ export function getEmbeddableServerRegistry(
return schemas;
},
getEmbeddableTransforms: (type: string) => {
const { getTransforms, getSchema, throwOnUnmappedPanel } = registry[type] ?? {};
const { getTransforms, throwOnUnmappedPanel } = registry[type] ?? {};
const schema = getCachedSchema(type);
return {
...getTransforms?.(drilldownRegistry.transforms),
...(getSchema ? { schema: getSchema(drilldownRegistry.getSchema) } : {}),
...(schema ? { schema } : {}),
...(typeof throwOnUnmappedPanel === 'boolean' ? { throwOnUnmappedPanel } : {}),
};
},
Expand Down
Loading