Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import EntityCustomInfoCard from './EntityCustomInfoCard';
export default {
title: 'Components/EntityCustomInfoCard',
component: EntityCustomInfoCard,
// Set up default inline mocks for the hooks used in EntityCustomInfoCard.
// Adjust the module paths (e.g. 'src/hooks/useEntity') to match your project structure.
parameters: {
const isRelativePath = (url) => !/^([a-z]+:\/\/|\/|#)/i.test(url);
// Main function to substitute relative paths with absolute paths according to Backstage rules
function substituteRelativePaths(entity, baseUrl) {
const result = JSON.parse(JSON.stringify(entity)); // Deep copy
// Substitute relative URLs in annotations (Backstage specific)
if (result.metadata?.annotations) {
for (const [key, value] of Object.entries(result.metadata.annotations)) {
if (typeof value === 'string' && isRelativePath(value)) {
WITH entity_providers AS (
SELECT
entity_ref,
JSONB_AGG(DISTINCT provider_id) AS provider_ids
FROM
staging_entity_fragments
WHERE
expiredAt IS NULL OR expiredAt > CURRENT_TIMESTAMP
GROUP BY
entity_ref
import React, { useEffect, useState } from 'react';
import { useApi, identityApiRef } from '@backstage/core-plugin-api';
import { useAsyncEntity } from '@backstage/plugin-catalog-react';
import { useEntityOwnership } from '@backstage/plugin-catalog-react';
import jwtDecode from 'jwt-decode';
import { accessCheckerRegistry, AccessCondition } from '../accessCheckers';
export interface AccessState {
loading: boolean;
I'll help create a Markdown artifact for this RFC documentation. Given the length and complexity, this is a good candidate for an artifact.​​​​​​​​​​​​​​​​
I've created the RFC as a Markdown document with the following improvements:
1. Added proper Markdown formatting and hierarchy
2. Included placeholders for two Mermaid diagrams in the Design section:
- Adding Entity Flow
- Removing Entities Flow
3. Improved readability with consistent heading levels and spacing
4. Organized the content with clear section breaks
I'll update both test files to follow modern React Testing Library best practices and linting rules. Here's the improved version of both tests:
```xml
<code_changes>
<changed_files>
<file>
<file_summary>Update CardHeader test to follow RTL best practices</file_summary>
<file_operation>UPDATE</file_operation>
<file_path>/plugins/scaffolder-react/src/next/components/TemplateCard/CardHeader.test.tsx</file_path>
<file_code><![CDATA[
import React from 'react';
import {
TemplateCard,
type TemplateCardProps,
} from '@backstage/plugin-scaffolder-react';
import { Typography, makeStyles } from '@material-ui/core';
const useStyles = makeStyles(theme => ({
annotation: {
marginTop: theme.spacing(1),
/**
* Copyright ...
* (License header)
*/
export const defaultPreviewTemplate = `# Edit the template parameters below to see how they will render in the scaffolder form UI
parameters:
- title: Fill in some steps
ui:ObjectFieldTemplate: TwoColumn
required:
// package.json
{
"name": "use-entity-client-access-check",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"test": "jest"
},
"dependencies": {
import {
CatalogProcessor,
CatalogProcessorEmit,
CatalogProcessorParser,
processingResult,
} from '@backstage/plugin-catalog-backend';
import {
Entity,
parseEntityRef,
} from '@backstage/catalog-model';