EndpointDuplicateOptions.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Copyright (C) 2017 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. // @flow
  15. import React from 'react'
  16. import { observer } from 'mobx-react'
  17. import styled from 'styled-components'
  18. import StatusImage from '../../atoms/StatusImage'
  19. import Button from '../../atoms/Button'
  20. import WizardOptionsField from '../../molecules/WizardOptionsField'
  21. import KeyboardManager from '../../../utils/KeyboardManager'
  22. import type { Project } from '../../../types/Project'
  23. import Palette from '../../styleUtils/Palette'
  24. import duplicateImage from './images/duplicate.svg'
  25. import Tooltip from '../../atoms/Tooltip'
  26. const Wrapper = styled.div`
  27. display: flex;
  28. flex-direction: column;
  29. align-items: center;
  30. padding: 0 32px 32px 32px;
  31. `
  32. const Options = styled.div`
  33. display: flex;
  34. flex-direction: column;
  35. align-items: center;
  36. width: 100%;
  37. `
  38. const Image = styled.div`
  39. margin-top: 48px;
  40. margin-bottom: 80px;
  41. width: 128px;
  42. height: 96px;
  43. background: url('${duplicateImage}') no-repeat center;
  44. `
  45. const Message = styled.div`
  46. margin-top: 48px;
  47. text-align: center;
  48. `
  49. const Title = styled.div`
  50. font-size: 18px;
  51. margin-bottom: 8px;
  52. `
  53. const Subtitle = styled.div`
  54. color: ${Palette.grayscale[4]};
  55. `
  56. const Form = styled.div`
  57. margin-bottom: 128px;
  58. `
  59. const Loading = styled.div`
  60. display: flex;
  61. flex-direction: column;
  62. align-items: center;
  63. margin-top: 32px;
  64. `
  65. const Buttons = styled.div`
  66. display: flex;
  67. justify-content: space-between;
  68. width: 100%;
  69. `
  70. const WizardOptionsFieldStyled = styled(WizardOptionsField)`
  71. width: 319px;
  72. justify-content: space-between;
  73. `
  74. type Props = {
  75. projects: Project[],
  76. selectedProjectId: string,
  77. duplicating: boolean,
  78. onCancelClick: () => void,
  79. onDuplicateClick: (projectId: string) => void,
  80. }
  81. type State = {
  82. selectedProjectId: string,
  83. }
  84. const testName = 'edOptions'
  85. @observer
  86. class EndpointDuplicateOptions extends React.Component<Props, State> {
  87. componentWillMount() {
  88. this.setState({ selectedProjectId: this.props.selectedProjectId })
  89. }
  90. componentDidMount() {
  91. KeyboardManager.onEnter('duplicate-options', () => {
  92. this.props.onDuplicateClick(this.state.selectedProjectId)
  93. }, 2)
  94. }
  95. componentWillUnmount() {
  96. KeyboardManager.removeKeyDown('duplicate-options')
  97. }
  98. renderDuplicating() {
  99. return (
  100. <Loading data-test-id={`${testName}-loading`}>
  101. <StatusImage data loading />
  102. <Message>
  103. <Title>Duplicating Endpoint</Title>
  104. <Subtitle>Please wait ...</Subtitle>
  105. </Message>
  106. </Loading>
  107. )
  108. }
  109. renderOptions() {
  110. return (
  111. <Options>
  112. <Image />
  113. <Form>
  114. <WizardOptionsFieldStyled
  115. data-test-id={`${testName}-field-project`}
  116. name="duplicate_to_project"
  117. type="string"
  118. enum={this.props.projects}
  119. skipNullValue
  120. value={this.state.selectedProjectId}
  121. onChange={projectId => { this.setState({ selectedProjectId: projectId }) }}
  122. width={318}
  123. />
  124. <Tooltip />
  125. {Tooltip.rebuild()}
  126. </Form>
  127. <Buttons>
  128. <Button secondary onClick={this.props.onCancelClick}>Cancel</Button>
  129. <Button
  130. data-test-id={`${testName}-duplicateButton`}
  131. onClick={() => { this.props.onDuplicateClick(this.state.selectedProjectId) }}
  132. >Duplicate</Button>
  133. </Buttons>
  134. </Options>
  135. )
  136. }
  137. render() {
  138. return (
  139. <Wrapper>
  140. {this.props.duplicating ? this.renderDuplicating() : this.renderOptions()}
  141. </Wrapper>
  142. )
  143. }
  144. }
  145. export default EndpointDuplicateOptions