From 36581a765e808b501ddd58246ece5e30a1a38826 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Tue, 5 Jun 2018 14:24:56 -0700 Subject: [PATCH] Send notification when copying to clipbaord --- ui/src/flux/components/DatabaseList.tsx | 9 +++++++- ui/src/flux/components/DatabaseListItem.tsx | 23 ++++++++++++++------- ui/src/flux/containers/CheckServices.tsx | 20 +++++++++++------- ui/src/shared/copy/notifications.ts | 11 ++++++++++ 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ui/src/flux/components/DatabaseList.tsx b/ui/src/flux/components/DatabaseList.tsx index 73a8ef327d..b93fafeb73 100644 --- a/ui/src/flux/components/DatabaseList.tsx +++ b/ui/src/flux/components/DatabaseList.tsx @@ -1,5 +1,6 @@ import React, {PureComponent} from 'react' +import {NotificationContext} from 'src/flux/containers/CheckServices' import DatabaseListItem from 'src/flux/components/DatabaseListItem' import {showDatabases} from 'src/shared/apis/metaQuery' @@ -49,7 +50,13 @@ class DatabaseList extends PureComponent { const {service} = this.props return databases.map(db => { - return + return ( + + {({notify}) => ( + + )} + + ) }) } } diff --git a/ui/src/flux/components/DatabaseListItem.tsx b/ui/src/flux/components/DatabaseListItem.tsx index cba0d84070..185dcb95d6 100644 --- a/ui/src/flux/components/DatabaseListItem.tsx +++ b/ui/src/flux/components/DatabaseListItem.tsx @@ -1,23 +1,27 @@ import React, {PureComponent, ChangeEvent, MouseEvent} from 'react' import classnames from 'classnames' - import {CopyToClipboard} from 'react-copy-to-clipboard' + import {tagKeys as fetchTagKeys} from 'src/shared/apis/flux/metaQueries' import parseValuesColumn from 'src/shared/parsing/flux/values' import TagList from 'src/flux/components/TagList' -import {Service} from 'src/types' +import { + notifyCopyToClipboardSuccess, + notifyCopyToClipboardFailed, +} from 'src/shared/copy/notifications' + +import {Service, Notification} from 'src/types' interface Props { db: string service: Service + notify: (message: Notification) => void } interface State { isOpen: boolean tags: string[] searchTerm: string - isCopied: boolean - copiedText: string } class DatabaseListItem extends PureComponent { @@ -27,8 +31,6 @@ class DatabaseListItem extends PureComponent { isOpen: false, tags: [], searchTerm: '', - isCopied: false, - copiedText: '', } } @@ -106,8 +108,13 @@ class DatabaseListItem extends PureComponent { e.stopPropagation() } - private handleCopy = (copiedText: string): void => { - this.setState({isCopied: true, copiedText}) + private handleCopy = (copiedText: string, isSuccessful: boolean): void => { + const {notify} = this.props + if (isSuccessful) { + notify(notifyCopyToClipboardSuccess(copiedText)) + } else { + notify(notifyCopyToClipboardFailed(copiedText)) + } } private onSearch = (e: ChangeEvent) => { diff --git a/ui/src/flux/containers/CheckServices.tsx b/ui/src/flux/containers/CheckServices.tsx index 660c5a2aa0..adc4def462 100644 --- a/ui/src/flux/containers/CheckServices.tsx +++ b/ui/src/flux/containers/CheckServices.tsx @@ -15,6 +15,8 @@ import { import * as a from 'src/shared/actions/overlayTechnology' import * as b from 'src/shared/actions/services' +export const NotificationContext = React.createContext() + const actions = {...a, ...b} interface Props { @@ -54,14 +56,16 @@ export class CheckServices extends PureComponent { } return ( - + + + ) } diff --git a/ui/src/shared/copy/notifications.ts b/ui/src/shared/copy/notifications.ts index 5dfb9fb6e9..8713980b1f 100644 --- a/ui/src/shared/copy/notifications.ts +++ b/ui/src/shared/copy/notifications.ts @@ -639,6 +639,17 @@ export const analyzeSuccess = { message: 'No errors found. Happy Happy Joy Joy!', } +export const notifyCopyToClipboardSuccess = text => ({ + ...defaultSuccessNotification, + icon: 'dash-h', + message: `'${text}' has been copied to clipboard.`, +}) + +export const notifyCopyToClipboardFailed = text => ({ + ...defaultErrorNotification, + message: `'${text}' was not copied to clipboard.`, +}) + // Service notifications export const couldNotGetServices = { ...defaultErrorNotification,