Skip to content

Commit

Permalink
Merge pull request #11756 from influxdata/fix/orgtasks-inline-edit
Browse files Browse the repository at this point in the history
Fix the inline edit for org tasks page
  • Loading branch information
Palakp41 authored Feb 7, 2019
2 parents cee8c6a + 28bb4ab commit 2376491
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ui/src/organizations/components/OrgTasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import {Task as TaskAPI, Organization} from '@influxdata/influx'
import {Task} from 'src/tasks/containers/TasksPage'
import {AppState} from 'src/types/v2'
import {client} from 'src/utils/api'

interface PassedInProps {
tasks: Task[]
Expand Down Expand Up @@ -127,6 +128,7 @@ class OrgTasksPage extends PureComponent<Props, State> {
onSelect={this.handleSelectTask}
onAddTaskLabels={onAddTaskLabels}
onRemoveTaskLabels={onRemoveTaskLabels}
onUpdate={this.handleUpdateTask}
/>
)}
</FilterList>
Expand All @@ -136,6 +138,11 @@ class OrgTasksPage extends PureComponent<Props, State> {
)
}

private handleUpdateTask = async (task: Task) => {
await client.tasks.update(task.id, task)
this.props.onChange()
}

private handleSelectTask = (task: Task) => {
const {selectTask, orgID} = this.props

Expand Down
2 changes: 1 addition & 1 deletion ui/src/shared/components/EditableName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'src/shared/components/EditableName.scss'
interface Props {
onUpdate: (name: string) => void
name: string
onEditName: () => void
onEditName: (e?: any) => void
hrefValue?: string
placeholder?: string
}
Expand Down
37 changes: 30 additions & 7 deletions ui/src/tasks/components/TaskRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface Task extends TaskAPI {

// Constants
import {IconFont} from 'src/clockface/types/index'
import EditableName from 'src/shared/components/EditableName'

interface Props {
task: Task
Expand All @@ -34,6 +35,7 @@ interface Props {
onSelect: (task: Task) => void
onClone: (task: Task) => void
onEditLabels: (task: Task) => void
onUpdate?: (task: Task) => void
}

export class TaskRow extends PureComponent<Props & WithRouterProps> {
Expand All @@ -47,13 +49,7 @@ export class TaskRow extends PureComponent<Props & WithRouterProps> {
stackChildren={Stack.Columns}
align={Alignment.Right}
>
<a
href="#"
onClick={this.handleClick}
className="index-list--resource-name"
>
{task.name}
</a>
{this.resourceNames}
{this.labels}
</ComponentSpacer>
</IndexList.Cell>
Expand Down Expand Up @@ -98,6 +94,33 @@ export class TaskRow extends PureComponent<Props & WithRouterProps> {
)
}

private get resourceNames(): JSX.Element {
const {onUpdate, task} = this.props
if (onUpdate) {
return (
<EditableName
onUpdate={this.handleUpdateTask}
name={task.name}
onEditName={this.handleClick}
/>
)
}
return (
<a
href="#"
onClick={this.handleClick}
className="index-list--resource-name"
>
{task.name}
</a>
)
}

private handleUpdateTask = (name: string) => {
const {onUpdate, task} = this.props
onUpdate({...task, name})
}

private handleClick = e => {
e.preventDefault()

Expand Down
4 changes: 3 additions & 1 deletion ui/src/tasks/components/TasksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
totalCount: number
onRemoveTaskLabels: typeof removeTaskLabelsAsync
onAddTaskLabels: typeof addTaskLabelsAsync
onUpdate?: (task: Task) => void
}

type SortKey = keyof Task | 'organization.name'
Expand Down Expand Up @@ -121,7 +122,7 @@ export default class TasksList extends PureComponent<Props, State> {
}

private rows = (tasks: Task[]): JSX.Element => {
const {onActivate, onDelete, onSelect, onClone} = this.props
const {onActivate, onDelete, onSelect, onClone, onUpdate} = this.props
const taskrows = (
<>
{tasks.map(t => (
Expand All @@ -133,6 +134,7 @@ export default class TasksList extends PureComponent<Props, State> {
onClone={onClone}
onSelect={onSelect}
onEditLabels={this.handleStartEditingLabels}
onUpdate={onUpdate}
/>
))}
</>
Expand Down

0 comments on commit 2376491

Please sign in to comment.