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(ui/labels): add searchTerm updating for label clicks #12111

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features
1. [12096](https://github.com/influxdata/influxdb/pull/12096): Add labels to cloned tasks
1. [12111](https://github.com/influxdata/influxdb/pull/12111): Add ability to filter resources by clicking a label

### Bug Fixes

Expand Down
92 changes: 92 additions & 0 deletions ui/cypress/e2e/dashboardsIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,96 @@ describe('Dashboards', () => {

cy.getByTestID('resource-card').should('contain', newName)
})

describe('labeling', () => {
it('can click to filter dashboard labels', () => {
const newLabelName = 'click-me'

cy.get<Organization>('@org').then(({id}) => {
cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, newLabelName)
})

cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, 'bar')
})
})

cy.visit('/dashboards')

cy.getByTestID('resource-card').should('have.length', 2)

cy.getByTestID(`label--pill ${newLabelName}`).click()

cy.getByTestID('resource-card').should('have.length', 1)
})
})

describe('searching', () => {
it('can search dashboards by labels', () => {
const widgetSearch = 'searchME'

cy.get<Organization>('@org').then(({id}) => {
cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, widgetSearch)
})

cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, 'bar')
})
})

cy.visit('/dashboards')

cy.getByTestID('resource-card').should('have.length', 2)

cy.getByTestID('search-widget').type(widgetSearch)

cy.getByTestID('resource-card').should('have.length', 1)

cy.getByTestID('resource-card')
.first()
.get('.label')
.should('contain', widgetSearch)
})

it('can search by clicking label', () => {
const clicked = 'click-me'

cy.get<Organization>('@org').then(({id}) => {
cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, clicked)
})

cy.createDashboard(id).then(({body}) => {
cy.createLabel('dashboards', body.id, 'bar')
})
})

cy.visit('/dashboards')

cy.getByTestID('resource-card').should('have.length', 2)

cy.getByTestID(`label--pill ${clicked}`).click()

cy.getByTestID('search-widget').should('have.value', clicked)

cy.getByTestID('resource-card').should('have.length', 1)
})

it('can search by dashboard name', () => {
const searchName = 'beepBoop'
cy.get<Organization>('@org').then(({id}) => {
cy.createDashboard(id, searchName)
cy.createDashboard(id)
})

cy.visit('/dashboards')

cy.getByTestID('search-widget').type('bEE')

cy.getByTestID('resource-card').should('have.length', 1)
cy.getByTestID('dashboard-card--name').contains('span', searchName)
})
})
})
40 changes: 40 additions & 0 deletions ui/cypress/e2e/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,44 @@ describe('Tasks', () => {

cy.getByTestID('notification-error').should('exist')
})

describe('labeling', () => {
it.only('can click to filter tasks by labels', () => {
const newLabelName = 'click-me'

cy.get<Organization>('@org').then(({id}) => {
cy.createTask(id).then(({body}) => {
cy.createLabel('tasks', body.id, newLabelName)
})

cy.createTask(id).then(({body}) => {
cy.createLabel('tasks', body.id, 'bar')
})
})

cy.visit('/tasks')

cy.getByTestID('task-row').should('have.length', 2)

cy.getByTestID(`label--pill ${newLabelName}`).click()

cy.getByTestID('task-row').should('have.length', 1)
})
})

describe('searching', () => {
it('can search by task name', () => {
const searchName = 'beepBoop'
cy.get<Organization>('@org').then(({id}) => {
cy.createTask(id, searchName)
cy.createTask(id)
})

cy.visit('/tasks')

cy.getByTestID('search-widget').type('bEE')

cy.getByTestID('task-row').should('have.length', 1)
})
})
})
2 changes: 2 additions & 0 deletions ui/cypress/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getByTitle,
createTask,
createVariable,
createLabel,
} from './support/commands'

declare global {
Expand All @@ -27,6 +28,7 @@ declare global {
getByTestID: typeof getByTestID
getByInputName: typeof getByInputName
getByTitle: typeof getByTitle
createLabel: typeof createLabel
}
}
}
47 changes: 43 additions & 4 deletions ui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ export const signin = (): Cypress.Chainable<Cypress.Response> => {
}

