Просмотр исходного кода

Fix assessment details tables layout

Fix the tables layout disturbances caused by the widening of the layout.
Sergiu Miclea 8 лет назад
Родитель
Сommit
f65800b9d9

+ 18 - 20
src/components/molecules/AssessedVmListItem/index.jsx

@@ -16,7 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 import React from 'react'
 import React from 'react'
 import { observer } from 'mobx-react'
 import { observer } from 'mobx-react'
-import styled from 'styled-components'
+import styled, { css } from 'styled-components'
 
 
 import Checkbox from '../../atoms/Checkbox'
 import Checkbox from '../../atoms/Checkbox'
 import InfoIcon from '../../atoms/InfoIcon'
 import InfoIcon from '../../atoms/InfoIcon'
@@ -24,31 +24,35 @@ import DropdownLink from '../../molecules/DropdownLink'
 import type { VmItem, VmSize } from '../../../types/Assessment'
 import type { VmItem, VmSize } from '../../../types/Assessment'
 
 
 import Palette from '../../styleUtils/Palette'
 import Palette from '../../styleUtils/Palette'
-import StyleProps from '../../styleUtils/StyleProps'
 
 
 const Wrapper = styled.div`
 const Wrapper = styled.div`
   position: relative;
   position: relative;
+  width: 100%;
 `
 `
 const Content = styled.div`
 const Content = styled.div`
   display: flex;
   display: flex;
-  margin-left: -16px;
+  margin-left: -32px;
 
 
   & > div {
   & > div {
-    margin-left: 16px;
+    margin-left: 32px;
   }
   }
 
 
   opacity: ${props => props.disabled ? 0.6 : 1};
   opacity: ${props => props.disabled ? 0.6 : 1};
 `
 `
+const columnWidth = (width: string) => css`
+  width: 100%;
+  max-width: ${width};
+`
 const DisplayName = styled.div`
 const DisplayName = styled.div`
   display: flex;
   display: flex;
-  ${props => StyleProps.exactWidth(props.width)}
-`
-const DisplayNameLabel = styled.div`
-  margin-left: 8px;
+  ${props => columnWidth(props.width)}
 `
 `
 const Value = styled.div`
 const Value = styled.div`
   color: ${Palette.grayscale[4]};
   color: ${Palette.grayscale[4]};
-  ${props => props.width ? StyleProps.exactWidth(props.width) : ''}
+  ${props => columnWidth(props.width)}
+`
+const DisplayNameLabel = styled.div`
+  margin-left: 8px;
 `
 `
 const InfoIconStyled = styled(InfoIcon) `
 const InfoIconStyled = styled(InfoIcon) `
   position: absolute;
   position: absolute;
