Merge pull request #17951 from backstage/blam/scaffolder-filtering

`scaffolder/next`: Keep the same filtering behaviour as the current
This commit is contained in:
Ben Lambert
2023-05-29 11:35:53 +02:00
committed by GitHub
4 changed files with 18 additions and 34 deletions
+1 -1
View File
@@ -206,7 +206,7 @@ export interface TemplateCardProps {
export const TemplateCategoryPicker: () => JSX.Element | null;
// @alpha
export const TemplateGroup: (props: TemplateGroupProps) => JSX.Element;
export const TemplateGroup: (props: TemplateGroupProps) => JSX.Element | null;
// @alpha (undocumented)
export type TemplateGroupFilter = {
@@ -22,16 +22,6 @@ import { TemplateCard } from '../TemplateCard';
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
describe('TemplateGroup', () => {
it('should return a message when no templates are passed in', async () => {
const { getByText } = render(
<TemplateGroup onSelected={jest.fn()} title="Test" templates={[]} />,
);
expect(
getByText(/No templates found that match your filter/),
).toBeInTheDocument();
});
it('should render a card for each template with the template being passed as a prop', () => {
const mockOnSelected = jest.fn();
const mockTemplates: { template: TemplateEntityV1beta3 }[] = [
@@ -130,14 +120,6 @@ describe('TemplateGroup', () => {
);
}
});
it('should render the title when no templates passed', () => {
const { getByText } = render(
<TemplateGroup onSelected={jest.fn()} title="Test" templates={[]} />,
);
expect(getByText('Test')).toBeInTheDocument();
});
it('should render the title when there are templates in the list', () => {
const mockTemplates: { template: TemplateEntityV1beta3 }[] = [
{
@@ -163,10 +145,20 @@ describe('TemplateGroup', () => {
it('should allow for passing through a user given title component', () => {
const TitleComponent = <p>Im a custom header</p>;
const mockTemplates: { template: TemplateEntityV1beta3 }[] = [
{
template: {
apiVersion: 'scaffolder.backstage.io/v1beta3',
kind: 'Template',
metadata: { name: 'test' },
spec: { parameters: [], steps: [], type: 'website' },
},
},
];
const { getByText } = render(
<TemplateGroup
onSelected={jest.fn()}
templates={[]}
templates={mockTemplates}
title={TitleComponent}
/>,
);
@@ -19,9 +19,7 @@ import {
Content,
ContentHeader,
ItemCardGrid,
Link,
} from '@backstage/core-components';
import { Typography } from '@material-ui/core';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { TemplateCardProps, TemplateCard } from '../TemplateCard';
import { IconComponent } from '@backstage/core-plugin-api';
@@ -61,18 +59,7 @@ export const TemplateGroup = (props: TemplateGroupProps) => {
typeof title === 'string' ? <ContentHeader title={title} /> : title;
if (templates.length === 0) {
return (
<Content>
{titleComponent}
<Typography variant="body2">
No templates found that match your filter. Learn more about{' '}
<Link to="https://backstage.io/docs/features/software-templates/adding-templates">
adding templates
</Link>
.
</Typography>
</Content>
);
return null;
}
const Card = CardComponent || TemplateCard;