blob: 4562b454baa541fdbcb6c53cad203926ece291f7 [file] [log] [blame]
interface LookupTable {
[key: string]: boolean;
}
export interface ChartMetadataConfig {
name: string;
canBeAnnotationTypes?: string[];
credits?: string[];
description?: string;
show?: boolean;
supportedAnnotationTypes?: string[];
thumbnail: string;
useLegacyApi?: boolean;
isNativeFilter?: boolean;
}
export default class ChartMetadata {
name: string;
canBeAnnotationTypes?: string[];
canBeAnnotationTypesLookup: LookupTable;
credits: string[];
description: string;
show: boolean;
supportedAnnotationTypes: string[];
thumbnail: string;
useLegacyApi: boolean;
isNativeFilter: boolean;
constructor(config: ChartMetadataConfig) {
const {
name,
canBeAnnotationTypes = [],
credits = [],
description = '',
show = true,
supportedAnnotationTypes = [],
thumbnail,
useLegacyApi = false,
isNativeFilter = false,
} = config;
this.name = name;
this.credits = credits;
this.description = description;
this.show = show;
this.canBeAnnotationTypes = canBeAnnotationTypes;
this.canBeAnnotationTypesLookup = canBeAnnotationTypes.reduce(
(prev: LookupTable, type: string) => {
const lookup = prev;
lookup[type] = true;
return lookup;
},
{},
);
this.supportedAnnotationTypes = supportedAnnotationTypes;
this.thumbnail = thumbnail;
this.useLegacyApi = useLegacyApi;
this.isNativeFilter = isNativeFilter;
}
canBeAnnotationType(type: string): boolean {
return this.canBeAnnotationTypesLookup[type] || false;
}
clone() {
return new ChartMetadata({
canBeAnnotationTypes: this.canBeAnnotationTypes,
credits: this.credits,
description: this.description,
name: this.name,
show: this.show,
supportedAnnotationTypes: this.supportedAnnotationTypes,
thumbnail: this.thumbnail,
useLegacyApi: this.useLegacyApi,
isNativeFilter: this.isNativeFilter,
});
}
}