Update telegraf to display notifications for update/delete

pull/12222/head
Palak Bhojani 2019-02-27 13:01:39 -08:00
parent 5a63037e76
commit f200db59fb
8 changed files with 53 additions and 13 deletions

View File

@ -126,7 +126,7 @@ class DashboardIndex extends PureComponent<Props, State> {
<DashboardsIndexContents <DashboardsIndexContents
filterComponent={() => ( filterComponent={() => (
<SearchWidget <SearchWidget
placeholderText="Filter dashboards by name..." placeholderText="Filter dashboards..."
onSearch={this.handleFilterDashboards} onSearch={this.handleFilterDashboards}
searchTerm={searchTerm} searchTerm={searchTerm}
/> />

View File

@ -74,7 +74,7 @@ export default class Buckets extends PureComponent<Props, State> {
<Tabs.TabContentsHeader> <Tabs.TabContentsHeader>
<Input <Input
icon={IconFont.Search} icon={IconFont.Search}
placeholder="Filter Buckets..." placeholder="Filter buckets..."
widthPixels={290} widthPixels={290}
value={searchTerm} value={searchTerm}
onChange={this.handleFilterChange} onChange={this.handleFilterChange}

View File

@ -13,7 +13,7 @@ import {getDeep} from 'src/utils/wrappers'
interface Props { interface Props {
collectors: Telegraf[] collectors: Telegraf[]
emptyState: JSX.Element emptyState: JSX.Element
onDelete: (telegrafID: string) => void onDelete: (telegraf: Telegraf) => void
onUpdate: (telegraf: Telegraf) => void onUpdate: (telegraf: Telegraf) => void
onOpenInstructions: (telegrafID: string) => void onOpenInstructions: (telegrafID: string) => void
onOpenTelegrafConfig: (telegrafID: string, telegrafName: string) => void onOpenTelegrafConfig: (telegrafID: string, telegrafName: string) => void

View File

@ -24,7 +24,7 @@ import {DEFAULT_COLLECTOR_NAME} from 'src/dashboards/constants'
interface Props { interface Props {
collector: Telegraf collector: Telegraf
bucket: string bucket: string
onDelete: (telegrafID: string) => void onDelete: (telegraf: Telegraf) => void
onUpdate: (telegraf: Telegraf) => void onUpdate: (telegraf: Telegraf) => void
onOpenInstructions: (telegrafID: string) => void onOpenInstructions: (telegrafID: string) => void
onOpenTelegrafConfig: (telegrafID: string, telegrafName: string) => void onOpenTelegrafConfig: (telegrafID: string, telegrafName: string) => void
@ -99,7 +99,7 @@ export default class CollectorRow extends PureComponent<Props> {
} }
private handleDeleteConfig = (): void => { private handleDeleteConfig = (): void => {
this.props.onDelete(this.props.collector.id) this.props.onDelete(this.props.collector)
} }
private handleOpenInstructions = (): void => { private handleOpenInstructions = (): void => {

View File

@ -39,6 +39,12 @@ import {
clearDataLoaders, clearDataLoaders,
} from 'src/dataLoaders/actions/dataLoaders' } from 'src/dataLoaders/actions/dataLoaders'
import {DataLoaderType} from 'src/types/v2/dataLoaders' import {DataLoaderType} from 'src/types/v2/dataLoaders'
import {
telegrafUpdateSuccess,
telegrafUpdateFailed,
telegrafDeleteSuccess,
telegrafDeleteFailed,
} from 'src/shared/copy/v2/notifications'
interface OwnProps { interface OwnProps {
collectors: Telegraf[] collectors: Telegraf[]
@ -89,7 +95,7 @@ export class Collectors extends PureComponent<Props, State> {
<Tabs.TabContentsHeader> <Tabs.TabContentsHeader>
<Input <Input
icon={IconFont.Search} icon={IconFont.Search}
placeholder="Filter telegraf configs by bucket..." placeholder="Filter telegraf configs..."
widthPixels={290} widthPixels={290}
value={searchTerm} value={searchTerm}
type={InputType.Text} type={InputType.Text}
@ -248,14 +254,28 @@ export class Collectors extends PureComponent<Props, State> {
) )
} }
private handleDeleteTelegraf = async (telegrafID: string) => { private handleDeleteTelegraf = async (telegraf: Telegraf) => {
await client.telegrafConfigs.delete(telegrafID) const {onChange, notify} = this.props
this.props.onChange() try {
await client.telegrafConfigs.delete(telegraf.id)
onChange()
notify(telegrafDeleteSuccess(telegraf.name))
} catch (e) {
console.error(e)
notify(telegrafDeleteFailed(telegraf.name))
}
} }
private handleUpdateTelegraf = async (telegraf: Telegraf) => { private handleUpdateTelegraf = async (telegraf: Telegraf) => {
await client.telegrafConfigs.update(telegraf.id, telegraf) const {onChange, notify} = this.props
this.props.onChange() try {
await client.telegrafConfigs.update(telegraf.id, telegraf)
onChange()
notify(telegrafUpdateSuccess(telegraf.name))
} catch (e) {
console.error(e)
notify(telegrafUpdateFailed(telegraf.name))
}
} }
private handleFilterChange = (e: ChangeEvent<HTMLInputElement>): void => { private handleFilterChange = (e: ChangeEvent<HTMLInputElement>): void => {

View File

@ -67,7 +67,7 @@ export default class Scrapers extends PureComponent<Props, State> {
<Tabs.TabContentsHeader> <Tabs.TabContentsHeader>
<Input <Input
icon={IconFont.Search} icon={IconFont.Search}
placeholder="Filter scrapers by bucket..." placeholder="Filter scrapers..."
widthPixels={290} widthPixels={290}
value={searchTerm} value={searchTerm}
type={InputType.Text} type={InputType.Text}

View File

@ -185,3 +185,23 @@ export const scraperUpdateFailed = (scraperName: string): Notification => ({
...defaultErrorNotification, ...defaultErrorNotification,
message: `Failed to update scraper: "${scraperName}"`, message: `Failed to update scraper: "${scraperName}"`,
}) })
export const telegrafUpdateSuccess = (telegrafName: string): Notification => ({
...defaultSuccessNotification,
message: `Telegraf "${telegrafName}" was updated successfully`,
})
export const telegrafUpdateFailed = (telegrafName: string): Notification => ({
...defaultErrorNotification,
message: `Failed to update telegraf: "${telegrafName}"`,
})
export const telegrafDeleteSuccess = (telegrafName: string): Notification => ({
...defaultSuccessNotification,
message: `Telegraf "${telegrafName}" was deleted successfully`,
})
export const telegrafDeleteFailed = (telegrafName: string): Notification => ({
...defaultErrorNotification,
message: `Failed to delete telegraf: "${telegrafName}"`,
})

View File

@ -100,7 +100,7 @@ export default class TasksHeader extends PureComponent<Props> {
return ( return (
<SearchWidget <SearchWidget
placeholderText="Filter tasks by name..." placeholderText="Filter tasks..."
onSearch={setSearchTerm} onSearch={setSearchTerm}
searchTerm={searchTerm} searchTerm={searchTerm}
/> />