1- import React , { useEffect , useState } from 'react' ;
21import PropTypes from 'prop-types' ;
2+ import React , { useEffect , useState } from 'react' ;
33import { Tab , TabPanel } from 'react-tabs' ;
4- import { getPlutoItemById } from " ../../../services/PlutoApi" ;
5- import PlutoProjectLink from " ../../../components/Pluto/PlutoProjectLink" ;
4+ import PlutoProjectLink from ' ../../../components/Pluto/PlutoProjectLink' ;
5+ import { getPlutoItemById } from ' ../../../services/PlutoApi' ;
66
77export class PlutoTab extends React . Component {
88 static tabsRole = Tab . tabsRole ;
99
1010 render ( ) {
11- return (
12- < Tab { ...this . props } >
13- Pluto
14- </ Tab >
15- ) ;
11+ return < Tab { ...this . props } > Pluto</ Tab > ;
1612 }
1713}
1814
@@ -29,35 +25,46 @@ export class PlutoTabPanel extends React.Component {
2925 return (
3026 < TabPanel { ...rest } >
3127 < div className = "form__group" >
32- {
33- video . plutoData &&
34- < PlutoProjectLink projectId = { video . plutoData . projectId } />
35- }
28+ { video . plutoData && (
29+ < PlutoProjectLink projectId = { video . plutoData . projectId } />
30+ ) }
3631
3732 < header className = "video__detailbox__header" > Commission</ header >
38- < ReadOnlyPlutoItem id = { video . plutoData && video . plutoData . commissionId } itemType = "commission" />
33+ < ReadOnlyPlutoItem
34+ id = { video . plutoData ?. commissionId }
35+ itemType = "commissions"
36+ />
3937
4038 < header className = "video__detailbox__header" > Project</ header >
41- < ReadOnlyPlutoItem id = { video . plutoData && video . plutoData . projectId } itemType = "project" />
42-
39+ < ReadOnlyPlutoItem
40+ id = { video . plutoData ?. projectId }
41+ itemType = "projects"
42+ />
4343 </ div >
4444 </ TabPanel >
4545 ) ;
4646 }
4747}
4848
49- const ReadOnlyPlutoItem = ( { id, itemType} ) => {
49+ /**
50+ *
51+ * @param {{id: string, itemType: import('../../../services/PlutoApi').PlutoItemType} } param0
52+ * @returns
53+ */
54+ const ReadOnlyPlutoItem = ( { id, itemType } ) => {
55+ const [ title , setTitle ] = useState ( id ? 'Loading...' : '' ) ;
5056
51- const [ title , setTitle ] = useState ( id ? "Loading..." : "" ) ;
52-
53- if ( id ) {
54- useEffect ( ( ) => {
55- getPlutoItemById ( id , itemType ) . then ( data => setTitle ( data . title ) ) . catch ( e => {
56- const errorMessage = `Failed to lookup ${ itemType } with ID '${ id } '` ;
57- console . error ( errorMessage , e ) ;
58- setTitle ( errorMessage ) ;
59- } ) ; } , [ ] ) ;
60- }
57+ useEffect ( ( ) => {
58+ if ( id ) {
59+ getPlutoItemById ( id , itemType )
60+ . then ( data => setTitle ( data . title ) )
61+ . catch ( e => {
62+ const errorMessage = `Failed to lookup ${ itemType } with ID '${ id } '` ;
63+ console . error ( errorMessage , e ) ;
64+ setTitle ( errorMessage ) ;
65+ } ) ;
66+ }
67+ } , [ id , itemType ] ) ;
6168
6269 return < p className = "details-list__field" > { title } </ p > ;
6370} ;
0 commit comments