Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 404 page for entity not found in catalog #2623

Merged
merged 5 commits into from Sep 29, 2020
Merged

feat: 404 page for entity not found in catalog #2623

merged 5 commits into from Sep 29, 2020

Conversation

BA1RY
Copy link
Contributor

@BA1RY BA1RY commented Sep 25, 2020

Hey, I just made a Pull Request!

Addresses #2266

Task: Creation of 404 page for Entity not found

Solution: Created EntityNotFound component for catalog which displays the 404 page when entity is not found.

To test the page:
Visit url http://localhost:3000/catalog/Component/xyz (where xyz component doesn't exist).

Screenshot:
Screenshot from 2020-09-26 00-05-26

✔️ Checklist

  • All tests are passing yarn test
  • Screenshots attached (for UI changes)
  • Relevant documentation updated
  • Prettier run on changed files
  • Tests added for new functionality
  • Regression tests added for bug fixes

@BA1RY BA1RY requested a review from a team as a code owner September 25, 2020 18:47
@stefanalund
Copy link
Contributor

I think you should remove both the header and the ContentHeader in this case.

@BA1RY
Copy link
Contributor Author

BA1RY commented Sep 26, 2020

@stefanalund I can do that.
@shmidt-i Should I make the change that @stefanalund suggested?

@benjdlambert
Copy link
Member

@BA1RY go ahead 👍

@BA1RY
Copy link
Contributor Author

BA1RY commented Sep 28, 2020

@stefanalund I've made the changes you've suggested. Let me know if there are any corrections.

Screenshot from 2020-09-28 23-28-45

}, REDIRECT_DELAY);
}
// Commenting to check EntityNotFound page
// if (error || (!loading && !entity)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shmidt-i Can this code block be removed now that we are not redirecting to /catalog when entity isn't found?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please remove them and then we can merge!

}, REDIRECT_DELAY);
}
// Commenting to check EntityNotFound page
// if (error || (!loading && !entity)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please remove them and then we can merge!

@@ -20,7 +20,7 @@ import { catalogApiRef } from '../api/types';
import { useAsync } from 'react-use';
import { Entity } from '@backstage/catalog-model';

const REDIRECT_DELAY = 2000;
// const REDIRECT_DELAY = 2000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove.

},
}));

export const EntityNotFound: FC<{}> = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BA1RY
Copy link
Contributor Author

BA1RY commented Sep 29, 2020

@stefanalund I've made the changes you've asked for.

Copy link
Contributor

@shmidt-i shmidt-i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on the component! Integration needs some more attention, wrote couple of pointers to follow ;)

@@ -47,7 +48,7 @@ const DefaultEntityPage = () => (
const EntityPageSwitch = ({ EntityPage }: { EntityPage: ComponentType }) => {
const { entity } = useEntity();
// Loading and error states
if (!entity) return <EntityPageLayout />;
if (!entity) return <EntityNotFound />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, that's probably not gonna work nicely. Now there is going to be a flickering when entity is being loaded, so the EntityNotFound will be first to show, then immediately after we get an entity it will be replaced with an EntityPageLayout.
You need to decouple loading from the error state, if loading then just return <EntityPageLayout/>.
https://github.com/spotify/backstage/blob/0d33fdba1e278da69c1b81bae4d4d433ac19377b/plugins/catalog/src/hooks/useEntity.ts#L70
You can also make useEntity hook to return if the entity is loading/error. (keep in mind that there is also case where the entity hasn't been fetched yet, hence loading: false, entity: undefined, error: undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shmidt-i I've made the changes. Please check it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, now some type fixes and can merge ! 😃

@@ -58,6 +58,8 @@ export const useEntityFromUrl = (): EntityLoadingStatus => {
* Always going to return an entity, or throw an error if not a descendant of a EntityProvider.
*/
export const useEntity = () => {
const { entity } = useContext<{ entity: Entity }>(EntityContext as any);
return { entity };
const { entity, loading, error } = useContext<EntityLoadingStatus>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shmidt-i I noticed that since entity is optional in EntityLoadingStatus it is giving error. If we pass { entity: Entity; loading: boolean; error: Error; } instead of EntityLoadingStatus to useContext, the error is resolved. Should I make that change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's start with that 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you literally just covered the entity is not there case :)

Copy link
Contributor Author

@BA1RY BA1RY Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've made the changes. Please check it

Copy link
Contributor

@shmidt-i shmidt-i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@shmidt-i shmidt-i merged commit 126b216 into backstage:master Sep 29, 2020
@BA1RY BA1RY deleted the feat/entity-404-page-2266 branch September 29, 2020 19:08
taras added a commit to taras/backstage that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants