1- import React from 'react' ;
2- import { useParams } from 'react-router' ;
1+ import React , { useEffect } from 'react' ;
2+ import { useHistory , useParams } from 'react-router' ;
33import styled from 'styled-components' ;
4+ import { LoadingOutlined } from '@ant-design/icons' ;
45import { ErrorSection } from '../../shared/error/ErrorSection' ;
56import useGetEntityByUrl from './useGetEntityByUrl' ;
67import LookupNotFound from './LookupNotFound' ;
78import LookupFoundMultiple from './LookupFoundMultiple' ;
8- import LookupLoading from './LookupLoading' ;
9- import GoToLookup from './GoToLookup' ;
10-
11- type RouteParams = {
12- url : string ;
13- } ;
149
1510const PageContainer = styled . div `
1611 display: flex;
@@ -19,17 +14,29 @@ const PageContainer = styled.div`
1914 height: 85vh;
2015` ;
2116
17+ const LookupLoading = styled ( LoadingOutlined ) `
18+ font-size: 50px;
19+ ` ;
20+
21+ type RouteParams = {
22+ url : string ;
23+ } ;
24+
2225const EmbedLookup = ( ) => {
26+ const history = useHistory ( ) ;
2327 const { url : encodedUrl } = useParams < RouteParams > ( ) ;
2428 const decodedUrl = decodeURIComponent ( encodedUrl ) ;
25- const { count, entity, error, loading } = useGetEntityByUrl ( decodedUrl ) ;
29+ const { embedUrl, notFound, foundMultiple, error } = useGetEntityByUrl ( decodedUrl ) ;
30+
31+ useEffect ( ( ) => {
32+ if ( embedUrl ) history . push ( embedUrl ) ;
33+ } , [ embedUrl , history ] ) ;
2634
2735 const getContent = ( ) => {
28- if ( loading ) return < LookupLoading /> ;
2936 if ( error ) return < ErrorSection /> ;
30- if ( count === 0 || ! entity ) return < LookupNotFound url = { encodedUrl } /> ;
31- if ( count > 1 ) return < LookupFoundMultiple url = { encodedUrl } /> ;
32- return < GoToLookup entityType = { entity . type } entityUrn = { entity . urn } /> ;
37+ if ( notFound ) return < LookupNotFound url = { encodedUrl } /> ;
38+ if ( foundMultiple ) return < LookupFoundMultiple url = { encodedUrl } /> ;
39+ return < LookupLoading /> ;
3340 } ;
3441
3542 return < PageContainer > { getContent ( ) } </ PageContainer > ;
0 commit comments