Skip to content

Commit

Permalink
Adds EmptyState with title No Resource Found
Browse files Browse the repository at this point in the history
This patch adds EmptyState with title `No Resource Found`
if selected filter doesn't match to any resources

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Jan 8, 2021
1 parent d0849ef commit 026f6c0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ui/src/containers/Resources/Resources.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
bottom: 0;
margin: auto;
}

.hub-resource-emptystate__margin {
margin-left: -12em;
}
32 changes: 31 additions & 1 deletion ui/src/containers/Resources/Resources.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { mount } from 'enzyme';
import { when } from 'mobx';
import { GalleryItem } from '@patternfly/react-core';
import { EmptyState, GalleryItem } from '@patternfly/react-core';
import { BrowserRouter as Router } from 'react-router-dom';
import { FakeHub } from '../../api/testutil';
import { createProviderAndStore } from '../../store/root';
Expand Down Expand Up @@ -47,4 +47,34 @@ describe('Resource Component', () => {
}
);
});

it('should find EmptyState if filtered does not match to any resources', (done) => {
const component = mount(
<Provider>
<Router>
<Resources />
</Router>
</Provider>
);

const { resources } = root;
when(
() => {
return !resources.isLoading;
},
() => {
setTimeout(() => {
resources.setSearch('asdf');
const resource = resources.filteredResources;
expect(resource.length).toBe(0);

component.update();
const r = component.find(EmptyState);
expect(r.length).toEqual(1);

done();
}, 0);
}
);
});
});
25 changes: 23 additions & 2 deletions ui/src/containers/Resources/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import React from 'react';
import { Gallery, Spinner } from '@patternfly/react-core';
import { useMst } from '../../store/root';
import { useObserver } from 'mobx-react';
import {
EmptyState,
EmptyStateIcon,
EmptyStateVariant,
Gallery,
Spinner,
Title
} from '@patternfly/react-core';
import CubesIcon from '@patternfly/react-icons/dist/js/icons/cubes-icon';
import { useMst } from '../../store/root';
import Cards from '../../components/Cards';
import './Resources.css';

const Resources = () => {
const { resources } = useMst();

const resourceNotFound = () => {
return (
<EmptyState variant={EmptyStateVariant.full} className="hub-resource-emptystate__margin">
<EmptyStateIcon icon={CubesIcon} />
<Title headingLevel="h5" size="md">
No Resource Found.
</Title>
</EmptyState>
);
};

return useObserver(() =>
resources.isLoading ? (
<Spinner className="hub-spinner" />
) : !resources.filteredResources.length ? (
resourceNotFound()
) : (
<React.Fragment>
<Gallery hasGutter className="hub-resource">
Expand Down

0 comments on commit 026f6c0

Please sign in to comment.