Skip to content

Commit

Permalink
Fix repo filter in Catalog (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Apr 8, 2020
1 parent 3fefc31 commit 1fc968b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 10 additions & 1 deletion dashboard/src/components/Catalog/Catalog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultChartState = {
} as IChartState;
const defaultProps = {
charts: defaultChartState,
repo: "stable",
repo: "",
filter: "",
fetchCharts: jest.fn(),
pushSearchFilter: jest.fn(),
Expand Down Expand Up @@ -313,6 +313,15 @@ describe("renderization", () => {
expect(wrapper.find(MessageAlert)).not.toExist();
expect(wrapper.find(".Catalog")).toExist();
});

it("should skip operators if the repo filter is used", () => {
const wrapper = shallow(
<Catalog {...defaultProps} charts={chartState} csvs={csvs} repo="test" />,
);
const cardGrid = wrapper.find(CardGrid);
expect(cardGrid).toExist();
expect(cardGrid.children().length).toBe(chartState.items.length);
});
});
});
});
19 changes: 13 additions & 6 deletions dashboard/src/components/Catalog/Catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ class Catalog extends React.Component<ICatalogProps, ICatalogState> {
/>
);
}
const filteredCharts = this.filteredCharts(allItems);
const filteredCSVs = this.filteredCSVs(csvs);
const catalogItems = this.getCatalogItems(filteredCharts, filteredCSVs);
if (!isFetching && catalogItems.length === 0) {
if (!isFetching && allItems.length === 0 && csvs.length === 0) {
return (
<MessageAlert
level={"warning"}
Expand All @@ -101,6 +98,9 @@ class Catalog extends React.Component<ICatalogProps, ICatalogState> {
/>
);
}
const filteredCharts = this.filteredCharts(allItems);
const filteredCSVs = this.shouldRenderOperators() ? this.filteredCSVs(csvs) : [];
const catalogItems = this.getCatalogItems(filteredCharts, filteredCSVs);
const items = catalogItems.map(c => (
<CatalogItem key={`${c.type}/${c.repoName || c.csv}/${c.name}`} item={c} />
));
Expand All @@ -118,7 +118,7 @@ class Catalog extends React.Component<ICatalogProps, ICatalogState> {
</PageHeader>
<LoadingWrapper loaded={!isFetching}>
<div className="row">
{csvs.length > 0 && (
{this.shouldRenderOperators() && (
<div className="col-2">
<div className="margin-b-normal">
<span>
Expand All @@ -143,7 +143,7 @@ class Catalog extends React.Component<ICatalogProps, ICatalogState> {
</div>
</div>
)}
<div className={csvs.length > 0 ? "col-10" : ""}>
<div className={this.shouldRenderOperators() ? "col-10" : ""}>
<CardGrid>{items}</CardGrid>
</div>
</div>
Expand Down Expand Up @@ -212,6 +212,13 @@ class Catalog extends React.Component<ICatalogProps, ICatalogState> {
filter,
});
};

// Render Operators only if there are Operators to render and if we are not
// filtering by repo
private shouldRenderOperators = () => {
const { csvs, repo } = this.props;
return csvs.length > 0 && !repo;
};
}

export default Catalog;

0 comments on commit 1fc968b

Please sign in to comment.