import React from "react"
import PropTypes from "prop-types"
import { fromJS } from "immutable"
import ImPropTypes from "react-immutable-proptypes"
import { sanitizeUrl } from "core/utils"
export class InfoBasePath extends React.Component {
static propTypes = {
host: PropTypes.string,
basePath: PropTypes.string
}
render() {
let { host, basePath } = this.props
return (
[ Base URL: {host}{basePath} ]
)
}
}
class Contact extends React.Component {
static propTypes = {
data: PropTypes.object,
getComponent: PropTypes.func.isRequired
}
render(){
let { data, getComponent } = this.props
let name = data.get("name") || "the developer"
let url = data.get("url")
let email = data.get("email")
const Link = getComponent("Link")
return (
{ url &&
{ name } - Website
}
{ email &&
{ url ? `Send email to ${name}` : `Contact ${name}`}
}
)
}
}
class License extends React.Component {
static propTypes = {
license: PropTypes.object,
getComponent: PropTypes.func.isRequired
}
render(){
let { license, getComponent } = this.props
const Link = getComponent("Link")
let name = license.get("name") || "License"
let url = license.get("url")
return (
{
url ? { name }
: { name }
}
)
}
}
export class InfoUrl extends React.PureComponent {
static propTypes = {
url: PropTypes.string.isRequired,
getComponent: PropTypes.func.isRequired
}
render() {
const { url, getComponent } = this.props
const Link = getComponent("Link")
return { url }
}
}
export default class Info extends React.Component {
static propTypes = {
info: PropTypes.object,
url: PropTypes.string,
host: PropTypes.string,
basePath: PropTypes.string,
externalDocs: ImPropTypes.map,
getComponent: PropTypes.func.isRequired,
}
render() {
let { info, url, host, basePath, getComponent, externalDocs } = this.props
let version = info.get("version")
let description = info.get("description")
let title = info.get("title")
let termsOfService = info.get("termsOfService")
let contact = info.get("contact")
let license = info.get("license")
const { url:externalDocsUrl, description:externalDocsDescription } = (externalDocs || fromJS({})).toJS()
const Markdown = getComponent("Markdown")
const Link = getComponent("Link")
const VersionStamp = getComponent("VersionStamp")
const InfoUrl = getComponent("InfoUrl")
const InfoBasePath = getComponent("InfoBasePath")
return (
{ title }
{ version && }
{ host || basePath ? : null }
{ url && }
{
termsOfService &&
Terms of service
}
{contact && contact.size ?
: null }
{license && license.size ?
: null }
{ externalDocsUrl ?
{externalDocsDescription || externalDocsUrl}
: null }
)
}
}
Info.propTypes = {
title: PropTypes.any,
description: PropTypes.any,
version: PropTypes.any,
url: PropTypes.string
}