UserListItem.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 styled from 'styled-components'
  17. import { observer } from 'mobx-react'
  18. import type { User } from '../../../types/User'
  19. import Palette from '../../styleUtils/Palette'
  20. import StyleProps from '../../styleUtils/StyleProps'
  21. import userImage from './images/user.svg'
  22. const Content = styled.div`
  23. display: flex;
  24. align-items: center;
  25. border-top: 1px solid ${Palette.grayscale[1]};
  26. padding: 8px 16px;
  27. cursor: pointer;
  28. flex-grow: 1;
  29. transition: all ${StyleProps.animations.swift};
  30. min-width: 785px;
  31. &:hover {
  32. background: ${Palette.grayscale[1]};
  33. }
  34. `
  35. const Wrapper = styled.div`
  36. display: flex;
  37. align-items: center;
  38. &:last-child ${Content} {
  39. border-bottom: 1px solid ${Palette.grayscale[1]};
  40. }
  41. `
  42. const Image = styled.div`
  43. min-width: 48px;
  44. height: 48px;
  45. background: url('${userImage}') no-repeat center;
  46. margin-right: 16px;
  47. `
  48. const Title = styled.div`
  49. flex-grow: 1;
  50. overflow: hidden;
  51. margin-right: 48px;
  52. min-width: 100px;
  53. `
  54. const TitleLabel = styled.div`
  55. font-size: 16px;
  56. overflow: hidden;
  57. white-space: nowrap;
  58. text-overflow: ellipsis;
  59. `
  60. const Subtitle = styled.div`
  61. color: ${Palette.grayscale[4]};
  62. margin-top: 3px;
  63. `
  64. const ItemLabel = styled.div`
  65. color: ${Palette.grayscale[4]};
  66. `
  67. const ItemValue = styled.div`
  68. color: ${Palette.primary};
  69. overflow: hidden;
  70. text-overflow: ellipsis;
  71. white-space: nowrap;
  72. `
  73. const bodyWidth = 620
  74. const Body = styled.div`
  75. ${StyleProps.exactWidth(`${bodyWidth}px`)}
  76. display: flex;
  77. `
  78. const Data = styled.div`
  79. ${props => StyleProps.exactWidth(`${Math.floor(bodyWidth / (100 / props.percentage)) - 68}px`)}
  80. margin: 0 32px;
  81. &:last-child {
  82. margin-right: 0;
  83. }
  84. `
  85. type Props = {
  86. item: User,
  87. onClick: () => void,
  88. getProjectName: (projectId: ?string) => string,
  89. }
  90. const testName = 'ulItem'
  91. @observer
  92. class UserListItem extends React.Component<Props> {
  93. render() {
  94. return (
  95. <Wrapper>
  96. <Content data-test-id={`${testName}-content`} onClick={this.props.onClick}>
  97. <Image />
  98. <Title>
  99. <TitleLabel data-test-id={`${testName}-name`}>{this.props.item.name}</TitleLabel>
  100. <Subtitle data-test-id={`${testName}-description`}>{this.props.item.description}</Subtitle>
  101. </Title>
  102. <Body>
  103. <Data percentage={45}>
  104. <ItemLabel>Email</ItemLabel>
  105. <ItemValue data-test-id={`${testName}-email`}>
  106. {this.props.item.email || '-'}
  107. </ItemValue>
  108. </Data>
  109. <Data percentage={35}>
  110. <ItemLabel>Primary Project</ItemLabel>
  111. <ItemValue data-test-id={`${testName}-project`}>
  112. {this.props.getProjectName(this.props.item.project_id)}
  113. </ItemValue>
  114. </Data>
  115. <Data percentage={20}>
  116. <ItemLabel>Enabled</ItemLabel>
  117. <ItemValue data-test-id={`${testName}-enabled`}>
  118. {this.props.item.enabled ? 'Yes' : 'No'}
  119. </ItemValue>
  120. </Data>
  121. </Body>
  122. </Content>
  123. </Wrapper>
  124. )
  125. }
  126. }
  127. export default UserListItem