@@ -58,7 +62,6 @@ const InfoIconStyled = styled(InfoIcon) `
 
 
 type Props = {
 type Props = {
   item: VmItem,
   item: VmItem,
-  columnsWidths: string[],
   selected: boolean,
   selected: boolean,
   onSelectedChange: (item: VmItem, isChecked: boolean) => void,
   onSelectedChange: (item: VmItem, isChecked: boolean) => void,
   disabled: boolean,
   disabled: boolean,
@@ -70,11 +73,6 @@ type Props = {
 }
 }
 @observer
 @observer
 class AssessedVmListItem extends React.Component<Props> {
 class AssessedVmListItem extends React.Component<Props> {
-  getColumnWidth(index: number) {
-    let width = parseInt(this.props.columnsWidths[index], 10)
-    return `${width - 16}px`
-  }
-
   renderInfoIcon() {
   renderInfoIcon() {
     if (!this.props.disabled) {
     if (!this.props.disabled) {
       return null
       return null
@@ -100,7 +98,7 @@ class AssessedVmListItem extends React.Component<Props> {
       <Wrapper>
       <Wrapper>
         {this.renderInfoIcon()}
         {this.renderInfoIcon()}
         <Content disabled={this.props.disabled}>
         <Content disabled={this.props.disabled}>
-          <DisplayName width={this.getColumnWidth(0)}>
+          <DisplayName width="25%">
             <Checkbox
             <Checkbox
               checked={this.props.selected}
               checked={this.props.selected}
               onChange={checked => { this.props.onSelectedChange(this.props.item, checked) }}
               onChange={checked => { this.props.onSelectedChange(this.props.item, checked) }}
@@ -108,16 +106,16 @@ class AssessedVmListItem extends React.Component<Props> {
             />
             />
             <DisplayNameLabel>{`${this.props.item.properties.datacenterContainer}/${this.props.item.properties.displayName}`}</DisplayNameLabel>
             <DisplayNameLabel>{`${this.props.item.properties.datacenterContainer}/${this.props.item.properties.displayName}`}</DisplayNameLabel>
           </DisplayName>
           </DisplayName>
-          <Value width={this.getColumnWidth(1)}>
+          <Value width="25%">
             {this.props.item.properties.operatingSystem}
             {this.props.item.properties.operatingSystem}
           </Value>
           </Value>
-          <Value width={this.getColumnWidth(2)}>
+          <Value width="25%">
             {standardCount} Standard, {premiumCount} Premium
             {standardCount} Standard, {premiumCount} Premium
           </Value>
           </Value>
-          <Value>
+          <Value width="25%">
             <DropdownLink
             <DropdownLink
               searchable
               searchable
-              width={this.props.columnsWidths[3]}
+              width="208px"
               noItemsLabel="Loading..."
               noItemsLabel="Loading..."
               items={this.props.loadingVmSizes ? [] : this.props.vmSizes.map(s => ({ value: s.name, label: s.name, size: s }))}
               items={this.props.loadingVmSizes ? [] : this.props.vmSizes.map(s => ({ value: s.name, label: s.name, size: s }))}
               selectedItem={this.props.selectedVmSize ? this.props.selectedVmSize.name : ''}
               selectedItem={this.props.selectedVmSize ? this.props.selectedVmSize.name : ''}

+ 34 - 19
src/components/organisms/AssessmentDetailsContent/index.jsx

@@ -58,9 +58,11 @@ const DetailsBody = styled.div`
 `
 `
 const Columns = styled.div`
 const Columns = styled.div`
   display: flex;
   display: flex;
+  margin-left: -32px;
 `
 `
 const Column = styled.div`
 const Column = styled.div`
   width: 50%;
   width: 50%;
+  margin-left: 32px;
 `
 `
 const Row = styled.div`
 const Row = styled.div`
   margin-bottom: 32px;
   margin-bottom: 32px;
@@ -104,7 +106,7 @@ const LoadingText = styled.div`
   font-size: 18px;
   font-size: 18px;
   margin-top: 32px;
   margin-top: 32px;
 `
 `
-const TableStyled = styled(Table) `
+const TableStyled = styled(Table)`
   margin-top: 62px;
   margin-top: 62px;
   ${props => props.addWidthPadding ? css`
   ${props => props.addWidthPadding ? css`
     margin-left: -24px;
     margin-left: -24px;
@@ -121,16 +123,31 @@ const TableBodyStyle = css`
 `
 `
 const NetworkItem = styled.div`
 const NetworkItem = styled.div`
   display: flex;
   display: flex;
+  width: 100%;
+`
+const column = () => css`
+  padding-right: 32px;
+  width: 100%;
+  max-width: 25%;
 `
 `
 const NetworkName = styled.div`
 const NetworkName = styled.div`
-  ${props => StyleProps.exactWidth(props.width)}
+  ${column()}
 `
 `
 const Arrow = styled.div`
 const Arrow = styled.div`
+  width: 32px;
   height: 16px;
   height: 16px;
+  position: absolute;
+  right: 0;
   background: url('${arrowImage}') no-repeat;
   background: url('${arrowImage}') no-repeat;
-  ${props => StyleProps.exactWidth(props.width)}
   background-position-y: center;
   background-position-y: center;
 `
 `
+const ColumnStub = styled.div`
+  ${column()}
+  position: relative;
+  &:last-child {
+    padding-right: 0;
+  }
+`
 const VmHeaderItem = styled.div`
 const VmHeaderItem = styled.div`
   display: flex;
   display: flex;
   font-size: 14px;
   font-size: 14px;
@@ -316,13 +333,11 @@ class AssessmentDetailsContent extends React.Component<Props> {
       return null
       return null
     }
     }
 
 
