1- import React , { FC } from 'react'
2- import { useSelector } from 'react-redux'
1+ import React , { FC , useEffect } from 'react'
2+ import { useSelector , useDispatch } from 'react-redux'
33import { Link } from 'react-router-dom'
44
55import {
@@ -20,7 +20,6 @@ import {
2020} from '@influxdata/clockface'
2121
2222import { pageTitleSuffixer } from 'src/shared/utils/pageTitles'
23- import { getOrg } from 'src/organizations/selectors'
2423import {
2524 CLIIcon ,
2625 GoIcon ,
@@ -38,11 +37,21 @@ import UsageProvider from 'src/usage/context/usage'
3837import Resources from 'src/me/components/Resources'
3938import RateLimitAlert from 'src/cloud/components/RateLimitAlert'
4039
40+ // Selectors
41+ import { getOrg } from 'src/organizations/selectors'
42+ import { getAllTelegrafs } from 'src/resources/selectors'
43+
44+ // Thunks
45+ import { getTelegrafs } from 'src/telegrafs/actions/thunks'
46+
4147export const HomepageContainer : FC = ( ) => {
48+ const dispatch = useDispatch ( )
4249 const org = useSelector ( getOrg )
50+ const telegrafs = useSelector ( getAllTelegrafs )
4351 const pythonWizardLink = `/orgs/${ org . id } /new-user-setup/python`
4452 const cliPageLink = `/orgs/${ org . id } /load-data/file-upload/csv`
4553 const telegrafPageLink = `/orgs/${ org . id } /load-data/telegrafs`
54+ const newTelegrafPageLink = `/orgs/${ org . id } /load-data/telegrafs/new`
4655 const golangLink = `/orgs/${ org . id } /new-user-setup/golang`
4756 const loadDataSourcesLink = `/orgs/${ org . id } /load-data/sources`
4857 const javaScriptNodeLink = `/orgs/${ org . id } /new-user-setup/nodejs`
@@ -53,6 +62,17 @@ export const HomepageContainer: FC = () => {
5362
5463 const squareGridCardSize = '200px'
5564
65+ useEffect ( ( ) => {
66+ dispatch ( getTelegrafs )
67+ } , [ telegrafs ] ) // eslint-disable-line react-hooks/exhaustive-deps
68+
69+ const telegrafLink = ( ) => {
70+ if ( ! telegrafs . length ) {
71+ return newTelegrafPageLink
72+ }
73+ return telegrafPageLink
74+ }
75+
5676 // events handling
5777 const logGoWizardClick = ( ) => {
5878 event ( 'firstMile.goWizard.clicked' )
@@ -187,7 +207,7 @@ export const HomepageContainer: FC = () => {
187207 </ div >
188208 </ Link >
189209 < Link
190- to = { telegrafPageLink }
210+ to = { telegrafLink }
191211 style = { linkStyle }
192212 onClick = { logTelegrafButtonClick }
193213 >
0 commit comments