-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Option.additional_input to be a choice field and add textarea
input for options (#594)
- Loading branch information
1 parent
c737247
commit d511cb8
Showing
12 changed files
with
154 additions
and
18 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
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,59 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import classNames from 'classnames' | ||
import isEmpty from 'lodash/isEmpty' | ||
import isNil from 'lodash/isNil' | ||
import get from 'lodash/get' | ||
|
||
import { getId, getLabel, getHelp } from 'rdmo/management/assets/js/utils/forms' | ||
|
||
const Radio = ({ config, element, field, options, onChange }) => { | ||
const id = getId(element, field), | ||
label = getLabel(config, element, field), | ||
help = getHelp(config, element, field), | ||
warnings = get(element, ['warnings', field]), | ||
errors = get(element, ['errors', field]) | ||
|
||
const className = classNames({ | ||
'form-group': true, | ||
'has-warning': !isEmpty(warnings), | ||
'has-error': !isEmpty(errors) | ||
}) | ||
|
||
const value = isNil(element[field]) ? '' : element[field] | ||
|
||
return ( | ||
<div className={className}> | ||
<label className="control-label" htmlFor={id}>{label}</label> | ||
|
||
<div> | ||
{ | ||
options.map((option, index) => ( | ||
<label key={index} className="radio-inline"> | ||
<input type="radio" name="inlineRadioOptions" disabled={element.read_only} | ||
checked={value === option.id} | ||
value={option.id} onChange={event => onChange(field, event.target.value)}/> | ||
<span>{option.text}</span> | ||
</label> | ||
)) | ||
} | ||
</div> | ||
|
||
{help && <p className="help-block">{help}</p>} | ||
|
||
{errors && <ul className="help-block list-unstyled"> | ||
{errors.map((error, index) => <li key={index}>{error}</li>)} | ||
</ul>} | ||
</div> | ||
) | ||
} | ||
|
||
Radio.propTypes = { | ||
config: PropTypes.object, | ||
element: PropTypes.object, | ||
field: PropTypes.string, | ||
options: PropTypes.array, | ||
onChange: PropTypes.func | ||
} | ||
|
||
export default Radio |
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
27 changes: 27 additions & 0 deletions
27
rdmo/options/migrations/0032_alter_option_additional_input.py
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,27 @@ | ||
# Generated by Django 4.2.5 on 2023-10-01 12:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def run_data_migration(apps, schema_editor): | ||
Option = apps.get_model('options', 'Option') | ||
|
||
for option in Option.objects.all(): | ||
option.additional_input = 'text' if option.additional_input == 'True' else '' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MyPyDavid
Member
|
||
option.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('options', '0031_add_editors'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='option', | ||
name='additional_input', | ||
field=models.CharField(blank=True, choices=[('', 'None'), ('text', 'Text'), ('textarea', 'Textarea')], default=False, help_text='Designates whether an additional input is possible for this option.', max_length=256, verbose_name='Additional input'), | ||
), | ||
migrations.RunPython(run_data_migration), | ||
] |
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
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
Hi @jochenklar , we have one Issue with the update to 2.1.2 (from 2.0.2) in the text and options.
The previous
additional_input=True
fields are missing and all converted into-----
.Could this
'True'
be a typo in therun_data_migration
and cause of this data migration issue?