From 9442a685b031903347900e956735ecd4d679af65 Mon Sep 17 00:00:00 2001 From: Palak Bhojani <palak@influxdata.com> Date: Wed, 16 Jan 2019 12:16:10 -0800 Subject: [PATCH] Add the ability to delete a task from organization --- ui/src/organizations/components/TaskList.tsx | 14 ++---- ui/src/organizations/components/TaskRow.tsx | 48 +++++++++++++++++++ ui/src/organizations/components/Tasks.tsx | 17 ++++++- .../containers/OrganizationView.tsx | 8 +++- 4 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 ui/src/organizations/components/TaskRow.tsx diff --git a/ui/src/organizations/components/TaskList.tsx b/ui/src/organizations/components/TaskList.tsx index f6e6b0d7d5..3390e6b81e 100644 --- a/ui/src/organizations/components/TaskList.tsx +++ b/ui/src/organizations/components/TaskList.tsx @@ -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} /> )) } } diff --git a/ui/src/organizations/components/TaskRow.tsx b/ui/src/organizations/components/TaskRow.tsx new file mode 100644 index 0000000000..03f6feb399 --- /dev/null +++ b/ui/src/organizations/components/TaskRow.tsx @@ -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) + } +} diff --git a/ui/src/organizations/components/Tasks.tsx b/ui/src/organizations/components/Tasks.tsx index e2fb4beaae..ad6d71ed0f 100644 --- a/ui/src/organizations/components/Tasks.tsx +++ b/ui/src/organizations/components/Tasks.tsx @@ -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() + } } diff --git a/ui/src/organizations/containers/OrganizationView.tsx b/ui/src/organizations/containers/OrganizationView.tsx index b45ca2f606..c55476dd7a 100644 --- a/ui/src/organizations/containers/OrganizationView.tsx +++ b/ui/src/organizations/containers/OrganizationView.tsx @@ -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>