Skip to content

Commit

Permalink
Merge pull request backstage#17847 from SnowBlitzer/catalogTableTitles
Browse files Browse the repository at this point in the history
Adding info on entities selected to catalog table title
  • Loading branch information
Rugvip authored Jun 12, 2023
2 parents d4c5b8a + 1c7f705 commit 5b38139
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-shrimps-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---

Adding in type and kind entity details to catalog table title for user clarity
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('DefaultApiExplorerPage', () => {
const { findByTitle, findByText } = await renderWrapped(
<DefaultApiExplorerPage />,
);
expect(await findByText(/All \(1\)/)).toBeInTheDocument();
expect(await findByText(/All apis \(1\)/)).toBeInTheDocument();
expect(await findByTitle(/View/)).toBeInTheDocument();
expect(await findByTitle(/View/)).toBeInTheDocument();
expect(await findByTitle(/Edit/)).toBeInTheDocument();
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('DefaultApiExplorerPage', () => {
const { findByTitle, findByText } = await renderWrapped(
<DefaultApiExplorerPage actions={actions} />,
);
expect(await findByText(/All \(1\)/)).toBeInTheDocument();
expect(await findByText(/All apis \(1\)/)).toBeInTheDocument();
expect(await findByTitle(/Foo Action/)).toBeInTheDocument();
expect(await findByTitle(/Bar Action/)).toBeInTheDocument();
expect((await findByTitle(/Bar Action/)).firstChild).toBeDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ describe('DefaultCatalogPage', () => {
it('should render the default actions of an item in the grid', async () => {
await renderWrapped(<DefaultCatalogPage />);
fireEvent.click(screen.getByTestId('user-picker-owned'));
await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/Owned components \(1\)/),
).resolves.toBeInTheDocument();
await expect(screen.findByTitle(/View/)).resolves.toBeInTheDocument();
await expect(screen.findByTitle(/Edit/)).resolves.toBeInTheDocument();
await expect(
Expand Down Expand Up @@ -235,7 +237,9 @@ describe('DefaultCatalogPage', () => {

await renderWrapped(<DefaultCatalogPage actions={actions} />);
fireEvent.click(screen.getByTestId('user-picker-owned'));
await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/Owned components \(1\)/),
).resolves.toBeInTheDocument();
await expect(screen.findByTitle(/Foo Action/)).resolves.toBeInTheDocument();
await expect(screen.findByTitle(/Bar Action/)).resolves.toBeInTheDocument();
await expect(
Expand All @@ -249,34 +253,46 @@ describe('DefaultCatalogPage', () => {
it('should render', async () => {
await renderWrapped(<DefaultCatalogPage />);
fireEvent.click(screen.getByTestId('user-picker-owned'));
await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/Owned components \(1\)/),
).resolves.toBeInTheDocument();
fireEvent.click(screen.getByTestId('user-picker-all'));
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/All components \(2\)/),
).resolves.toBeInTheDocument();
}, 20_000);

it('should set initial filter correctly', async () => {
await renderWrapped(<DefaultCatalogPage initiallySelectedFilter="all" />);
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/All components \(2\)/),
).resolves.toBeInTheDocument();
}, 20_000);

// this test is for fixing the bug after favoriting an entity, the matching
// entities defaulting to "owned" filter and not based on the selected filter
it('should render the correct entities filtered on the selected filter', async () => {
await renderWrapped(<DefaultCatalogPage />);
fireEvent.click(screen.getByTestId('user-picker-owned'));
await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/Owned components \(1\)/),
).resolves.toBeInTheDocument();
// The "Starred" menu option should initially be disabled, since there
// aren't any starred entities.
expect(screen.getByTestId('user-picker-starred')).toHaveAttribute(
'aria-disabled',
'true',
);
fireEvent.click(screen.getByTestId('user-picker-all'));
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/All components \(2\)/),
).resolves.toBeInTheDocument();

const starredIcons = await screen.findAllByTitle('Add to favorites');
fireEvent.click(starredIcons[0]);
await expect(screen.findByText(/All \(2\)/)).resolves.toBeInTheDocument();
await expect(
screen.findByText(/All components \(2\)/),
).resolves.toBeInTheDocument();

// Now that we've starred an entity, the "Starred" menu option should be
// enabled.
Expand All @@ -286,7 +302,7 @@ describe('DefaultCatalogPage', () => {
);
fireEvent.click(screen.getByTestId('user-picker-starred'));
await expect(
screen.findByText(/Starred \(1\)/),
screen.findByText(/Starred components \(1\)/),
).resolves.toBeInTheDocument();
}, 20_000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ describe('CatalogTable component', () => {
() => false,
() => false,
),
kind: {
value: 'component',
getCatalogFilters: () => ({ kind: 'component' }),
toQueryValue: () => 'component',
},
},
}}
>
Expand All @@ -107,7 +112,7 @@ describe('CatalogTable component', () => {
},
},
);
expect(screen.getByText(/Owned \(3\)/)).toBeInTheDocument();
expect(screen.getByText(/Owned components \(3\)/)).toBeInTheDocument();
expect(screen.getByText(/component1/)).toBeInTheDocument();
expect(screen.getByText(/component2/)).toBeInTheDocument();
expect(screen.getByText(/component3/)).toBeInTheDocument();
Expand Down
8 changes: 7 additions & 1 deletion plugins/catalog/src/components/CatalogTable/CatalogTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { capitalize } from 'lodash';
import React, { ReactNode, useMemo } from 'react';
import { columnFactories } from './columns';
import { CatalogTableRow } from './types';
import pluralize from 'pluralize';

/**
* Props for {@link CatalogTable}.
Expand Down Expand Up @@ -226,6 +227,11 @@ export const CatalogTable = (props: CatalogTableProps) => {
typeColumn.hidden = !showTypeColumn;
}
const showPagination = rows.length > 20;
const currentKind = filters.kind?.value || '';
const currentType = filters.type?.value || '';
const titleDisplay = [titlePreamble, currentType, pluralize(currentKind)]
.filter(s => s)
.join(' ');

return (
<Table<CatalogTableRow>
Expand All @@ -241,7 +247,7 @@ export const CatalogTable = (props: CatalogTableProps) => {
pageSizeOptions: [20, 50, 100],
...tableOptions,
}}
title={`${titlePreamble} (${entities.length})`}
title={`${titleDisplay} (${entities.length})`}
data={rows}
actions={actions || defaultActions}
subtitle={subtitle}
Expand Down

0 comments on commit 5b38139

Please sign in to comment.