ContentPlugin.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. Copyright (C) 2022 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import * as React from 'react'
  15. import styled from 'styled-components'
  16. import type { Field } from '@src/@types/Field'
  17. import { Endpoint, Validation } from '@src/@types/Endpoint'
  18. import { ThemePalette } from '@src/components/Theme'
  19. import { Link } from 'react-router-dom'
  20. import {
  21. Wrapper, renderFields, findInvalidFields,
  22. } from '../default/ContentPlugin'
  23. const ServersInfo = styled.div`
  24. font-size: 12px;
  25. padding: 8px 32px 0;
  26. `
  27. const LinkStyled = styled(Link)`
  28. color: ${ThemePalette.primary};
  29. text-decoration: none;
  30. `
  31. const LinkDiv = styled.span`
  32. color: ${ThemePalette.primary};
  33. cursor: pointer;
  34. `
  35. type Props = {
  36. connectionInfoSchema: Field[],
  37. validation: Validation | null,
  38. invalidFields: string[],
  39. getFieldValue: (field: Field | null) => any,
  40. handleFieldChange: (field: Field | null, value: any) => void,
  41. disabled: boolean,
  42. cancelButtonText: string,
  43. validating: boolean,
  44. onRef: (contentPlugin: any) => void,
  45. handleFieldsChange: (items: { field: Field, value: any }[]) => void,
  46. originalConnectionInfo: Endpoint['connection_info'],
  47. onResizeUpdate: (scrollOffset: number) => void,
  48. scrollableRef: (ref: HTMLElement) => void,
  49. highlightRequired: () => void
  50. handleValidateClick: () => void
  51. handleCancelClick: () => void
  52. }
  53. class ContentPlugin extends React.Component<Props> {
  54. componentDidMount() {
  55. this.props.onRef(this)
  56. }
  57. componentWillUnmount() {
  58. this.props.onRef(undefined)
  59. }
  60. // eslint-disable-next-line react/no-unused-class-component-methods
  61. findInvalidFields = () => findInvalidFields(this.props.connectionInfoSchema, this.props.getFieldValue)
  62. renderFields() {
  63. return renderFields({
  64. schema: this.props.connectionInfoSchema,
  65. getFieldValue: this.props.getFieldValue,
  66. handleFieldChange: this.props.handleFieldChange,
  67. disabled: this.props.disabled,
  68. invalidFields: this.props.invalidFields,
  69. })
  70. }
  71. render() {
  72. const link = window.location.pathname === '/bare-metal-servers'
  73. ? (
  74. <LinkDiv onClick={() => window.location.reload()}>hub servers page</LinkDiv>
  75. ) : (
  76. <LinkStyled to="/bare-metal-servers">hub servers page</LinkStyled>
  77. )
  78. return (
  79. <Wrapper>
  80. <ServersInfo>To add a server to an existing hub, use the {link}.</ServersInfo>
  81. {this.renderFields()}
  82. </Wrapper>
  83. )
  84. }
  85. }
  86. export default ContentPlugin