/*
Copyright (C) 2017 Cloudbase Solutions SRL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import React from 'react'
import { observer } from 'mobx-react'
import styled, { css } from 'styled-components'
import Button from '@src/components/ui/Button'
import CopyButton from '@src/components/ui/CopyButton'
import StatusImage from '@src/components/ui/StatusComponents/StatusImage'
import { ThemePalette } from '@src/components/Theme'
import type { Validation as ValidationType } from '@src/@types/Endpoint'
import notificationStore from '@src/stores/NotificationStore'
import DomUtils from '@src/utils/DomUtils'
const Wrapper = styled.div`
padding: 48px 32px 32px 32px;
`
const contentStyle = css`
display: flex;
flex-direction: column;
align-items: center;
`
const Loading = styled.div`
${contentStyle}
`
const Validation = styled.div`
${contentStyle}
`
const Message = styled.div`
max-width: 100%;
overflow: auto;
margin-top: 48px;
text-align: center;
`
const Title = styled.div`
font-size: 18px;
margin-bottom: 8px;
`
const Subtitle = styled.div`
color: ${ThemePalette.grayscale[4]};
`
const Buttons = styled.div`
margin-top: 48px;
display: flex;
justify-content: ${props => (props.center ? 'center' : 'space-between')};
`
const Error = styled.div`
text-align: left;
cursor: pointer;
&:hover > span {
opacity: 1;
}
> span {
background-position-y: 4px;
margin-left: 4px;
}
`
type Props = {
loading: boolean,
validation?: ValidationType | null,
onCancelClick: () => void,
onRetryClick: () => void,
}
@observer
class EndpointValidation extends React.Component {
handleCopyClick(message: string) {
const succesful = DomUtils.copyTextToClipboard(message)
if (succesful) {
notificationStore.alert('The value has been copied to clipboard.')
} else {
notificationStore.alert('The value couldn\'t be copied', 'error')
}
}
renderLoading() {
if (!this.props.loading) {
return null
}
return (
Validating EndpointPlease wait ...
)
}
renderSuccessValidationMessage() {
if (!this.props.validation || !this.props.validation.valid || this.props.loading) {
return null
}
return (
Endpoint is ValidAll tests passed succesfully.
)
}
renderFailedValidationMessage() {
if (!this.props.validation || this.props.validation.valid || this.props.loading) {
return null
}
const message = this.props.validation.message || 'An unexpected error occurred.'
return (
Validation Failed { this.handleCopyClick(message) }}>
{message}
)
}
renderButtons() {
if (!this.props.loading && this.props.validation && this.props.validation.valid) {
return (
)
}
return (
)
}
render() {
return (
{this.renderLoading()}
{this.renderFailedValidationMessage()}
{this.renderSuccessValidationMessage()}
{this.renderButtons()}
)
}
}
export default EndpointValidation