@@ -85,24 +85,6 @@ export function TopologyCard({
8585 [ size ]
8686 ) ;
8787
88- const canShowChildHealth = ( ) => {
89- let totalCount = 0 ;
90- if ( topology ?. summary ?. checks ) {
91- topology . summary . checks . healthy = topology . summary . checks . healthy || 0 ;
92- topology . summary . checks . unhealthy =
93- topology . summary . checks . unhealthy || 0 ;
94- topology . summary . checks . warning = topology . summary . checks . warning || 0 ;
95- Object . keys ( topology . summary . checks ) . forEach ( ( key ) => {
96- totalCount +=
97- topology . summary ?. checks ?. [ key as keyof Topology [ "summary" ] ] || 0 ;
98- } ) ;
99- }
100- return (
101- ! topology ?. components ?. length &&
102- ( ! topology ?. is_leaf || ( topology . is_leaf && totalCount !== 1 ) )
103- ) ;
104- } ;
105-
10688 const prepareTopologyLink = ( topologyItem : Topology ) => {
10789 if ( topologyItem . id === parentId && parentId ) {
10890 return "" ;
@@ -143,17 +125,44 @@ export function TopologyCard({
143125 [ topology ?. components ]
144126 ) ;
145127
128+ const { heading, properties, isPropertiesPanelEmpty } = useMemo ( ( ) => {
129+ const allProperties = topology ?. properties || [ ] ;
130+ const properties = allProperties . filter ( ( i ) => ! i . headline ) ;
131+
132+ const heading = allProperties . filter (
133+ ( i ) => i . headline && ( ! ! i . value || ! ! i . text || ! ! i . url )
134+ ) ;
135+
136+ const isPropertiesPanelShown =
137+ properties . filter (
138+ ( i ) => ! i . headline && i . type !== "hidden" && ( i . text || i . value )
139+ ) . length > 0 ;
140+
141+ return {
142+ heading,
143+ properties,
144+ isPropertiesPanelEmpty : ! isPropertiesPanelShown
145+ } ;
146+ } , [ topology ?. properties ] ) ;
147+
148+ const isAnalyticsPanelEmpty = useMemo ( ( ) => {
149+ // if there are no insights, checks or components, we don't need to show the
150+ // second panel at all
151+ return (
152+ ! topology ?. summary ?. insights &&
153+ ! topology ?. summary ?. checks &&
154+ ( sortedTopologyComponents ?? [ ] ) . length === 0
155+ ) ;
156+ } , [
157+ sortedTopologyComponents ,
158+ topology ?. summary ?. checks ,
159+ topology ?. summary ?. insights
160+ ] ) ;
161+
146162 if ( topology == null ) {
147163 return < TopologyCardSkeletonLoader /> ;
148164 }
149165
150- const allProperties = topology . properties || [ ] ;
151- const properties = allProperties . filter ( ( i ) => ! i . headline ) ;
152-
153- const heading = allProperties . filter (
154- ( i ) => i . headline && ( ! ! i . value || ! ! i . text || ! ! i . url )
155- ) ;
156-
157166 return (
158167 < div
159168 style = { { width : CardWidth [ size as Size ] || size } }
@@ -224,42 +233,43 @@ export function TopologyCard({
224233 </ div >
225234 </ div >
226235 < div className = "flex flex-nowrap space-x-4 rounded-b-8px bg-lightest-gray" >
227- { metricsInFooter ? (
236+ { metricsInFooter && heading . length > 0 ? (
228237 < div className = "flex flex-1 py-4" >
229238 < CardMetrics items = { heading } />
230239 </ div >
231240 ) : (
232241 < >
233- < TopologyCardPropertiesColumn properties = { properties } />
234- < CustomScroll
235- className = "flex-1 space-y-1.5 py-2 pl-2 pr-2"
236- showMoreClass = "text-xs linear-1.21rel mr-1 cursor-pointer"
237- maxHeight = "200px"
238- minChildCount = { 5 }
239- >
240- < TopologyConfigAnalysisLine topology = { topology } />
241- { canShowChildHealth ( ) && (
242- < HealthSummary
243- className = ""
244- target = { target }
245- key = { topology . id }
246- component = { topology }
247- />
248- ) }
249- < HealthChecksSummary
250- checks = { topology ?. summary ?. checks }
251- className = ""
252- />
253- { topology ?. id && < IncidentCardSummary topology = { topology } /> }
254- { sortedTopologyComponents ?. map ( ( component : any ) => (
255- < HealthSummary
242+ < TopologyCardPropertiesColumn
243+ displayTwoColumns = { isAnalyticsPanelEmpty }
244+ properties = { properties }
245+ />
246+ { ! isAnalyticsPanelEmpty && (
247+ < CustomScroll
248+ className = { clsx (
249+ "flex-1 py-2 pl-2 pr-2" ,
250+ isPropertiesPanelEmpty ? "grid grid-cols-2 gap-1" : ""
251+ ) }
252+ showMoreClass = "text-xs linear-1.21rel mr-1 cursor-pointer"
253+ maxHeight = "200px"
254+ // When we showing two columns, we need to show more items
255+ minChildCount = { isPropertiesPanelEmpty ? 5 : 10 }
256+ >
257+ < TopologyConfigAnalysisLine topology = { topology } />
258+ < HealthChecksSummary
259+ checks = { topology ?. summary ?. checks }
256260 className = ""
257- target = { target }
258- key = { component . id }
259- component = { component }
260261 />
261- ) ) }
262- </ CustomScroll >
262+ { sortedTopologyComponents ?. map ( ( component : any ) => (
263+ < HealthSummary
264+ className = ""
265+ target = { target }
266+ key = { component . id }
267+ component = { component }
268+ />
269+ ) ) }
270+ { topology ?. id && < IncidentCardSummary topology = { topology } /> }
271+ </ CustomScroll >
272+ ) }
263273 </ >
264274 ) }
265275 </ div >
0 commit comments