-    const COLUMN_WIDTHS = ['278px', '186px', '260px', '180px']
     let items = this.props.filteredAssessedVms.map(vm => {
     let items = this.props.filteredAssessedVms.map(vm => {
       let filteredVm = this.props.filteredAssessedVms.find(v => v.id === vm.id)
       let filteredVm = this.props.filteredAssessedVms.find(v => v.id === vm.id)
       return (
       return (
         <AssessedVmListItem
         <AssessedVmListItem
           item={vm}
           item={vm}
-          columnsWidths={COLUMN_WIDTHS}
           selected={this.props.selectedVms.filter(m => m.id === vm.id).length > 0}
           selected={this.props.selectedVms.filter(m => m.id === vm.id).length > 0}
           onSelectedChange={(vm, selected) => { this.props.onVmSelectedChange(vm, selected) }}
           onSelectedChange={(vm, selected) => { this.props.onVmSelectedChange(vm, selected) }}
           disabled={!this.doesVmMatchSource(vm)}
           disabled={!this.doesVmMatchSource(vm)}
@@ -355,7 +370,6 @@ class AssessmentDetailsContent extends React.Component<Props> {
         items={items}
         items={items}
         bodyStyle={TableBodyStyle}
         bodyStyle={TableBodyStyle}
         headerStyle={TableHeaderStyle}
         headerStyle={TableHeaderStyle}
-        columnsWidths={COLUMN_WIDTHS}
         header={[vmHeaderItem, 'OS', 'Target Disk Type', 'Azure VM Size']}
         header={[vmHeaderItem, 'OS', 'Target Disk Type', 'Azure VM Size']}
         useSecondaryStyle
         useSecondaryStyle
         noItemsLabel="No VMs found!"
         noItemsLabel="No VMs found!"
@@ -385,7 +399,6 @@ class AssessmentDetailsContent extends React.Component<Props> {
       return null
       return null
     }
     }
 
 
-    const COLUMNS_WIDTHS = ['407px', '315px', '174px']
     let items = nics.map(nic => {
     let items = nics.map(nic => {
       let selectedNetworkName = this.props.selectedNetworks && this.props.selectedNetworks.find(n => n.sourceNic.network_name === nic.network_name)
       let selectedNetworkName = this.props.selectedNetworks && this.props.selectedNetworks.find(n => n.sourceNic.network_name === nic.network_name)
       if (selectedNetworkName) {
       if (selectedNetworkName) {
@@ -395,24 +408,26 @@ class AssessmentDetailsContent extends React.Component<Props> {
       return (
       return (
         // $FlowIgnore
         // $FlowIgnore
         <NetworkItem key={nic.network_name}>
         <NetworkItem key={nic.network_name}>
-          <NetworkName width={COLUMNS_WIDTHS[0]}>{nic.network_name}</NetworkName>
-          <Arrow width={COLUMNS_WIDTHS[1]} />
-          <DropdownLink
-            width={COLUMNS_WIDTHS[2]}
-            noItemsLabel="No Networks found"
-            selectItemLabel="Select Network"
-            selectedItem={selectedNetworkName}
-            onChange={item => { this.props.onNetworkChange(nic, item.network) }}
-            items={this.props.networks.map(network => ({ value: network.name || '', label: network.name || '', network }))}
-          />
+          <NetworkName width="25%">{nic.network_name}</NetworkName>
+          <ColumnStub width="25%"><Arrow /></ColumnStub>
+          <ColumnStub width="25%" />
+          <ColumnStub width="25%">
+            <DropdownLink
+              width="208px"
+              noItemsLabel="No Networks found"
+              selectItemLabel="Select Network"
+              selectedItem={selectedNetworkName}
+              onChange={item => { this.props.onNetworkChange(nic, item.network) }}
+              items={this.props.networks.map(network => ({ value: network.name || '', label: network.name || '', network }))}
+            />
+          </ColumnStub>
         </NetworkItem>
         </NetworkItem>
       )
       )
     })
     })
     return (
     return (
       <TableStyled
       <TableStyled
         items={items}
         items={items}
-        columnsWidths={COLUMNS_WIDTHS}
-        header={['Source Network', '', 'Target Network']}
+        header={['Source Network', '', '', 'Target Network']}
         useSecondaryStyle
         useSecondaryStyle
       />
       />
     )
     )