11// Libraries
22import React , { FC , useEffect } from 'react'
3- import { connect } from 'react-redux'
3+ import { useSelector , useDispatch } from 'react-redux'
44import classnames from 'classnames'
55
66// Components
@@ -23,13 +23,12 @@ import {
2323 extractRateLimitResources ,
2424 extractRateLimitStatus ,
2525} from 'src/cloud/utils/limits'
26+ import { event } from 'src/cloud/utils/reporting'
2627
2728// Constants
2829import { CLOUD } from 'src/shared/constants'
2930
3031// Types
31- import { AppState } from 'src/types'
32- import { LimitStatus } from 'src/cloud/actions/limits'
3332import RateLimitAlertContent from 'src/cloud/components/RateLimitAlertContent'
3433
3534import { notify } from 'src/shared/actions/notifications'
@@ -42,59 +41,50 @@ import {UpgradeContent} from 'src/cloud/components/RateLimitAlertContent'
4241
4342import './RateLimitAlert.scss'
4443
45- interface StateProps {
46- resources : string [ ]
47- status : LimitStatus [ 'status' ]
48- showUpgrade : boolean
49- }
50-
51- interface OwnProps {
44+ interface Props {
5245 alertOnly ?: boolean
5346 className ?: string
54- sendNotify : ( _ : any ) => void
55- handleShowOverlay : any
56- handleDismissOverlay : any
47+ location ?: string
5748}
58- type Props = StateProps & OwnProps
5949
60- const RateLimitAlert : FC < Props > = ( {
61- status,
62- alertOnly,
63- className,
64- resources,
65- showUpgrade,
66- sendNotify,
67- handleShowOverlay,
68- handleDismissOverlay,
69- } ) => {
50+ const RateLimitAlert : FC < Props > = ( { alertOnly, className, location} ) => {
51+ const resources = useSelector ( extractRateLimitResources )
52+ const status = useSelector ( extractRateLimitStatus )
53+ const showUpgrade = useSelector ( shouldShowUpgradeButton )
54+ const dispatch = useDispatch ( )
55+
7056 const appearOverlay = ( ) => {
71- handleShowOverlay ( 'write-limit' , null , handleDismissOverlay )
57+ dispatch ( showOverlay ( 'write-limit' , null , ( ) => dispatch ( dismissOverlay ) ) )
7258 }
7359
7460 useEffect ( ( ) => {
7561 if ( CLOUD && status === 'exceeded' && resources . includes ( 'write' ) ) {
7662 if ( showUpgrade ) {
77- sendNotify (
78- writeLimitReached (
79- '' ,
80- < UpgradeContent
81- type = "write"
82- link = "https://docs.influxdata.com/influxdb/v2.0/write-data/best-practices/optimize-writes/"
83- className = "flex-upgrade-content"
84- />
63+ dispatch (
64+ notify (
65+ writeLimitReached (
66+ '' ,
67+ < UpgradeContent
68+ type = "write"
69+ link = "https://docs.influxdata.com/influxdb/v2.0/write-data/best-practices/optimize-writes/"
70+ className = "flex-upgrade-content"
71+ />
72+ )
8573 )
8674 )
8775 } else {
88- sendNotify (
89- writeLimitReached (
90- "Data in has stopped because you've hit the query write limit. Let's get it flowing again: " ,
91- < Button
92- className = "rate-alert-overlay-button"
93- color = { ComponentColor . Primary }
94- size = { ComponentSize . Small }
95- onClick = { appearOverlay }
96- text = "Request Write Limit Increase"
97- />
76+ dispatch (
77+ notify (
78+ writeLimitReached (
79+ "Data in has stopped because you've hit the query write limit. Let's get it flowing again: " ,
80+ < Button
81+ className = "rate-alert-overlay-button"
82+ color = { ComponentColor . Primary }
83+ size = { ComponentSize . Small }
84+ onClick = { appearOverlay }
85+ text = "Request Write Limit Increase"
86+ />
87+ )
9888 )
9989 )
10090 }
@@ -126,27 +116,17 @@ const RateLimitAlert: FC<Props> = ({
126116 }
127117
128118 if ( CLOUD && ! alertOnly ) {
129- return < CloudUpgradeButton className = "upgrade-payg--button__header" />
119+ return (
120+ < CloudUpgradeButton
121+ className = "upgrade-payg--button__header"
122+ metric = { ( ) => {
123+ event ( 'rate limit upgrade' , { location} )
124+ } }
125+ />
126+ )
130127 }
131128
132129 return null
133130}
134131
135- const mstp = ( state : AppState ) => {
136- const resources = extractRateLimitResources ( state )
137- const status = extractRateLimitStatus ( state )
138- const showUpgrade = shouldShowUpgradeButton ( state )
139- return {
140- status,
141- resources,
142- showUpgrade,
143- }
144- }
145-
146- const mdtp = {
147- sendNotify : notify ,
148- handleShowOverlay : showOverlay ,
149- handleDismissOverlay : dismissOverlay ,
150- }
151-
152- export default connect ( mstp , mdtp ) ( RateLimitAlert )
132+ export default RateLimitAlert
0 commit comments