Send notification when copying to clipbaord

pull/10616/head
Iris Scholten 2018-06-05 14:24:56 -07:00
parent bcc7b36ec5
commit 36581a765e
4 changed files with 46 additions and 17 deletions

View File

@ -1,5 +1,6 @@
import React, {PureComponent} from 'react' import React, {PureComponent} from 'react'
import {NotificationContext} from 'src/flux/containers/CheckServices'
import DatabaseListItem from 'src/flux/components/DatabaseListItem' import DatabaseListItem from 'src/flux/components/DatabaseListItem'
import {showDatabases} from 'src/shared/apis/metaQuery' import {showDatabases} from 'src/shared/apis/metaQuery'
@ -49,7 +50,13 @@ class DatabaseList extends PureComponent<Props, State> {
const {service} = this.props const {service} = this.props
return databases.map(db => { return databases.map(db => {
return <DatabaseListItem db={db} key={db} service={service} /> return (
<NotificationContext.Consumer key={db}>
{({notify}) => (
<DatabaseListItem db={db} service={service} notify={notify} />
)}
</NotificationContext.Consumer>
)
}) })
} }
} }

View File

@ -1,23 +1,27 @@
import React, {PureComponent, ChangeEvent, MouseEvent} from 'react' import React, {PureComponent, ChangeEvent, MouseEvent} from 'react'
import classnames from 'classnames' import classnames from 'classnames'
import {CopyToClipboard} from 'react-copy-to-clipboard' import {CopyToClipboard} from 'react-copy-to-clipboard'
import {tagKeys as fetchTagKeys} from 'src/shared/apis/flux/metaQueries' import {tagKeys as fetchTagKeys} from 'src/shared/apis/flux/metaQueries'
import parseValuesColumn from 'src/shared/parsing/flux/values' import parseValuesColumn from 'src/shared/parsing/flux/values'
import TagList from 'src/flux/components/TagList' 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 { interface Props {
db: string db: string
service: Service service: Service
notify: (message: Notification) => void
} }
interface State { interface State {
isOpen: boolean isOpen: boolean
tags: string[] tags: string[]
searchTerm: string searchTerm: string
isCopied: boolean
copiedText: string
} }
class DatabaseListItem extends PureComponent<Props, State> { class DatabaseListItem extends PureComponent<Props, State> {
@ -27,8 +31,6 @@ class DatabaseListItem extends PureComponent<Props, State> {
isOpen: false, isOpen: false,
tags: [], tags: [],
searchTerm: '', searchTerm: '',
isCopied: false,
copiedText: '',
} }
} }
@ -106,8 +108,13 @@ class DatabaseListItem extends PureComponent<Props, State> {
e.stopPropagation() e.stopPropagation()
} }
private handleCopy = (copiedText: string): void => { private handleCopy = (copiedText: string, isSuccessful: boolean): void => {
this.setState({isCopied: true, copiedText}) const {notify} = this.props
if (isSuccessful) {
notify(notifyCopyToClipboardSuccess(copiedText))
} else {
notify(notifyCopyToClipboardFailed(copiedText))
}
} }
private onSearch = (e: ChangeEvent<HTMLInputElement>) => { private onSearch = (e: ChangeEvent<HTMLInputElement>) => {

View File

@ -15,6 +15,8 @@ import {
import * as a from 'src/shared/actions/overlayTechnology' import * as a from 'src/shared/actions/overlayTechnology'
import * as b from 'src/shared/actions/services' import * as b from 'src/shared/actions/services'
export const NotificationContext = React.createContext()
const actions = {...a, ...b} const actions = {...a, ...b}
interface Props { interface Props {
@ -54,14 +56,16 @@ export class CheckServices extends PureComponent<Props & WithRouterProps> {
} }
return ( return (
<FluxPage <NotificationContext.Provider value={{notify}}>
source={this.source} <FluxPage
services={services} source={this.source}
links={links} services={services}
script={script} links={links}
notify={notify} script={script}
updateScript={updateScript} notify={notify}
/> updateScript={updateScript}
/>
</NotificationContext.Provider>
) )
} }

View File

@ -639,6 +639,17 @@ export const analyzeSuccess = {
message: 'No errors found. Happy Happy Joy Joy!', 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 // Service notifications
export const couldNotGetServices = { export const couldNotGetServices = {
...defaultErrorNotification, ...defaultErrorNotification,