Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sampledata): Route from buckets index to Data Explorer #17085

Merged
merged 7 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/cypress/e2e/buckets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Buckets', () => {

it("can update a bucket's retention rules", () => {
cy.get<Bucket>('@bucket').then(({name}: Bucket) => {
cy.getByTestID(`bucket--card--name ${name}`).click()
cy.getByTestID(`bucket-settings`).click()
cy.getByTestID(`bucket--card--name ${name}`).should(
'not.contain',
'7 days'
Expand Down
25 changes: 8 additions & 17 deletions ui/src/buckets/components/BucketCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,10 @@ class BucketRow extends PureComponent<Props & WithRouterProps & DispatchProps> {

private get cardName(): JSX.Element {
const {bucket} = this.props
if (bucket.type === 'user') {
return (
<ResourceCard.Name
testID={`bucket--card--name ${bucket.name}`}
onClick={this.handleNameClick}
name={bucket.name}
/>
)
}

return (
<ResourceCard.Name
testID={`bucket--card--name ${bucket.name}`}
onClick={this.handleNameClick}
name={bucket.name}
/>
)
Expand Down Expand Up @@ -126,10 +117,10 @@ class BucketRow extends PureComponent<Props & WithRouterProps & DispatchProps> {
onAddScraper={this.handleAddScraper}
/>
<Button
text="Rename"
testID="bucket-rename"
text="Settings"
testID="bucket-settings"
size={ComponentSize.ExtraSmall}
onClick={this.handleRenameBucket}
onClick={this.handleClickSettings}
/>
<FeatureFlag name="deleteWithPredicate">
<Button
Expand Down Expand Up @@ -162,24 +153,24 @@ class BucketRow extends PureComponent<Props & WithRouterProps & DispatchProps> {
onDeleteData(bucket)
}

private handleRenameBucket = () => {
private handleClickSettings = () => {
const {
params: {orgID},
bucket: {id},
router,
} = this.props

router.push(`/orgs/${orgID}/load-data/buckets/${id}/rename`)
router.push(`/orgs/${orgID}/load-data/buckets/${id}/edit`)
}

private handleNameClick = (): void => {
const {
params: {orgID},
bucket: {id},
bucket: {name},
router,
} = this.props

router.push(`/orgs/${orgID}/load-data/buckets/${id}/edit`)
router.push(`/orgs/${orgID}/data-explorer?bucket=${name}`)
}

private handleAddCollector = (): void => {
Expand Down
11 changes: 10 additions & 1 deletion ui/src/buckets/components/BucketOverlayForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
onChangeInput: (e: ChangeEvent<HTMLInputElement>) => void
disableRenaming: boolean
buttonText: string
onClickRename?: () => void
}

export default class BucketOverlayForm extends PureComponent<Props> {
Expand All @@ -43,6 +44,7 @@ export default class BucketOverlayForm extends PureComponent<Props> {
onChangeInput,
onChangeRuleType,
onChangeRetentionRule,
onClickRename,
} = this.props

const nameInputStatus = disableRenaming && ComponentStatus.Disabled
Expand Down Expand Up @@ -91,6 +93,13 @@ export default class BucketOverlayForm extends PureComponent<Props> {
onClick={onCloseModal}
type={ButtonType.Button}
/>
{buttonText === 'Save Changes' && (
<Button
text="Rename"
color={ComponentColor.Danger}
onClick={onClickRename}
/>
)}
<Button
text={buttonText}
color={this.submitButtonColor}
Expand Down Expand Up @@ -119,7 +128,7 @@ export default class BucketOverlayForm extends PureComponent<Props> {

private get nameHelpText(): string {
if (this.props.disableRenaming) {
return 'To rename the bucket use the RENAME button. Bucket renaming is not allowed here.'
return 'To rename bucket use the RENAME button below'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

return ''
Expand Down
5 changes: 5 additions & 0 deletions ui/src/buckets/components/UpdateBucketOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ const UpdateBucketOverlay: FunctionComponent<Props> = ({
router.push(`/orgs/${orgID}/load-data/buckets`)
}

const handleClickRename = () => {
router.push(`/orgs/${orgID}/load-data/buckets/${bucketID}/rename`)
}

const rules = get(bucketDraft, 'retentionRules', [])
const rule = rules.find(r => r.type === 'expire')

Expand All @@ -140,6 +144,7 @@ const UpdateBucketOverlay: FunctionComponent<Props> = ({
retentionSeconds={retentionSeconds}
onChangeRuleType={handleChangeRuleType}
onChangeRetentionRule={handleChangeRetentionRule}
onClickRename={handleClickRename}
/>
</Overlay.Body>
</SpinnerContainer>
Expand Down
44 changes: 25 additions & 19 deletions ui/src/dataExplorer/components/DataExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Libraries
import React, {PureComponent} from 'react'
import React, {FC, useEffect} from 'react'
import {connect} from 'react-redux'

// Components
Expand All @@ -9,40 +9,46 @@ import RateLimitAlert from 'src/cloud/components/RateLimitAlert'

// Actions
import {setActiveTimeMachine} from 'src/timeMachine/actions'
import {setBuilderBucketIfExists} from 'src/timeMachine/actions/queryBuilder'

// Utils
import {HoverTimeProvider} from 'src/dashboards/utils/hoverTime'
import {queryBuilderFetcher} from 'src/timeMachine/apis/QueryBuilderFetcher'
import {readQueryParams} from 'src/shared/utils/queryParams'

interface DispatchProps {
onSetActiveTimeMachine: typeof setActiveTimeMachine
onSetBuilderBucketIfExists: typeof setBuilderBucketIfExists
}

type Props = DispatchProps
class DataExplorer extends PureComponent<Props, {}> {
constructor(props: Props) {
super(props)

props.onSetActiveTimeMachine('de')
const DataExplorer: FC<Props> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just want to call out that switching from a PureComponent to a FunctionComponent might have performance implications since a FC always renders, while a PureComponent sometimes doesn't re-render. I don't have enough context to provide anything more helpful than that :|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.. I'll test it a bit..

onSetActiveTimeMachine,
onSetBuilderBucketIfExists,
}) => {
useEffect(() => {
const bucketQP = readQueryParams()['bucket']
onSetActiveTimeMachine('de')
queryBuilderFetcher.clearCache()
}

public render() {
return (
<LimitChecker>
<RateLimitAlert />
<div className="data-explorer">
<HoverTimeProvider>
<TimeMachine />
</HoverTimeProvider>
</div>
</LimitChecker>
)
}
onSetBuilderBucketIfExists(bucketQP)
}, [])

return (
<LimitChecker>
<RateLimitAlert />
<div className="data-explorer">
<HoverTimeProvider>
<TimeMachine />
</HoverTimeProvider>
</div>
</LimitChecker>
)
}

const mdtp: DispatchProps = {
onSetActiveTimeMachine: setActiveTimeMachine,
onSetBuilderBucketIfExists: setBuilderBucketIfExists,
}

export default connect<{}, DispatchProps, {}>(
Expand Down
13 changes: 13 additions & 0 deletions ui/src/timeMachine/actions/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
BuilderAggregateFunctionType,
GetState,
RemoteDataState,
ResourceType,
Bucket,
} from 'src/types'
import {Dispatch} from 'react'
import {BuilderFunctionsType} from '@influxdata/influx'
Expand All @@ -23,6 +25,7 @@ import {

// Selectors
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'

export type Action =
| ReturnType<typeof setBuilderAggregateFunctionType>
Expand Down Expand Up @@ -404,3 +407,13 @@ export const reloadTagSelectors = () => (dispatch: Dispatch<Action>) => {
dispatch(setBuilderTagsStatus(RemoteDataState.Loading))
dispatch(loadTagSelector(0))
}

export const setBuilderBucketIfExists = (bucketName: string) => (
dispatch: Dispatch<Action>,
getState: GetState
) => {
const buckets = getAll<Bucket>(getState(), ResourceType.Buckets)
if (buckets.find(b => b.name === bucketName)) {
dispatch(setBuilderBucket(bucketName, true))
}
}