Skip to content

Commit 648a899

Browse files
feat: add the new telegraf refresh ui path from buckets card (#3203)
1 parent 2d705a3 commit 648a899

File tree

8 files changed

+105
-39
lines changed

8 files changed

+105
-39
lines changed

cypress/e2e/shared/buckets.test.ts

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ describe('Buckets', () => {
132132
})
133133

134134
describe('add data', function() {
135+
const TELEGRAF_SYSTEMS_PLUGINS_ORIGINAL_COUNT = 5
136+
135137
it('configure telegraf agent', () => {
138+
cy.setFeatureFlags({
139+
telegrafUiRefresh: true,
140+
})
136141
// click "add data" and choose Configure Telegraf Agent
137142
cy.getByTestID('add-data--button').click()
138143
cy.get('.bucket-add-data--option')
@@ -147,32 +152,45 @@ describe('Buckets', () => {
147152
)
148153
})
149154

150-
// filter plugins and choose system
155+
// many plugins with "sys" in their names have been added
151156
cy.getByTestID('input-field').type('sys')
152-
cy.getByTestID('square-grid--card').should('have.length', 1)
157+
cy.getByTestID('square-grid--card').should('have.length.greaterThan', 1)
153158
cy.getByTestID('input-field').clear()
154-
cy.getByTestID('square-grid--card').should('have.length', 5)
159+
160+
// total plugins should be greater than just the original Systems plugins
161+
cy.getByTestID('square-grid--card').should(
162+
'have.length.greaterThan',
163+
TELEGRAF_SYSTEMS_PLUGINS_ORIGINAL_COUNT
164+
)
155165
cy.getByTestID('telegraf-plugins--System').click()
156-
cy.getByTestID('next').click()
166+
cy.getByTestID('plugin-create-configuration-continue-configuring').click()
167+
168+
// cancel mid-flow and redo steps, ensuring user is still at Load Data > Buckets
169+
cy.get('button.cf-overlay--dismiss').click()
170+
cy.getByTestID('add-data--button').click()
171+
cy.get('.bucket-add-data--option')
172+
.contains('Configure Telegraf Agent')
173+
.click()
174+
cy.get<string>('@defaultBucket').then((defaultBucket: string) => {
175+
cy.getByTestID('bucket-dropdown--button').should(
176+
'contain',
177+
defaultBucket
178+
)
179+
})
180+
cy.getByTestID('telegraf-plugins--System').click()
181+
cy.getByTestID('plugin-create-configuration-continue-configuring').click()
157182

158183
// add telegraf name and description
159-
cy.getByTitle('Telegraf Configuration Name')
184+
cy.getByTestID('plugin-create-configuration-customize-input--name')
160185
.clear()
161186
.type('Telegraf from bucket')
162-
cy.getByTitle('Telegraf Configuration Description')
187+
cy.getByTestID('plugin-create-configuration-customize-input--description')
163188
.clear()
164189
.type('This is a telegraf description')
165-
cy.getByTestID('next').click()
190+
cy.getByTestID('plugin-create-configuration-save-and-test').click()
191+
192+
cy.getByTestID('notification-success').should('be.visible')
166193

167-
// assert notifications
168-
cy.getByTestID('notification-success').should(
169-
'contain',
170-
'Your configurations have been saved'
171-
)
172-
cy.getByTestID('notification-success').should(
173-
'contain',
174-
'Successfully created dashboards for telegraf plugin: system.'
175-
)
176194
cy.getByTestID('next').click()
177195

178196
// assert telegraf card parameters

src/buckets/components/BucketCardActions.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'
1616
// Actions
1717
import {addBucketLabel, deleteBucketLabel} from 'src/buckets/actions/thunks'
1818
import {setBucketInfo} from 'src/dataLoaders/actions/steps'
19-
import {setDataLoadersType} from 'src/dataLoaders/actions/dataLoaders'
19+
import {
20+
setDataLoadersType,
21+
setLocationOnDismiss,
22+
} from 'src/dataLoaders/actions/dataLoaders'
2023
import {event} from 'src/cloud/utils/reporting'
2124

2225
// Types
@@ -48,6 +51,7 @@ const BucketCardActions: FC<Props> = ({
4851
history,
4952
onSetDataLoadersBucket,
5053
onSetDataLoadersType,
54+
setLocationOnDismiss,
5155
}) => {
5256
if (bucketType === 'system') {
5357
return null
@@ -76,7 +80,8 @@ const BucketCardActions: FC<Props> = ({
7680
onSetDataLoadersBucket(orgID, bucket.name, bucket.id)
7781

7882
onSetDataLoadersType(DataLoaderType.Streaming)
79-
history.push(`/orgs/${orgID}/load-data/buckets/${bucket.id}/telegrafs/new`)
83+
setLocationOnDismiss(`/orgs/${orgID}/load-data/buckets`)
84+
history.push(`/orgs/${orgID}/load-data/telegrafs/new`)
8085
}
8186

8287
const handleAddLineProtocol = () => {
@@ -153,6 +158,7 @@ const mdtp = {
153158
onDeleteBucketLabel: deleteBucketLabel,
154159
onSetDataLoadersBucket: setBucketInfo,
155160
onSetDataLoadersType: setDataLoadersType,
161+
setLocationOnDismiss,
156162
}
157163

158164
const connector = connect(null, mdtp)

src/dataLoaders/actions/dataLoaders.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type Action =
8888
| SetTelegrafConfigName
8989
| SetTelegrafConfigDescription
9090
| SetToken
91+
| SetLocationOnDismiss
9192

9293
interface SetDataLoadersType {
9394
type: 'SET_DATA_LOADERS_TYPE'
@@ -669,3 +670,14 @@ export const saveScraperTarget = () => async (
669670
console.error()
670671
}
671672
}
673+
674+
interface SetLocationOnDismiss {
675+
type: 'SET_LOCATION_ON_DISMISS'
676+
payload: {locationOnDismiss: string}
677+
}
678+
export const setLocationOnDismiss = (
679+
locationOnDismiss: string
680+
): SetLocationOnDismiss => ({
681+
type: 'SET_LOCATION_ON_DISMISS',
682+
payload: {locationOnDismiss},
683+
})

src/dataLoaders/components/collectorsWizard/TelegrafUIRefreshWizard.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
clearSteps,
2727
decrementCurrentStepIndex,
2828
incrementCurrentStepIndex,
29-
setBucketInfo,
3029
setCurrentStepIndex,
3130
setSubstepIndex,
3231
} from 'src/dataLoaders/actions/steps'
@@ -60,10 +59,8 @@ class TelegrafUIRefreshWizard extends PureComponent<Props> {
6059
}
6160

6261
public componentDidMount() {
63-
this.props.clearDataLoaders()
6462
this.props.onSetCurrentStepIndex(0)
6563
this.props.onSetSubstepIndex(0, 0)
66-
this.props.setBucketInfo('', '', '')
6764
}
6865

6966
public render() {
@@ -99,12 +96,15 @@ class TelegrafUIRefreshWizard extends PureComponent<Props> {
9996
}
10097

10198
private handleDismiss = () => {
102-
const {history, org} = this.props
99+
const {history, locationOnDismiss, org} = this.props
103100
const {clearDataLoaders, onClearSteps} = this.props
104101
clearDataLoaders()
105102
onClearSteps()
106103
this.setState({isVisible: false})
107-
history.push(`/orgs/${org.id}/load-data/telegrafs`)
104+
const location = locationOnDismiss
105+
? locationOnDismiss
106+
: `/orgs/${org.id}/load-data/telegrafs`
107+
history.push(location)
108108
}
109109

110110
private handleSetIsValidConfiguration = (isValid: boolean) => {
@@ -150,7 +150,7 @@ class TelegrafUIRefreshWizard extends PureComponent<Props> {
150150
const mstp = (state: AppState) => {
151151
const {
152152
dataLoading: {
153-
dataLoaders: {telegrafPlugins},
153+
dataLoaders: {locationOnDismiss, telegrafPlugins},
154154
steps: {currentStep, substep = 0, bucket},
155155
},
156156
me: {name},
@@ -166,14 +166,15 @@ const mstp = (state: AppState) => {
166166
const org = getOrg(state)
167167

168168
return {
169-
telegrafPlugins,
170-
text: telegrafEditor.text,
171-
currentStepIndex: currentStep,
172-
substepIndex: typeof substep === 'number' ? substep : 0,
173-
username: name,
174169
bucket,
175170
buckets: nonSystemBuckets,
171+
currentStepIndex: currentStep,
172+
locationOnDismiss,
176173
org,
174+
substepIndex: typeof substep === 'number' ? substep : 0,
175+
telegrafPlugins,
176+
text: telegrafEditor.text,
177+
username: name,
177178
}
178179
}
179180

@@ -185,7 +186,6 @@ const mdtp = {
185186
onIncrementCurrentStepIndex: incrementCurrentStepIndex,
186187
onSetCurrentStepIndex: setCurrentStepIndex,
187188
onSetSubstepIndex: setSubstepIndex,
188-
setBucketInfo,
189189
}
190190

191191
const connector = connect(mstp, mdtp)

src/dataLoaders/components/collectorsWizard/select/TelegrafUIRefreshCollectorsStep.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ type Props = OwnProps & ReduxProps
3737

3838
@ErrorHandling
3939
export class SelectCollectorsStep extends PureComponent<Props, State> {
40-
state = {selectedBucketName: ''}
40+
constructor(props: Props) {
41+
super(props)
42+
const {bucketID, buckets} = this.props
43+
44+
const selectedBucketName =
45+
buckets.find(bucket => bucket.id === bucketID)?.name ?? ''
46+
this.state = {selectedBucketName}
47+
}
4148

4249
public componentDidUpdate() {
4350
const {setIsValidConfiguration} = this.props

src/dataLoaders/reducers/dataLoaders.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const INITIAL_STATE: DataLoadersState = {
3636
telegrafConfigName: 'Name this Configuration',
3737
telegrafConfigDescription: '',
3838
token: '',
39+
locationOnDismiss: '',
3940
}
4041

4142
export default (state = INITIAL_STATE, action: Action): DataLoadersState => {
@@ -316,6 +317,12 @@ export default (state = INITIAL_STATE, action: Action): DataLoadersState => {
316317
...state,
317318
token: action.payload.token,
318319
}
320+
321+
case 'SET_LOCATION_ON_DISMISS':
322+
return {
323+
...state,
324+
locationOnDismiss: action.payload.locationOnDismiss,
325+
}
319326
default:
320327
return state
321328
}

src/types/dataLoaders.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ interface ScraperTarget {
2424
}
2525

2626
export interface DataLoadersState {
27-
telegrafPlugins: TelegrafPlugin[]
27+
locationOnDismiss: string
2828
pluginBundles: BundleName[]
29-
type: DataLoaderType
30-
telegrafConfigID: string
3129
scraperTarget: ScraperTarget
32-
telegrafConfigName: string
3330
telegrafConfigDescription: string
31+
telegrafConfigID: string
32+
telegrafConfigName: string
33+
telegrafPlugins: TelegrafPlugin[]
3434
token: string
35+
type: DataLoaderType
3536
}
3637

3738
export enum ConfigurationState {

src/writeData/components/PluginCreateConfiguration/Footer.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ import {
1111
} from '@influxdata/clockface'
1212

1313
// Actions
14-
import {createOrUpdateTelegrafConfigAsync} from 'src/dataLoaders/actions/dataLoaders'
14+
import {
15+
createOrUpdateTelegrafConfigAsync,
16+
setLocationOnDismiss,
17+
} from 'src/dataLoaders/actions/dataLoaders'
18+
import {setBucketInfo} from 'src/dataLoaders/actions/steps'
1519
import {updateTelegraf} from 'src/telegrafs/actions/thunks'
1620

1721
// Types
1822
import {AppState, ResourceType, Telegraf} from 'src/types'
1923
import {PluginConfigurationStepProps} from 'src/writeData/components/AddPluginToConfiguration'
2024

2125
// Selectors
22-
import {getDataLoaders} from 'src/dataLoaders/selectors'
2326
import {getAll} from 'src/resources/selectors'
2427
import {getQuartzMe} from 'src/me/selectors'
2528

@@ -47,9 +50,12 @@ const FooterComponent: FC<Props> = props => {
4750
onIncrementCurrentStepIndex,
4851
onSaveTelegrafConfig,
4952
onUpdateTelegraf,
53+
orgID,
5054
pluginConfig,
5155
pluginConfigName,
56+
setBucketInfo,
5257
setIsValidConfiguration,
58+
setLocationOnDismiss,
5359
substepIndex,
5460
telegrafConfig,
5561
} = props
@@ -86,6 +92,8 @@ const FooterComponent: FC<Props> = props => {
8692

8793
const handleSaveAndTest = () => {
8894
onSaveTelegrafConfig()
95+
setBucketInfo('', '', '')
96+
setLocationOnDismiss(`/orgs/${orgID}/load-data/telegrafs`)
8997
onIncrementCurrentStepIndex()
9098
}
9199

@@ -149,7 +157,12 @@ const FooterComponent: FC<Props> = props => {
149157
}
150158

151159
const mstp = (state: AppState) => {
152-
const {telegrafConfigID} = getDataLoaders(state)
160+
const {
161+
dataLoading: {
162+
dataLoaders: {telegrafConfigID},
163+
steps: {orgID},
164+
},
165+
} = state
153166
const accountType = getQuartzMe(state)?.accountType ?? 'free'
154167
let telegrafConfig = null
155168
if (telegrafConfigID) {
@@ -158,12 +171,14 @@ const mstp = (state: AppState) => {
158171
telegraf => telegraf.id === telegrafConfigID
159172
)
160173
}
161-
return {accountType, telegrafConfig}
174+
return {accountType, orgID, telegrafConfig}
162175
}
163176

164177
const mdtp = {
165178
onSaveTelegrafConfig: createOrUpdateTelegrafConfigAsync,
166179
onUpdateTelegraf: updateTelegraf,
180+
setBucketInfo,
181+
setLocationOnDismiss,
167182
}
168183

169184
const connector = connect(mstp, mdtp)

0 commit comments

Comments
 (0)