-
Notifications
You must be signed in to change notification settings - Fork 0
ERA-11397 & ERA-11399 #1290
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
Merged
ERA-11397 & ERA-11399 #1290
Changes from 1 commit
Commits
Show all changes
2 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
import React, { useMemo } from 'react'; | ||
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. I decided to divide (and conquer) the
|
||
import Form from '@rjsf/bootstrap-4'; | ||
|
||
import { formValidator } from '../../utils/events'; | ||
|
||
import { | ||
AddButton, | ||
ArrayFieldItemTemplate, | ||
ArrayFieldTemplate, | ||
BaseInputTemplate, | ||
ExternalLinkField, | ||
MoveDownButton, | ||
MoveUpButton, | ||
ObjectFieldTemplate, | ||
RemoveButton, | ||
} from '../../SchemaFields'; | ||
|
||
import * as styles from './styles.module.scss'; | ||
|
||
// For V1 schemas, we basically hack a rjsf Form so they render all the fields for us and we styled them so they don't | ||
// look like fields. | ||
const V1SchemaFormSummary = ({ eventSchema, report }) => { | ||
const { schema, uiSchema } = eventSchema; | ||
|
||
const filteredSchema = useMemo(() => { | ||
const { properties = {} } = schema ?? {}; | ||
const eventDetailsKeys = Object.keys(report?.event_details ?? {}); | ||
|
||
return { | ||
...schema, | ||
properties: Object.entries(properties).reduce((acc, [key, value]) => { | ||
return eventDetailsKeys.includes(key) ? { ...acc, [key]: value } : acc; | ||
}, {}) | ||
}; | ||
}, [report, schema]); | ||
|
||
return <Form | ||
className={styles.form} | ||
disabled | ||
fields={{ externalLink: ExternalLinkField }} | ||
formData={report?.event_details} | ||
schema={filteredSchema} | ||
showErrorList={false} | ||
templates={{ | ||
ArrayFieldItemTemplate, | ||
ArrayFieldTemplate, | ||
BaseInputTemplate, | ||
ButtonTemplates: { AddButton, MoveDownButton, MoveUpButton, RemoveButton }, | ||
ObjectFieldTemplate, | ||
}} | ||
uiSchema={uiSchema} | ||
validator={formValidator} | ||
/>; | ||
}; | ||
|
||
export default V1SchemaFormSummary; |
113 changes: 113 additions & 0 deletions
113
src/ReportFormSummary/V1SchemaFormSummary/styles.module.scss
This file contains hidden or 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,113 @@ | ||
@use '../../common/styles/vars/colors'; | ||
|
||
.form { | ||
[class*=react-datepicker-wrapper] { | ||
div { | ||
border: none; | ||
padding: 0; | ||
height: auto; | ||
background: transparent; | ||
} | ||
} | ||
|
||
[class*=row] { | ||
padding: 0; | ||
|
||
> * { | ||
padding: 0; | ||
} | ||
} | ||
|
||
[class*=col-] { | ||
padding: 0; | ||
} | ||
|
||
label { | ||
color: colors.$secondary-medium-gray; | ||
font-size: 0.875rem; | ||
margin: 0.75rem 0 0; | ||
} | ||
|
||
button, | ||
input, | ||
[class*=control] { | ||
background-color: transparent !important; | ||
border: transparent; | ||
font-size: 1rem; | ||
height: 1.5rem !important; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
[class*=control] { | ||
min-height: 1.5rem; | ||
} | ||
|
||
[class*=selectWidget] { | ||
div { | ||
height: 1.5rem; | ||
display: block; | ||
padding: 0; | ||
} | ||
|
||
[class*=singleValue] { | ||
color: black; | ||
margin: 0; | ||
} | ||
} | ||
|
||
legend { | ||
border-bottom: 1px solid colors.$light-gray-border; | ||
font-size: 1rem; | ||
font-weight: 500; | ||
margin: 1.5rem 0 0.5rem; | ||
} | ||
|
||
h5 { | ||
font-size: 1rem; | ||
} | ||
|
||
hr { | ||
margin-bottom: 0; | ||
} | ||
|
||
button[class*=moveButton], | ||
button[type=submit], | ||
svg, | ||
[class*=addButton], | ||
[class*=triangle], | ||
[class*=IndicatorsContainer] { | ||
display: none !important; | ||
} | ||
|
||
[class*=checkboxesWidget] { | ||
border: none; | ||
max-height: none; | ||
overflow-y: hidden; | ||
|
||
[class*=checkbox] { | ||
margin-bottom: 0; | ||
padding-left: 0; | ||
|
||
label { | ||
color: black; | ||
font-size: 1rem; | ||
margin: 0; | ||
opacity: 1; | ||
|
||
&:before { | ||
content: "\002D"; | ||
margin-right: 0.25rem; | ||
} | ||
} | ||
|
||
input { | ||
display: none; | ||
} | ||
|
||
&:has(input:not(:checked)) { | ||
display: none; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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,75 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import getHumanizedFieldValue from '../../utils/v2-event-schemas/getHumanizedFieldValue'; | ||
import makeFieldsFromSchema from '../../utils/v2-event-schemas/makeFieldsFromSchema'; | ||
import { FORM_ELEMENT_TYPES, ROOT_CANVAS_ID } from '../../utils/v2-event-schemas/constants'; | ||
|
||
import * as styles from './styles.module.scss'; | ||
|
||
const FieldSummary = ({ field, formData, id }) => { | ||
const { i18n, t } = useTranslation('details-view', { keyPrefix: 'reportFormSummary.v2SchemaFormSummary' }); | ||
|
||
const gpsFormat = useSelector((state) => state.view.userPreferences.gpsFormat); | ||
|
||
return <> | ||
<p className={styles.fieldLabel}>{field.details.label}</p> | ||
|
||
<p className={styles.fieldValue}>{getHumanizedFieldValue( | ||
field, | ||
formData[id], | ||
'-', | ||
i18n.language, | ||
gpsFormat, | ||
t | ||
)}</p> | ||
</>; | ||
}; | ||
|
||
const SectionSummary = ({ details, fields, formData }) => <div className={styles.section}> | ||
<hr className={styles.separator} /> | ||
|
||
{details.label && <p className={styles.sectionLabel}>{details.label}</p>} | ||
|
||
<div className={styles.columns}> | ||
<div className={`${styles.column} ${details.columns === 1 ? styles.fullWidth : styles.halfWidthLeft}`}> | ||
{details.leftColumn.map((fieldId) => fields[fieldId].type === FORM_ELEMENT_TYPES.HEADER | ||
? <p | ||
className={styles[`header-${fields[fieldId].details.size.toLowerCase()}`]} | ||
key={fieldId}> | ||
{fields[fieldId].details.label} | ||
</p> | ||
: <FieldSummary | ||
field={fields[fieldId]} | ||
formData={formData} | ||
id={fieldId} | ||
key={fieldId} | ||
/>)} | ||
</div> | ||
|
||
{details.columns === 2 && <div className={`${styles.column} ${styles.halfWidthRight}`}> | ||
{details.rightColumn.map((fieldId) => <FieldSummary | ||
field={fields[fieldId]} | ||
formData={formData} | ||
id={fieldId} | ||
key={fieldId} | ||
/>)} | ||
</div>} | ||
</div> | ||
</div>; | ||
|
||
// For V2 schemas, we have a customized rendering of the details using utility functions like makeFieldsFromSchema and | ||
// getHumanizedFieldValue following the schema definition. | ||
const V2SchemaFormSummary = ({ eventSchema, formData }) => { | ||
const fields = useMemo(() => makeFieldsFromSchema(eventSchema), [eventSchema]); | ||
|
||
return fields[ROOT_CANVAS_ID]?.details.fields.map((sectionId) => <SectionSummary | ||
details={fields[sectionId].details} | ||
fields={fields} | ||
formData={formData} | ||
key={sectionId} | ||
/>); | ||
}; | ||
|
||
export default V2SchemaFormSummary; |
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.
The purpose of all the logic removed here was only to render the form summary, so it didn't make sense to keep it here. I moved it to the
ReportFormSummary
component keeping the parent (this component) cleaner.