Catalog: Wrap EntityOrphanWarning in EntitySwitch

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-05-19 09:36:42 +02:00
parent d720a3ecf8
commit c023c72230
3 changed files with 15 additions and 5 deletions
@@ -41,6 +41,7 @@ import {
isKind,
EntityHasResourcesCard,
EntityOrphanWarning,
isOrphan,
} from '@backstage/plugin-catalog';
import {
EntityCircleCIContent,
@@ -215,9 +216,14 @@ const errorsContent = (
const overviewContent = (
<Grid container spacing={3} alignItems="stretch">
<Grid item xs={12}>
<EntityOrphanWarning />
</Grid>
<EntitySwitch>
<EntitySwitch.Case if={isOrphan}>
<Grid item xs={12}>
<EntityOrphanWarning />
</Grid>
</EntitySwitch.Case>
</EntitySwitch>
<Grid item md={8} xs={12}>
<EntityAboutCard variant="gridItem" />
</Grid>
@@ -14,12 +14,16 @@
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { Alert } from '@material-ui/lab';
import React, { useState } from 'react';
import { useNavigate } from 'react-router';
import { DeleteEntityDialog } from './DeleteEntityDialog';
export const isOrphan = (entity: Entity) =>
entity?.metadata?.annotations?.['backstage.io/orphan'] === 'true';
/**
* Displays a warning alert if the entity is marked as orphan with the ability to delete said entity.
*/
@@ -28,7 +32,7 @@ export const EntityOrphanWarning = () => {
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
const { entity } = useEntity();
if (entity.metadata?.annotations?.['backstage.io/orphan'] !== 'true') {
if (entity?.metadata?.annotations?.['backstage.io/orphan'] !== 'true') {
return null;
}
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { EntityOrphanWarning } from './EntityOrphanWarning';
export { EntityOrphanWarning, isOrphan } from './EntityOrphanWarning';