UNPKG

@nitin15j/plugin-dora-frontend

Version:
36 lines (33 loc) 1.57 kB
import { useApi, configApiRef } from '@backstage/core-plugin-api'; import { DORA_CONFIG_KEYS, ENTITY_ANNOTATION_KEYS } from '../types/config.esm.js'; import { DEFAULT_ENTITY_VALUES } from '../constants/annotations.esm.js'; const DORA_DEFAULT_CONFIG = { environment: DEFAULT_ENTITY_VALUES.ENVIRONMENT, deployment: DEFAULT_ENTITY_VALUES.DEPLOYMENT, defaultTimeRange: "last28days" }; const useDoraConfig = () => { try { const configApi = useApi(configApiRef); const environment = configApi.getOptionalString(DORA_CONFIG_KEYS.ENVIRONMENT) || DORA_DEFAULT_CONFIG.environment; const deployment = configApi.getOptionalString(DORA_CONFIG_KEYS.DEPLOYMENT) || DORA_DEFAULT_CONFIG.deployment; const defaultTimeRange = configApi.getOptionalString(DORA_CONFIG_KEYS.DEFAULT_TIME_RANGE) || DORA_DEFAULT_CONFIG.defaultTimeRange; return { environment, deployment, defaultTimeRange }; } catch (error) { console.warn("DORA Plugin: Config API not available, using default values:", error); return DORA_DEFAULT_CONFIG; } }; const getEntityConfig = (entity, config) => { return { projectSlug: entity.metadata.annotations?.[ENTITY_ANNOTATION_KEYS.PROJECT_SLUG] || DEFAULT_ENTITY_VALUES.PROJECT_SLUG, environment: entity.metadata.annotations?.[ENTITY_ANNOTATION_KEYS.ENVIRONMENT] || config.environment, deployment: entity.metadata.annotations?.[ENTITY_ANNOTATION_KEYS.DEPLOYMENT] || config.deployment }; }; export { DORA_DEFAULT_CONFIG, getEntityConfig, useDoraConfig }; //# sourceMappingURL=config.esm.js.map