Skip to content

Commit

Permalink
Merge pull request #13568 from influxdata/fix/telegraf-list-resource
Browse files Browse the repository at this point in the history
Update telegraf list to use ResourceList
  • Loading branch information
Palakp41 authored Apr 23, 2019
2 parents 5e77bd1 + 1e4acb3 commit 6c20c6c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 98 deletions.
19 changes: 14 additions & 5 deletions ui/cypress/e2e/collectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Collectors', () => {
.click()
})

cy.getByTestID('table-row')
cy.getByTestID('resource-card')
.should('have.length', 1)
.and('contain', newConfig)
})
Expand All @@ -63,10 +63,19 @@ describe('Collectors', () => {
cy.createTelegraf(telegrafConfigName, description, id)
})

cy.getByTestID('table-cell').within(() => {
cy.getByTestID('editable-name').click()
cy.getByTestID('input-field').type(`${newConfigName}{enter}`)
})
cy.getByTestID('collector-card--name')
.first()
.trigger('mouseover')

cy.getByTestID('collector-card--name-button')
.first()
.click()

cy.getByTestID('collector-card--input')
.type(newConfigName)
.type('{enter}')

cy.getByTestID('collector-card--name').should('contain', newConfigName)
})

it.skip('can delete a telegraf config', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@ import {connect} from 'react-redux'
import {withRouter, WithRouterProps} from 'react-router'

// Components
import {IndexList, Alignment, ConfirmationButton} from 'src/clockface'
import {
ComponentSize,
Button,
ComponentColor,
ComponentSpacer,
FlexDirection,
JustifyContent,
AlignItems,
} from '@influxdata/clockface'
import {ResourceList, Context, IconFont} from 'src/clockface'
import {ComponentColor} from '@influxdata/clockface'
import {ITelegraf as Telegraf, Organization} from '@influxdata/influx'
import EditableName from 'src/shared/components/EditableName'
import EditableDescription from 'src/shared/components/editable_description/EditableDescription'
import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'

// Actions
Expand Down Expand Up @@ -63,52 +53,46 @@ class CollectorRow extends PureComponent<Props & WithRouterProps> {
const {collector, bucket} = this.props

return (
<>
<IndexList.Row>
<IndexList.Cell>
<ComponentSpacer
margin={ComponentSize.Small}
direction={FlexDirection.Column}
alignItems={AlignItems.FlexStart}
stretchToFitWidth={true}
>
<EditableName
onUpdate={this.handleUpdateName}
name={collector.name}
noNameString={DEFAULT_COLLECTOR_NAME}
onEditName={this.handleNameClick}
/>
<EditableDescription
description={collector.description}
placeholder={`Describe ${collector.name}`}
onUpdate={this.handleUpdateDescription}
/>
{this.labels}
</ComponentSpacer>
</IndexList.Cell>
<IndexList.Cell>{bucket}</IndexList.Cell>
<IndexList.Cell revealOnHover={true} alignment={Alignment.Right}>
<ComponentSpacer
margin={ComponentSize.Small}
direction={FlexDirection.Row}
justifyContent={JustifyContent.FlexEnd}
>
<Button
text="Setup Instructions"
size={ComponentSize.ExtraSmall}
color={ComponentColor.Secondary}
onClick={this.handleOpenInstructions}
/>
<ConfirmationButton
size={ComponentSize.ExtraSmall}
text="Delete"
confirmText="Confirm"
onConfirm={this.handleDeleteConfig}
/>
</ComponentSpacer>
</IndexList.Cell>
</IndexList.Row>
</>
<ResourceList.Card
key={`telegraf-id--${collector.id}`}
testID="resource-card"
name={() => (
<ResourceList.Name
onUpdate={this.handleUpdateName}
onClick={this.handleNameClick}
name={collector.name}
noNameString={DEFAULT_COLLECTOR_NAME}
parentTestID="collector-card--name"
buttonTestID="collector-card--name-button"
inputTestID="collector-card--input"
/>
)}
description={() => (
<ResourceList.Description
onUpdate={this.handleUpdateDescription}
description={collector.description}
placeholder={`Describe ${collector.name}`}
/>
)}
labels={() => this.labels}
metaData={() => [
<>Bucket: {bucket}</>,
<>
<a onClick={this.handleOpenInstructions}>Setup Instructions</a>
</>,
]}
contextMenu={() => this.contextMenu}
/>
)
}

private get contextMenu(): JSX.Element {
return (
<Context>
<Context.Menu icon={IconFont.Trash} color={ComponentColor.Danger}>
<Context.Item label="Delete" action={this.handleDeleteConfig} />
</Context.Menu>
</Context>
)
}

Expand Down
33 changes: 18 additions & 15 deletions ui/src/telegrafs/components/CollectorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import _ from 'lodash'
import memoizeOne from 'memoize-one'

// Components
import {IndexList} from 'src/clockface'
import CollectorRow from 'src/telegrafs/components/CollectorRow'
import {ResourceList} from 'src/clockface'
import CollectorRow from 'src/telegrafs/components/CollectorCard'

// Types
import {ITelegraf as Telegraf} from '@influxdata/influx'
Expand All @@ -15,7 +15,7 @@ import {SortTypes, getSortedResources} from 'src/shared/utils/sort'
//Utils
import {getDeep} from 'src/utils/wrappers'

type SortKey = keyof Telegraf
type SortKey = keyof Telegraf | 'bucket'

interface Props {
collectors: Telegraf[]
Expand All @@ -40,28 +40,31 @@ export default class CollectorList extends PureComponent<Props> {

return (
<>
<IndexList>
<IndexList.Header>
<IndexList.HeaderCell
<ResourceList>
<ResourceList.Header>
<ResourceList.Sorter
sortKey={this.headerKeys[0]}
sort={sortKey === this.headerKeys[0] ? sortDirection : Sort.None}
columnName="Name"
width="50%"
name="Name"
onClick={onClickColumn}
/>
<IndexList.HeaderCell columnName="Bucket" width="25%" />
<IndexList.HeaderCell columnName="" width="25%" />
</IndexList.Header>
<IndexList.Body columnCount={3} emptyState={emptyState}>
<ResourceList.Sorter
name="Bucket"
sortKey={this.headerKeys[1]}
sort={sortKey === this.headerKeys[1] ? sortDirection : Sort.None}
onClick={onClickColumn}
/>
</ResourceList.Header>
<ResourceList.Body emptyState={emptyState}>
{this.collectorsList}
</IndexList.Body>
</IndexList>
</ResourceList.Body>
</ResourceList>
</>
)
}

private get headerKeys(): SortKey[] {
return ['name']
return ['name', 'bucket']
}

public get collectorsList(): JSX.Element[] {
Expand Down
32 changes: 12 additions & 20 deletions ui/src/telegrafs/components/__snapshots__/Collectors.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@

exports[`CollectorList rendering renders 1`] = `
<Fragment>
<IndexList>
<IndexListHeader>
<IndexListHeaderCell
alignment="left"
columnName="Name"
<ResourceList>
<ResourceListHeader>
<ResourceListSorter
name="Name"
sort="none"
sortKey="name"
width="50%"
/>
<IndexListHeaderCell
alignment="left"
columnName="Bucket"
width="25%"
/>
<IndexListHeaderCell
alignment="left"
columnName=""
width="25%"
<ResourceListSorter
name="Bucket"
sort="none"
sortKey="bucket"
/>
</IndexListHeader>
<IndexListBody
columnCount={3}
</ResourceListHeader>
<ResourceListBody
emptyState={<React.Fragment />}
>
<Connect(withRouter(CollectorRow))
Expand Down Expand Up @@ -54,7 +46,7 @@ exports[`CollectorList rendering renders 1`] = `
onOpenInstructions={[MockFunction]}
onUpdate={[MockFunction]}
/>
</IndexListBody>
</IndexList>
</ResourceListBody>
</ResourceList>
</Fragment>
`;

0 comments on commit 6c20c6c

Please sign in to comment.