Skip to content

Commit db0ebb6

Browse files
authored
fix: use correct resource card height when AssetLimitAlert is first in a row (#4631)
1 parent 7b15786 commit db0ebb6

File tree

3 files changed

+77
-31
lines changed

3 files changed

+77
-31
lines changed

src/cloud/components/AssetLimitAlert.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC} from 'react'
2+
import React, {CSSProperties, FC} from 'react'
33

44
// Components
55
import {
@@ -34,15 +34,22 @@ interface Props {
3434
limitStatus: LimitStatus['status']
3535
resourceName: string
3636
className?: string
37+
style?: CSSProperties
3738
}
3839

39-
const AssetLimitAlert: FC<Props> = ({limitStatus, resourceName, className}) => {
40+
const AssetLimitAlert: FC<Props> = ({
41+
limitStatus,
42+
resourceName,
43+
className,
44+
style = {},
45+
}) => {
4046
if (CLOUD && limitStatus === 'exceeded') {
4147
return (
4248
<GradientBox
4349
borderGradient={Gradients.MiyazakiSky}
4450
borderColor={InfluxColors.Grey5}
4551
className={className}
52+
style={{...style}}
4653
>
4754
<Panel backgroundColor={InfluxColors.Grey5} className="asset-alert">
4855
<Panel.Header>

src/dashboards/components/dashboard_index/DashboardCards.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import memoizeOne from 'memoize-one'
55

66
// Components
77
import DashboardCard from 'src/dashboards/components/dashboard_index/DashboardCard'
8-
import {TechnoSpinner} from '@influxdata/clockface'
8+
import {ResourceCard, TechnoSpinner} from '@influxdata/clockface'
99
import AssetLimitAlert from 'src/cloud/components/AssetLimitAlert'
1010

1111
// Selectors
@@ -60,6 +60,9 @@ class DashboardCards extends PureComponent<Props> {
6060
private _observer
6161
private _isMounted = true
6262
private _spinner
63+
private _assetLimitAlertStyle = {
64+
height: 'inherit',
65+
}
6366

6467
private memGetSortedResources = memoizeOne<typeof getSortedResources>(
6568
getSortedResources
@@ -69,6 +72,7 @@ class DashboardCards extends PureComponent<Props> {
6972
pages: 1,
7073
windowSize: 0,
7174
pinnedItems: [],
75+
dashboardCardHeight: 'inherit',
7276
}
7377

7478
public componentDidMount() {
@@ -78,6 +82,17 @@ class DashboardCards extends PureComponent<Props> {
7882
this.setState(prev => ({...prev, windowSize: 15}))
7983
}
8084

85+
public componentDidUpdate() {
86+
const card = document.querySelector<HTMLElement>(
87+
'.dashboards-card-grid > .cf-resource-card'
88+
)
89+
if (card?.offsetHeight) {
90+
this.setState({
91+
dashboardCardHeight: `${card.offsetHeight}px`,
92+
})
93+
}
94+
}
95+
8196
public componentWillUnmount() {
8297
this._isMounted = false
8398
}
@@ -205,11 +220,16 @@ class DashboardCards extends PureComponent<Props> {
205220
}
206221
/>
207222
))}
208-
<AssetLimitAlert
209-
className="dashboards--asset-alert"
210-
resourceName="dashboards"
211-
limitStatus={this.props.limitStatus}
212-
/>
223+
{this.props.limitStatus === 'exceeded' && (
224+
<ResourceCard style={{height: this.state.dashboardCardHeight}}>
225+
<AssetLimitAlert
226+
className="dashboards--asset-alert"
227+
resourceName="dashboards"
228+
limitStatus={this.props.limitStatus}
229+
style={this._assetLimitAlertStyle}
230+
/>
231+
</ResourceCard>
232+
)}
213233
</div>
214234
{windowSize * pages < dashboards.length && (
215235
<div

src/dashboards/components/dashboard_index/DashboardCardsPaginated.tsx

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {connect, ConnectedProps} from 'react-redux'
55
// Components
66
import DashboardCard from 'src/dashboards/components/dashboard_index/DashboardCard'
77
import AssetLimitAlert from 'src/cloud/components/AssetLimitAlert'
8+
import {ResourceCard} from '@influxdata/clockface'
89

910
// Types
1011
import {AppState, Dashboard} from 'src/types'
@@ -51,9 +52,13 @@ type Props = OwnProps & StateProps & ReduxProps
5152

5253
class DashboardCards extends PureComponent<Props> {
5354
private _isMounted = true
55+
private _assetLimitAlertStyle = {
56+
height: 'inherit',
57+
}
5458

5559
state = {
5660
pinnedItems: [],
61+
dashboardCardHeight: 'inherit',
5762
}
5863

5964
public componentDidMount() {
@@ -62,6 +67,17 @@ class DashboardCards extends PureComponent<Props> {
6267
}
6368
}
6469

70+
public componentDidUpdate() {
71+
const card = document.querySelector<HTMLElement>(
72+
'.dashboards-card-grid > .cf-resource-card'
73+
)
74+
if (card?.offsetHeight) {
75+
this.setState({
76+
dashboardCardHeight: `${card.offsetHeight}px`,
77+
})
78+
}
79+
}
80+
6581
public componentWillUnmount() {
6682
this._isMounted = false
6783
}
@@ -72,30 +88,33 @@ class DashboardCards extends PureComponent<Props> {
7288
const {pinnedItems} = this.state
7389

7490
return (
75-
<div>
76-
<div className="dashboards-card-grid">
77-
{dashboards.map(({id, name, description, labels, meta}) => (
78-
<DashboardCard
79-
key={id}
80-
id={id}
81-
name={name}
82-
labels={labels}
83-
updatedAt={meta.updatedAt}
84-
description={description}
85-
onFilterChange={onFilterChange}
86-
onPinDashboard={this.handlePinDashboard}
87-
onUnpinDashboard={this.handleUnpinDashboard}
88-
isPinned={
89-
!!pinnedItems.find(item => item?.metadata.dashboardID === id)
90-
}
91-
/>
92-
))}
93-
<AssetLimitAlert
94-
className="dashboards--asset-alert"
95-
resourceName="dashboards"
96-
limitStatus={this.props.limitStatus}
91+
<div className="dashboards-card-grid">
92+
{dashboards.map(({id, name, description, labels, meta}) => (
93+
<DashboardCard
94+
key={id}
95+
id={id}
96+
name={name}
97+
labels={labels}
98+
updatedAt={meta.updatedAt}
99+
description={description}
100+
onFilterChange={onFilterChange}
101+
onPinDashboard={this.handlePinDashboard}
102+
onUnpinDashboard={this.handleUnpinDashboard}
103+
isPinned={
104+
!!pinnedItems.find(item => item?.metadata.dashboardID === id)
105+
}
97106
/>
98-
</div>
107+
))}
108+
{this.props.limitStatus === 'exceeded' && (
109+
<ResourceCard style={{height: this.state.dashboardCardHeight}}>
110+
<AssetLimitAlert
111+
className="dashboards--asset-alert"
112+
resourceName="dashboards"
113+
limitStatus={this.props.limitStatus}
114+
style={this._assetLimitAlertStyle}
115+
/>
116+
</ResourceCard>
117+
)}
99118
</div>
100119
)
101120
}

0 commit comments

Comments
 (0)