Merge pull request #1157 from hooloovooo/catalog-edit-link
Slightly more robust edit link creation
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user