Skip to content

Commit d35df38

Browse files
subirjollySubir Jolly
andauthored
fix: select correct bucket in buckets list (#4672)
* fix: select correct bucket in buckets list * chore: add test * chore: uncommented tests * chore: remove typo Co-authored-by: Subir Jolly <sjolly@influxdata.com>
1 parent f250a6e commit d35df38

File tree

4 files changed

+103
-68
lines changed

4 files changed

+103
-68
lines changed

cypress/e2e/cloud/subscriptions.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ describe('Subscriptions', () => {
122122
cy.get('.cf-resource-card').should('be.visible')
123123
cy.get('.cf-resource-card').should('have.length', 1)
124124
cy.get('.cf-resource-card').contains('My Subscription')
125+
126+
// bucket review
127+
cy.getByTestID('subscription-card').should('be.visible')
128+
cy.getByTestID('subscription-name').should('be.visible')
129+
cy.getByTestID('subscription-name').click()
130+
cy.get('.subscription-details-page').should('be.visible')
131+
cy.getByTestID('update-subscription-form--submit').click()
132+
cy.getByTestID('update-subscription-form--bucket').contains('defbuck')
133+
cy.getByTestID('update-subscription-form--edit').click()
134+
cy.getByTestID('buckets--list').should('be.visible')
135+
cy.getByTestID('list-item')
136+
.should('have.length', 1)
137+
.should('have.attr', 'style')
138+
cy.getByTestID('update-subscription-form--cancel').click()
139+
125140
// update
126141
cy.getByTestID('subscription-card').should('be.visible')
127142
cy.getByTestID('subscription-name').should('be.visible')

src/writeData/components/WriteDataDetailsContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ const DEFAULT_BUCKET = '<BUCKET>'
2525

2626
interface WriteDataDetailsContextType {
2727
bucket: Bucket
28+
buckets: Bucket[]
2829
changeBucket: (bucket: Bucket) => void
2930
query: string
3031
changeQuery: (query: string) => void
3132
}
3233

3334
export const DEFAULT_WRITE_DATA_DETAILS_CONTEXT: WriteDataDetailsContextType = {
3435
bucket: null,
36+
buckets: [],
3537
changeBucket: () => {},
3638
query: null,
3739
changeQuery: () => {},
@@ -119,6 +121,7 @@ const WriteDataDetailsProvider: FC = ({children}) => {
119121
<WriteDataDetailsContext.Provider
120122
value={{
121123
bucket,
124+
buckets,
122125
changeBucket,
123126
query,
124127
changeQuery,

src/writeData/components/WriteDataHelperBuckets.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const WriteDataHelperBuckets: FC<Props> = ({
6969
backgroundColor={InfluxColors.Grey5}
7070
style={{height: '200px'}}
7171
maxHeight="200px"
72+
testID="buckets--list"
7273
>
7374
{buckets.map(b => (
7475
<List.Item
Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC} from 'react'
2+
import React, {FC, useContext, useEffect} from 'react'
33

44
// Components
55
import {
@@ -24,6 +24,7 @@ import {Subscription} from 'src/types/subscriptions'
2424
// Styles
2525
import 'src/writeData/subscriptions/components/SubscriptionDetails.scss'
2626
import {event} from 'src/cloud/utils/reporting'
27+
import {WriteDataDetailsContext} from 'src/writeData/components/WriteDataDetailsContext'
2728

2829
interface Props {
2930
currentSubscription: Subscription
@@ -37,77 +38,92 @@ const SubscriptionFormContent: FC<Props> = ({
3738
updateForm,
3839
className,
3940
edit,
40-
}) => (
41-
<Grid>
42-
<Grid.Row>
43-
<Grid.Column widthSM={Columns.Twelve}>
44-
<Form.ValidationElement
45-
label="Topic"
46-
value={currentSubscription.topic}
47-
helpText="Subscribe to a topic to start receiving messages."
48-
required={true}
49-
validationFunc={() =>
50-
handleValidation('Topic', currentSubscription.topic)
51-
}
52-
>
53-
{status => (
54-
<Input
55-
type={InputType.Text}
56-
placeholder="Enter a topic (wildcards accepted)"
57-
name="topic"
58-
autoFocus={false}
59-
value={currentSubscription.topic}
60-
onChange={e => {
61-
updateForm({
62-
...currentSubscription,
63-
topic: e.target.value,
64-
})
65-
}}
66-
onBlur={() =>
67-
event(
68-
'completed form field',
69-
{formField: 'topic'},
70-
{feature: 'subscriptions'}
71-
)
72-
}
73-
status={edit ? status : ComponentStatus.Disabled}
74-
maxLength={56}
75-
testID={`${className}-subscription-form--topic`}
76-
/>
77-
)}
78-
</Form.ValidationElement>
79-
</Grid.Column>
80-
<Grid.Column widthXS={Columns.Twelve}>
81-
<Heading
82-
element={HeadingElement.H3}
83-
weight={FontWeight.Bold}
84-
className={`${className}-subscription-form__header`}
85-
>
86-
Write Destination
87-
</Heading>
88-
{className === 'create' || edit ? (
89-
<div>
41+
}) => {
42+
const {bucket, buckets, changeBucket} = useContext(WriteDataDetailsContext)
43+
useEffect(() => {
44+
if (bucket.name === currentSubscription?.bucket) {
45+
return
46+
}
47+
48+
const found = buckets.find(b => b.name === currentSubscription?.bucket)
49+
if (found) {
50+
changeBucket(found)
51+
}
52+
}, [])
53+
54+
return (
55+
<Grid>
56+
<Grid.Row>
57+
<Grid.Column widthSM={Columns.Twelve}>
58+
<Form.ValidationElement
59+
label="Topic"
60+
value={currentSubscription.topic}
61+
helpText="Subscribe to a topic to start receiving messages."
62+
required={true}
63+
validationFunc={() =>
64+
handleValidation('Topic', currentSubscription.topic)
65+
}
66+
>
67+
{status => (
68+
<Input
69+
type={InputType.Text}
70+
placeholder="Enter a topic (wildcards accepted)"
71+
name="topic"
72+
autoFocus={false}
73+
value={currentSubscription.topic}
74+
onChange={e => {
75+
updateForm({
76+
...currentSubscription,
77+
topic: e.target.value,
78+
})
79+
}}
80+
onBlur={() =>
81+
event(
82+
'completed form field',
83+
{formField: 'topic'},
84+
{feature: 'subscriptions'}
85+
)
86+
}
87+
status={edit ? status : ComponentStatus.Disabled}
88+
maxLength={56}
89+
testID={`${className}-subscription-form--topic`}
90+
/>
91+
)}
92+
</Form.ValidationElement>
93+
</Grid.Column>
94+
<Grid.Column widthXS={Columns.Twelve}>
95+
<Heading
96+
element={HeadingElement.H3}
97+
weight={FontWeight.Bold}
98+
className={`${className}-subscription-form__header`}
99+
>
100+
Write Destination
101+
</Heading>
102+
{className === 'create' || edit ? (
103+
<div>
104+
<Heading
105+
element={HeadingElement.H5}
106+
weight={FontWeight.Regular}
107+
className={`${className}-subscription-form__text`}
108+
>
109+
Select a bucket to write your data to.
110+
</Heading>
111+
<WriteDataHelperBuckets className="write-data--subscriptions-title" />
112+
</div>
113+
) : (
90114
<Heading
91-
element={HeadingElement.H5}
115+
element={HeadingElement.H4}
92116
weight={FontWeight.Regular}
93117
className={`${className}-subscription-form__text`}
118+
testID={`${className}-subscription-form--bucket`}
94119
>
95-
Select a bucket to write your data to.
120+
Bucket: {currentSubscription && currentSubscription.bucket}
96121
</Heading>
97-
<WriteDataHelperBuckets className="write-data--subscriptions-title" />
98-
</div>
99-
) : (
100-
<Heading
101-
element={HeadingElement.H4}
102-
weight={FontWeight.Regular}
103-
className={`${className}-subscription-form__text`}
104-
>
105-
Bucket: {currentSubscription && currentSubscription.bucket}
106-
</Heading>
107-
)}
108-
</Grid.Column>
109-
</Grid.Row>
110-
</Grid>
111-
)
122+
)}
123+
</Grid.Column>
124+
</Grid.Row>
125+
</Grid>
126+
)
127+
}
112128

113129
export default SubscriptionFormContent

0 commit comments

Comments
 (0)