-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace input/output variables list with table
- Loading branch information
Showing
4 changed files
with
122 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
app/assets/scripts/components/documents/single-view/common/variables-table.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EmptySection } from '../document-body'; | ||
import SafeReadEditor from '../../../slate/safe-read-editor'; | ||
import styled from 'styled-components'; | ||
import { VariablePropType } from '../../../../types'; | ||
|
||
const TableElement = styled.table` | ||
width: 100%; | ||
border-collapse: collapse; | ||
margin: 20px 0; | ||
`; | ||
|
||
const Tr = styled.tr` | ||
&:nth-child(even) { | ||
background-color: #f2f2f2; | ||
} | ||
`; | ||
|
||
const Th = styled.th` | ||
background-color: rgb(244, 245, 247); | ||
border: 1px solid rgb(193, 199, 208); | ||
padding: 8px; | ||
min-width: 48px; | ||
text-align: center; | ||
> * { | ||
margin: 0; | ||
} | ||
`; | ||
|
||
const Td = styled.td` | ||
background-color: rgb(255, 255, 255); | ||
border: 1px solid rgb(193, 199, 208); | ||
padding: 8px; | ||
min-width: 48px; | ||
> * { | ||
margin: 0; | ||
} | ||
`; | ||
|
||
const NameTd = styled(Td)` | ||
width: 150px; | ||
`; | ||
|
||
const UnitTd = styled(Td)` | ||
width: 100px; | ||
`; | ||
|
||
export const VariablesTable = ({ variables }) => { | ||
return ( | ||
<TableElement> | ||
<thead> | ||
<Tr> | ||
<Th>Name</Th> | ||
<Th>Long Name</Th> | ||
<Th>Unit</Th> | ||
</Tr> | ||
</thead> | ||
<tbody> | ||
{variables.map((variable) => ( | ||
<Tr key={variable.name.children[0].children[0].text}> | ||
<NameTd> | ||
<SafeReadEditor | ||
value={variable.name} | ||
whenEmpty={<EmptySection />} | ||
/> | ||
</NameTd> | ||
<Td> | ||
<SafeReadEditor | ||
value={variable.long_name} | ||
whenEmpty={<EmptySection />} | ||
/> | ||
</Td> | ||
<UnitTd> | ||
<SafeReadEditor | ||
value={variable.unit} | ||
whenEmpty={<EmptySection />} | ||
/> | ||
</UnitTd> | ||
</Tr> | ||
))} | ||
</tbody> | ||
</TableElement> | ||
); | ||
}; | ||
|
||
VariablesTable.propTypes = { | ||
variables: PropTypes.arrayOf(VariablePropType).isRequired | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
// Basic text child type | ||
const textChildType = PropTypes.shape({ | ||
const TextChildType = PropTypes.shape({ | ||
text: PropTypes.string.isRequired | ||
}); | ||
|
||
// Type for a paragraph element with children | ||
const pChildType = PropTypes.shape({ | ||
const ParagraphType = PropTypes.shape({ | ||
type: PropTypes.string.isRequired, | ||
children: PropTypes.arrayOf(textChildType).isRequired | ||
children: PropTypes.arrayOf(TextChildType).isRequired | ||
}); | ||
|
||
// Type for a variable node with children | ||
const variableNodePropType = PropTypes.shape({ | ||
children: PropTypes.arrayOf(pChildType).isRequired | ||
export const VariableNodeType = PropTypes.shape({ | ||
children: PropTypes.arrayOf(ParagraphType).isRequired | ||
}); | ||
|
||
// Type for a variable item in the list | ||
export const variableNodeType = PropTypes.shape({ | ||
name: variableNodePropType.isRequired, | ||
long_name: variableNodePropType.isRequired, | ||
unit: variableNodePropType.isRequired | ||
export const VariablePropType = PropTypes.shape({ | ||
name: VariableNodeType.isRequired, | ||
long_name: VariableNodeType.isRequired, | ||
unit: VariableNodeType.isRequired | ||
}); |