export const createDashboard = (
orgID?: string
orgID?: string,
name: string = 'test dashboard'
): Cypress.Chainable<Cypress.Response> => {
return cy.request({
method: 'POST',
url: '/api/v2/dashboards',
body: {
name: 'test dashboard',
name,
orgID,
},
})
Expand All @@ -48,10 +49,11 @@ export const createBucket = (): Cypress.Chainable<Cypress.Response> => {
}

export const createTask = (
orgID?: string
orgID?: string,
name: string = '🦄ask'
): Cypress.Chainable<Cypress.Response> => {
const flux = `option task = {
name: "🦄ask",
name: "${name}",
every: 1d,
offset: 20m
}
Expand Down Expand Up @@ -90,6 +92,40 @@ export const createVariable = (
})
}

export const createLabel = (
resource: string,
resourceID: string,
name?: string
): Cypress.Chainable<Cypress.Response> => {
return cy
.request({
method: 'POST',
url: '/api/v2/labels',
body: {
name,
properties: {
description: `test ${name}`,
color: '#ff00ff',
},
},
})
.then(({body}) => {
return addResourceLabel(resource, resourceID, body.label.id)
})
}

export const addResourceLabel = (
resource: string,
resourceID: string,
labelID: string
): Cypress.Chainable<Cypress.Response> => {
return cy.request({
method: 'POST',
url: `/api/v2/${resource}/${resourceID}/labels`,
body: {labelID},
})
}

export const createSource = (
orgID?: string
): Cypress.Chainable<Cypress.Response> => {
Expand Down Expand Up @@ -164,3 +200,6 @@ Cypress.Commands.add('createTask', createTask)

// variables
Cypress.Commands.add('createVariable', createVariable)

// Labels
Cypress.Commands.add('createLabel', createLabel)
8 changes: 6 additions & 2 deletions ui/src/clockface/components/index_views/IndexListRowCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ interface Props {
children: any
alignment?: Alignment
revealOnHover?: boolean
testID?: string
}

@ErrorHandling
class IndexListRowCell extends Component<Props> {
public static defaultProps: Partial<Props> = {
alignment: Alignment.Left,
revealOnHover: false,
testID: 'table-cell',
}

public render() {
const {children} = this.props
const {children, testID} = this.props

return (
<td className={this.className}>
<div className="index-list--cell">{children}</div>
<div className="index-list--cell" data-testid={testID}>
{children}
</div>
</td>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
Apple
</div>
Expand All @@ -169,12 +171,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
500
</div>
Expand All @@ -193,12 +197,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
Pear
</div>
Expand All @@ -207,12 +213,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
1000
</div>
Expand All @@ -231,12 +239,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
Banana
</div>
Expand All @@ -245,12 +255,14 @@ exports[`IndexList matches snapshot with minimal props 1`] = `
<IndexListRowCell
alignment="left"
revealOnHover={false}
testID="table-cell"
>
<td
className="index-list--row-cell index-list--align-left"
>
<div
className="index-list--cell"
data-testid="table-cell"
>
100
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/src/clockface/components/label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Label extends Component<Props, State> {
onMouseLeave={this.handleMouseLeave}
style={this.style}
title={this.title}
data-testid={`label--pill ${name}`}
>
<label>{name}</label>
{this.deleteButton}
Expand Down
5 changes: 4 additions & 1 deletion ui/src/clockface/components/label/LabelContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ interface Props {
limitChildCount?: number
resourceName?: string
onEdit?: () => void
testID?: string
}

class LabelContainer extends Component<Props> {
public static defaultProps: Partial<Props> = {
limitChildCount: 999,
resourceName: 'this resource',
testID: 'labels-con',
}

public render() {
const {className} = this.props
const {className, testID} = this.props

return (
<div
className={classnames('label--container', {
[`${className}`]: className,
})}
data-testid={testID}
>
<div className="label--container-margin">
{this.children}
Expand Down
Loading