Merge pull request #11156 from influxdata/feat/delete-task-adminui

Add the ability to delete a task from organization
pull/11185/head
Palakp41 2019-01-16 15:59:38 -08:00 committed by GitHub
commit 2a24c6dca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 13 deletions

View File

@ -1,16 +1,17 @@
// Libraries
import React, {PureComponent} from 'react'
import {Link} from 'react-router'
// Components
import {IndexList} from 'src/clockface'
// Types
import {Task} from 'src/api'
import TaskRow from 'src/organizations/components/TaskRow'
interface Props {
tasks: Task[]
emptyState: JSX.Element
onDelete: (taskID: string) => void
}
export default class TaskList extends PureComponent<Props> {
@ -30,14 +31,9 @@ export default class TaskList extends PureComponent<Props> {
}
private get rows(): JSX.Element[] {
return this.props.tasks.map(task => (
<IndexList.Row key={task.id}>
<IndexList.Cell>
<Link to={`/tasks/${task.id}`}>{task.name}</Link>
</IndexList.Cell>
<IndexList.Cell>{task.owner.name}</IndexList.Cell>
<IndexList.Cell revealOnHover={true}>DELETE</IndexList.Cell>
</IndexList.Row>
const {tasks, onDelete} = this.props
return tasks.map(task => (
<TaskRow key={task.id} task={task} onDelete={onDelete} />
))
}
}

View File

@ -0,0 +1,48 @@
// Libraries
import React, {PureComponent} from 'react'
import {Link} from 'react-router'
// Components
import {
ComponentSize,
IndexList,
ConfirmationButton,
Alignment,
} from 'src/clockface'
// Api
import {Task} from 'src/api'
interface Props {
task: Task
onDelete: (taskID: string) => void
}
export default class TaskRow extends PureComponent<Props> {
public render() {
const {task} = this.props
return (
<>
<IndexList.Row key={task.id}>
<IndexList.Cell>
<Link to={`/tasks/${task.id}`}>{task.name}</Link>
</IndexList.Cell>
<IndexList.Cell>{task.owner.name}</IndexList.Cell>
<IndexList.Cell revealOnHover={true} alignment={Alignment.Right}>
<ConfirmationButton
size={ComponentSize.ExtraSmall}
text="Delete"
confirmText="Confirm"
onConfirm={this.handleDeleteTask}
/>
</IndexList.Cell>
</IndexList.Row>
</>
)
}
private handleDeleteTask = (): void => {
this.props.onDelete(this.props.task.id)
}
}

View File

@ -10,10 +10,12 @@ import FilterList from 'src/shared/components/Filter'
// Types
import {Task} from 'src/api'
import {deleteTask} from 'src/tasks/api/v2/index'
interface Props {
tasks: Task[]
orgName: string
onChange: () => void
}
interface State {
@ -46,10 +48,16 @@ export default class Tasks extends PureComponent<Props, State> {
</TabbedPageHeader>
<FilterList<Task>
searchTerm={searchTerm}
searchKeys={['name', 'owner.name']}
searchKeys={['name']}
list={tasks}
>
{ts => <TaskList tasks={ts} emptyState={this.emptyState} />}
{ts => (
<TaskList
tasks={ts}
emptyState={this.emptyState}
onDelete={this.handleDeleteTask}
/>
)}
</FilterList>
</>
)
@ -84,4 +92,9 @@ export default class Tasks extends PureComponent<Props, State> {
</EmptyState>
)
}
private handleDeleteTask = async (taskID: string) => {
await deleteTask(taskID)
this.props.onChange()
}
}

View File

@ -138,9 +138,13 @@ class OrganizationView extends PureComponent<Props> {
title="Tasks"
>
<GetOrgResources<Task[]> organization={org} fetcher={getTasks}>
{(tasks, loading) => (
{(tasks, loading, fetch) => (
<Spinner loading={loading}>
<Tasks tasks={tasks} orgName={org.name} />
<Tasks
tasks={tasks}
orgName={org.name}
onChange={fetch}
/>
</Spinner>
)}
</GetOrgResources>