Merge pull request #1157 from hooloovooo/catalog-edit-link

Slightly more robust edit link creation
This commit is contained in:
Sebastian Qvarfordt
2020-06-08 10:11:22 +02:00
committed by GitHub
2 changed files with 11 additions and 5 deletions
+2 -3
View File
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { ReactNode } from 'react';
import { Location } from '@backstage/catalog-model';
export type Component = {
name: string;
kind: string;
description: React.ReactNode;
description: ReactNode;
location?: Location;
};
+9 -2
View File
@@ -29,7 +29,14 @@ const DescriptionWrapper = styled('span')({
alignItems: 'center',
});
const createEditLink = (url: string): string => url.replace('blob', 'edit');
const createEditLink = (location: Location): string => {
switch (location.type) {
case 'github':
return location.target.replace('/blob/', '/edit/');
default:
return location.target;
}
};
export function entityToComponent(
envelope: Entity,
@@ -42,7 +49,7 @@ export function entityToComponent(
<DescriptionWrapper>
{envelope.metadata?.annotations?.description ?? 'placeholder'}
{location?.target ? (
<a href={createEditLink(location?.target)}>
<a href={createEditLink(location)}>
<IconButton size="small">
<Edit fontSize="small" />
</IconButton>