Refactor the Sentry plugin router

This commit is contained in:
Björn Marschollek
2020-09-04 13:56:42 +02:00
parent eb4d54fcc4
commit bb7430daba
+14 -17
View File
@@ -19,31 +19,28 @@ import { Routes, Route } from 'react-router';
import { WarningPanel } from '@backstage/core';
import { SentryPluginWidget } from './SentryPluginWidget/SentryPluginWidget';
const SENTRY_ANNOTATION = 'sentry.io/project-id';
const SENTRY_ANNOTATION = 'sentry.io/project-slug';
const isPluginApplicableToEntity = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[SENTRY_ANNOTATION]) &&
entity.metadata.annotations?.[SENTRY_ANNOTATION] !== '';
export const Router = ({ entity }: { entity: Entity }) => {
const projectId = entity.metadata.annotations?.[SENTRY_ANNOTATION];
export const Router = ({ entity }: { entity: Entity }) =>
!isPluginApplicableToEntity(entity) ? (
<WarningPanel title="Sentry plugin:">
`entity.metadata.annotations['
{SENTRY_ANNOTATION}']` key is missing on the entity.{' '}
</WarningPanel>
) : (
if (!projectId) {
return (
<WarningPanel title="Sentry plugin:">
<pre>{SENTRY_ANNOTATION}</pre> annotation is missing on the entity.
</WarningPanel>
);
}
return (
<Routes>
<Route
path="/"
element={
<SentryPluginWidget
sentryProjectId={
entity.metadata.annotations?.[SENTRY_ANNOTATION] || ''
}
statsFor="24h"
/>
<SentryPluginWidget sentryProjectId={projectId} statsFor="24h" />
}
/>
)
</Routes>
);
};