@@ -3,7 +3,7 @@ import React, {useState, useRef, useEffect, useContext} from 'react';
3
3
import styled from 'styled-components' ;
4
4
import { MdHistory } from "react-icons/md" ;
5
5
import { SetModalResourceContext } from './Modal' ;
6
- import { ResourceDisplayName , ResourceWithDisplayName , VersionedResource } from './types' ;
6
+ import { ResourceDisplayName , Resource } from './types' ;
7
7
import { IconType } from 'react-icons' ;
8
8
9
9
export const LINK_COLOR = '#5097BA'
@@ -19,13 +19,15 @@ export const LINK_HOVER_COLOR = '#31586c'
19
19
const [ resourceFontSize , namePxPerChar , summaryPxPerChar ] = [ 16 , 10 , 9 ] ;
20
20
const iconWidth = 20 ; // not including text
21
21
const gapSize = 10 ;
22
- export const getMaxResourceWidth = ( displayResources : ResourceWithDisplayName [ ] ) => {
22
+ export const getMaxResourceWidth = ( displayResources : Resource [ ] ) => {
23
23
return displayResources . reduce ( ( w , r ) => {
24
+ if ( ! r . displayName || ! r . updateCadence ) return w
25
+
24
26
/* add the pixels for the display name */
25
27
let _w = r . displayName . default . length * namePxPerChar ;
26
28
if ( r . nVersions ) {
27
29
_w += gapSize + iconWidth ;
28
- _w += ( ( r ? .updateCadence ? .summary ? .length || 0 ) + 5 + String ( r . nVersions ) . length ) * summaryPxPerChar ;
30
+ _w += ( ( r . updateCadence . summary . length || 0 ) + 5 + String ( r . nVersions ) . length ) * summaryPxPerChar ;
29
31
}
30
32
return _w > w ? _w : w ;
31
33
} , 200 ) ; // 200 (pixels) is the minimum
@@ -107,7 +109,7 @@ export function IconContainer({Icon, text, handleClick, color, hoverColor}: Icon
107
109
108
110
109
111
interface IndividualResourceProps {
110
- resource : ResourceWithDisplayName
112
+ resource : Resource
111
113
isMobile : boolean
112
114
}
113
115
@@ -119,30 +121,35 @@ export const IndividualResource = ({resource, isMobile}: IndividualResourceProps
119
121
if ( ! ref . current ) return ;
120
122
/* The column CSS is great but doesn't allow us to know if an element is at
121
123
the top of its column, so we resort to JS */
124
+
125
+ /* offsetTop is not available on ParentNode but we know that the parent node
126
+ is an HTMLElement */
122
127
if ( ref . current . offsetTop === ( ref . current . parentNode as HTMLElement ) . offsetTop ) {
123
128
setTopOfColumn ( true ) ;
124
129
}
125
130
} , [ ] ) ;
126
131
132
+ if ( ! setModalResource || ! resource . displayName || ! resource . updateCadence ) return null
133
+
127
134
return (
128
135
< Container ref = { ref } >
129
136
130
137
< FlexRow >
131
138
132
139
< TooltipWrapper description = { `Last known update on ${ resource . lastUpdated } ` } >
133
- < ResourceLinkWrapper onShiftClick = { ( ) => setModalResource && setModalResource ( resource as VersionedResource ) } >
140
+ < ResourceLinkWrapper onShiftClick = { ( ) => setModalResource ( resource ) } >
134
141
< Name displayName = { resource . displayName } href = { resource . url } topOfColumn = { topOfColumn } />
135
142
</ ResourceLinkWrapper >
136
143
</ TooltipWrapper >
137
144
138
145
{ resource . versioned && ! isMobile && (
139
- < TooltipWrapper description = { ( resource as VersionedResource ) . updateCadence . description +
146
+ < TooltipWrapper description = { resource . updateCadence . description +
140
147
`<br/>Last known update on ${ resource . lastUpdated } ` +
141
148
`<br/>${ resource . nVersions } snapshots of this dataset available (click to see them)` } >
142
149
< IconContainer
143
150
Icon = { MdHistory }
144
- text = { `${ ( resource as VersionedResource ) . updateCadence . summary } (n=${ resource . nVersions } )` }
145
- handleClick = { ( ) => setModalResource && setModalResource ( resource as VersionedResource ) }
151
+ text = { `${ resource . updateCadence . summary } (n=${ resource . nVersions } )` }
152
+ handleClick = { ( ) => setModalResource ( resource ) }
146
153
/>
147
154
</ TooltipWrapper >
148
155
) }
0 commit comments