-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) adding support for questionInfo #152
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "Field tester", | ||
"pages": [ | ||
{ | ||
"label": "One", | ||
"sections": [ | ||
{ | ||
"label": "Sec One", | ||
"isExpanded": "true", | ||
"questions": [ | ||
{ | ||
"label": "Text question", | ||
"type": "obs", | ||
"required": false, | ||
"id": "id_text", | ||
"questionInfo":"sample tooltip info for text", | ||
"questionOptions": { | ||
"rendering": "text", | ||
"concept": "928def39-33c1-4ddb-8430-165db28448c8", | ||
"conceptMappings": [], | ||
"answers": [] | ||
}, | ||
"validators": [] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"processor": "EncounterFormProcessor", | ||
"encounterType": "e22e39fd-7db2-45e7-80f1-60fa0d5a4378", | ||
"referencedForms": [], | ||
"uuid": "0859d9ad-2ed4-48db-96eb-7b0ce0c9903e", | ||
"description": "A form containing most fields, to be used for testing purposes", | ||
"version": "1.0" | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.tooltip{ | ||
border: none; | ||
background-color: #f4f4f4; | ||
z-index: 999; | ||
margin-top: 0.25rem; | ||
} |
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,21 @@ | ||
import React from 'react'; | ||
import { Tooltip } from '@carbon/react'; | ||
import { Information } from '@carbon/react/icons'; | ||
import styles from './ohri-tooltip.scss'; | ||
import { OHRIFormField } from '../../../api/types'; | ||
|
||
interface OHRITooltipProps { | ||
field: OHRIFormField; | ||
} | ||
|
||
export const OHRITooltip: React.FC<OHRITooltipProps> = ({ field }) => { | ||
return ( | ||
<span> | ||
<Tooltip align="right" label={field.questionInfo} description={field.questionInfo}> | ||
<button className={styles.tooltip} type="button" data-testid={field.id}> | ||
<Information /> | ||
</button> | ||
</Tooltip> | ||
</span> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ import { OHRIUnspecified } from '../inputs/unspecified/ohri-unspecified.componen | |
import { OHRIFormField, OHRIFormFieldProps, SubmissionHandler } from '../../api/types'; | ||
import styles from './ohri-form-section.scss'; | ||
import { getFieldControlWithFallback, isUnspecifiedSupported } from './helpers'; | ||
import { OHRITooltip } from '../inputs/tooltip/ohri-tooltip'; | ||
import { subtle } from 'crypto'; | ||
|
||
interface FieldComponentMap { | ||
fieldComponent: React.ComponentType<OHRIFormFieldProps>; | ||
|
@@ -19,12 +21,12 @@ const OHRIFormSection = ({ fields, onFieldChange }) => { | |
|
||
useEffect(() => { | ||
Promise.all( | ||
fields.map(async fieldDescriptor => { | ||
fields.map(async (fieldDescriptor) => { | ||
const fieldComponent = await getFieldControlWithFallback(fieldDescriptor); | ||
const handler = await getRegisteredFieldSubmissionHandler(fieldDescriptor.type); | ||
return { fieldDescriptor, fieldComponent, handler }; | ||
}), | ||
).then(results => { | ||
).then((results) => { | ||
setFieldComponentMapEntries(results); | ||
}); | ||
}, [fields]); | ||
|
@@ -33,7 +35,7 @@ const OHRIFormSection = ({ fields, onFieldChange }) => { | |
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={() => {}}> | ||
<div className={styles.sectionContainer}> | ||
{fieldComponentMapEntries | ||
.filter(entry => entry?.fieldComponent) | ||
.filter((entry) => entry?.fieldComponent) | ||
.map((entry, index) => { | ||
const { fieldComponent: FieldComponent, fieldDescriptor, handler } = entry; | ||
if (FieldComponent) { | ||
|
@@ -47,12 +49,22 @@ const OHRIFormSection = ({ fields, onFieldChange }) => { | |
/> | ||
); | ||
return isUnspecifiedSupported(fieldDescriptor) && fieldDescriptor.questionOptions.rendering != 'group' ? ( | ||
<div key={index}> | ||
<div key={index} className={styles.parent}> | ||
{qnFragment} | ||
<OHRIUnspecified question={fieldDescriptor} onChange={onFieldChange} handler={handler} /> | ||
<div className={styles.tooltipWithUnspecified}> | ||
<OHRIUnspecified question={fieldDescriptor} onChange={onFieldChange} handler={handler} /> | ||
{fieldDescriptor.questionInfo && <OHRITooltip field={fieldDescriptor} />} | ||
</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment applies here about drying this out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been resolved. |
||
</div> | ||
) : ( | ||
<div key={index}>{qnFragment}</div> | ||
<div key={index}> | ||
<div className={styles.parent}> | ||
{qnFragment} | ||
<div className={styles.tooltip}> | ||
{fieldDescriptor.questionInfo && <OHRITooltip field={fieldDescriptor} />} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
})} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having 2 different references looks unnecessary. This can be condensed by renaming the class to some thing more generic and then adding the check only to show the Tooltip component