diff --git a/CHANGELOG.md b/CHANGELOG.md index 5987403c9c5..8a1936617cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ 1. [12782](https://github.com/influxdata/influxdb/pull/12782): Move bucket selection in the query builder to the first card in the list 1. [12850](https://github.com/influxdata/influxdb/pull/12850): Ensure editor is automatically focused in note editor +1. [12915](https://github.com/influxdata/influxdb/pull/12915): Add ability to edit a template's name. ## v2.0.0-alpha.6 [2019-03-15] diff --git a/ui/package-lock.json b/ui/package-lock.json index ff482360493..f03c61d6cc3 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -985,9 +985,9 @@ } }, "@influxdata/influx": { - "version": "0.2.50", - "resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.2.50.tgz", - "integrity": "sha512-M/aHzNBXcp0UKxQDh/bzZKeYe0WFz0TdZ91Bqv3LqH07j73gi5DVpZQDEoXK3Ogy2MAKvjpOMA5+1qZF3HMHRg==", + "version": "0.2.53", + "resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.2.53.tgz", + "integrity": "sha512-xOTUkDMyjT5G1yKLWt2U7FFhlmABStZtdAuMnq49CnsXxPokrWmVFcfZ0vtXTtlQLK6cdjpE/UY/N5MACBjYmQ==", "requires": { "axios": "^0.18.0" } @@ -2544,7 +2544,7 @@ }, "bindings": { "version": "1.2.1", - "resolved": "http://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=", "dev": true }, @@ -2962,7 +2962,7 @@ }, "callsites": { "version": "2.0.0", - "resolved": "http://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", "integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=", "dev": true }, @@ -3756,7 +3756,7 @@ }, "css-color-names": { "version": "0.0.4", - "resolved": "http://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", + "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", "integrity": "sha1-gIrcLnnPhHOAabZGyyDsJ762KeA=", "dev": true }, @@ -4638,7 +4638,7 @@ }, "dotenv": { "version": "5.0.1", - "resolved": "http://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz", "integrity": "sha512-4As8uPrjfwb7VXC+WnLCbXK7y+Ueb2B3zgNCePYfhxS1PYeaO1YTeplffTEcbfLhvFNGLAz90VvJs9yomG7bow==", "dev": true }, @@ -8277,7 +8277,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "dev": true }, @@ -10076,7 +10076,7 @@ }, "magic-string": { "version": "0.22.5", - "resolved": "http://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", "integrity": "sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w==", "dev": true, "requires": { @@ -11031,7 +11031,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -11458,7 +11458,7 @@ }, "json5": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", "dev": true, "requires": { diff --git a/ui/package.json b/ui/package.json index b4d5d2dac12..a87744a3c2d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -137,7 +137,7 @@ }, "dependencies": { "@influxdata/clockface": "0.0.5", - "@influxdata/influx": "0.2.50", + "@influxdata/influx": "0.2.53", "@influxdata/react-custom-scrollbars": "4.3.8", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", diff --git a/ui/src/shared/copy/notifications.ts b/ui/src/shared/copy/notifications.ts index 16c3c24db16..7a12d5c6b54 100644 --- a/ui/src/shared/copy/notifications.ts +++ b/ui/src/shared/copy/notifications.ts @@ -845,6 +845,16 @@ export const createTemplateFailed = (error: string): Notification => ({ message: `Failed to export resource as template: ${error}`, }) +export const updateTemplateSucceeded = (): Notification => ({ + ...defaultSuccessNotification, + message: `Successfully update template.`, +}) + +export const updateTemplateFailed = (error: string): Notification => ({ + ...defaultErrorNotification, + message: `Failed to update template: ${error}`, +}) + export const deleteTemplateFailed = (error: string): Notification => ({ ...defaultErrorNotification, message: `Failed to delete template: ${error}`, diff --git a/ui/src/templates/actions/index.ts b/ui/src/templates/actions/index.ts index 443cd8734d2..471937dd359 100644 --- a/ui/src/templates/actions/index.ts +++ b/ui/src/templates/actions/index.ts @@ -22,6 +22,7 @@ export enum ActionTypes { SetTemplatesStatus = 'SET_TEMPLATES_STATUS', SetExportTemplate = 'SET_EXPORT_TEMPLATE', RemoveTemplateSummary = 'REMOVE_TEMPLATE_SUMMARY', + SetTemplateSummary = 'SET_TEMPLATE_SUMMARY', } export type Actions = @@ -29,6 +30,7 @@ export type Actions = | SetTemplatesStatus | SetExportTemplate | RemoveTemplateSummary + | SetTemplateSummary export interface PopulateTemplateSummaries { type: ActionTypes.PopulateTemplateSummaries @@ -84,6 +86,33 @@ export const createTemplate = (template: DocumentCreate) => async dispatch => { } } +interface SetTemplateSummary { + type: ActionTypes.SetTemplateSummary + payload: {id: string; templateSummary: TemplateSummary} +} + +const setTemplateSummary = ( + id: string, + templateSummary: TemplateSummary +): SetTemplateSummary => ({ + type: ActionTypes.SetTemplateSummary, + payload: {id, templateSummary}, +}) + +export const updateTemplate = (id: string, props: TemplateSummary) => async ( + dispatch +): Promise => { + try { + const {meta} = await client.templates.update(id, props) + + dispatch(setTemplateSummary(id, {...props, meta})) + dispatch(notify(copy.updateTemplateSucceeded())) + } catch (e) { + console.error(e) + dispatch(notify(copy.updateTemplateFailed(e))) + } +} + export const convertToTemplate = (id: string) => async ( dispatch ): Promise => { diff --git a/ui/src/templates/components/TemplateCard.tsx b/ui/src/templates/components/TemplateCard.tsx index a30dd41580b..3eab134fc5f 100644 --- a/ui/src/templates/components/TemplateCard.tsx +++ b/ui/src/templates/components/TemplateCard.tsx @@ -7,7 +7,7 @@ import {withRouter, WithRouterProps} from 'react-router' import {ResourceList, Context, IconFont} from 'src/clockface' // Actions -import {deleteTemplate} from 'src/templates/actions' +import {deleteTemplate, updateTemplate} from 'src/templates/actions' // Types import {TemplateSummary} from '@influxdata/influx' @@ -23,6 +23,7 @@ interface OwnProps { interface DispatchProps { onDelete: typeof deleteTemplate + onUpdate: typeof updateTemplate } type Props = DispatchProps & OwnProps @@ -38,7 +39,7 @@ export class TemplateCard extends PureComponent { name={() => ( { ) } - //TODO handle rename template - private doNothing = () => {} + private handleUpdateTemplate = (name: string) => { + const {template} = this.props + + this.props.onUpdate(template.id, { + ...template, + meta: {...template.meta, name}, + }) + } private get contextMenu(): JSX.Element { const { @@ -93,6 +100,7 @@ export class TemplateCard extends PureComponent { const mdtp: DispatchProps = { onDelete: deleteTemplate, + onUpdate: updateTemplate, } export default connect<{}, DispatchProps, OwnProps>( diff --git a/ui/src/templates/reducers/index.ts b/ui/src/templates/reducers/index.ts index 31bf5c05510..df2f062c79d 100644 --- a/ui/src/templates/reducers/index.ts +++ b/ui/src/templates/reducers/index.ts @@ -42,6 +42,16 @@ const templatesReducer = ( return } + case ActionTypes.SetTemplateSummary: { + const filtered = draftState.items.filter(t => { + return t.id !== action.payload.id + }) + + draftState.items = [...filtered, action.payload.templateSummary] + + return + } + case ActionTypes.SetExportTemplate: { const {status, item, orgID} = action.payload draftState.exportTemplate.status = status