-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust the details component to be a little more polymorphic.
- Loading branch information
Showing
2 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
frontend/src/modules/requests/components/request/details-row.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,42 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import get from 'lodash/get'; | ||
|
||
import { RequestSchema } from '../../types'; | ||
import * as styles from './styles.css'; | ||
|
||
function getText(data, request) { | ||
const value = get(request, data.key); | ||
|
||
switch (data.inputType) { | ||
case 'checkbox': | ||
return <div>{value ? 'Yes' : 'No'}</div>; | ||
|
||
case 'radio': | ||
return data.values.find(d => d.value === value).label; | ||
|
||
default: | ||
return value || '-'; | ||
} | ||
} | ||
|
||
function DetailsRow({ data, request }) { | ||
const { key, label } = data; | ||
const text = getText(data, request); | ||
return ( | ||
<div id={`request-${key}-field`} className={styles.fieldRow}> | ||
<h6>{label}</h6> | ||
<p id={`request-${key}-text`}>{text}</p> | ||
</div> | ||
); | ||
} | ||
|
||
DetailsRow.propTypes = { | ||
data: PropTypes.shape({ | ||
label: PropTypes.string, | ||
key: PropTypes.string, | ||
}).isRequired, | ||
request: RequestSchema.isRequired, | ||
}; | ||
|
||
export default DetailsRow; |
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