chore: removing FavouriteTemplate in favor of FavoriteEntity

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-03-02 17:01:36 +01:00
parent b32fcd3485
commit 9562b13913
4 changed files with 8 additions and 94 deletions
@@ -1,74 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import { useStarredEntity } from '@backstage/plugin-catalog-react';
import { IconButton, makeStyles, Tooltip, withStyles } from '@material-ui/core';
import Star from '@material-ui/icons/Star';
import StarBorder from '@material-ui/icons/StarBorder';
import React, { ComponentProps } from 'react';
type Props = ComponentProps<typeof IconButton> & { entity: Entity };
const YellowStar = withStyles({
root: {
color: '#f3ba37',
},
})(Star);
const WhiteBorderStar = withStyles({
root: {
color: '#ffffff',
},
})(StarBorder);
const useStyles = makeStyles(theme => ({
starButton: {
position: 'absolute',
top: theme.spacing(0.5),
right: theme.spacing(0.5),
padding: '0.25rem',
},
}));
export const favouriteTemplateTooltip = (isStarred: boolean) =>
isStarred ? 'Remove from favorites' : 'Add to favorites';
export const favouriteTemplateIcon = (isStarred: boolean) =>
isStarred ? <YellowStar /> : <WhiteBorderStar />;
/**
* IconButton for showing if a current entity is starred and adding/removing it from the favourite entities
* @param props - MaterialUI IconButton props extended by required `entity` prop
*/
export const FavouriteTemplate = (props: Props) => {
const classes = useStyles();
const { toggleStarredEntity, isStarredEntity } = useStarredEntity(
props.entity,
);
return (
<IconButton
color="inherit"
className={classes.starButton}
{...props}
onClick={() => toggleStarredEntity()}
>
<Tooltip title={favouriteTemplateTooltip(isStarredEntity)}>
{favouriteTemplateIcon(isStarredEntity)}
</Tooltip>
</IconButton>
);
};
@@ -1,17 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './FavouriteTemplate';
@@ -21,6 +21,7 @@ import {
} from '@backstage/integration-react';
import {
EntityRefLinks,
FavoriteEntity,
getEntityRelations,
getEntitySourceLocation,
} from '@backstage/plugin-catalog-react';
@@ -42,7 +43,6 @@ import {
import WarningIcon from '@material-ui/icons/Warning';
import React from 'react';
import { selectedTemplateRouteRef } from '../../routes';
import { FavouriteTemplate } from '../FavouriteTemplate/FavouriteTemplate';
import { Button, ItemCardHeader } from '@backstage/core-components';
import { useApi, useRouteRef } from '@backstage/core-plugin-api';
@@ -74,6 +74,12 @@ const useStyles = makeStyles(theme => ({
leftButton: {
marginRight: 'auto',
},
starButton: {
position: 'absolute',
top: theme.spacing(0.5),
right: theme.spacing(0.5),
padding: '0.25rem',
},
}));
const useDeprecationStyles = makeStyles(theme => ({
@@ -159,7 +165,7 @@ export const TemplateCard = ({ template, deprecated }: TemplateCardProps) => {
return (
<Card>
<CardMedia className={classes.cardHeader}>
<FavouriteTemplate entity={template} />
<FavoriteEntity className={classes.starButton} entity={template} />
{deprecated && <DeprecationWarning />}
<ItemCardHeader
title={templateProps.title}
@@ -15,7 +15,6 @@
*/
export * from './fields';
export type { RepoUrlPickerUiOptions } from './fields';
export { FavouriteTemplate } from './FavouriteTemplate';
export { TemplateList } from './TemplateList';
export type { TemplateListProps } from './TemplateList';
export { TemplateTypePicker } from './TemplateTypePicker';