Skip to content

Commit

Permalink
feat: Allow designating Single Selection items as response data ident…
Browse files Browse the repository at this point in the history
…ifiers (M2-8690) (#1738)
  • Loading branch information
farmerpaul authored Feb 14, 2025
1 parent 7e42fa9 commit 734bd1f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apps/activities/domain/response_type_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class _SelectionConfig(_ScreenConfig, PublicModel):
class SingleSelectionConfig(_SelectionConfig, PublicModel):
type: Literal[ResponseType.SINGLESELECT] | None
auto_advance: bool = False
response_data_identifier: bool = False


class MultiSelectionConfig(_SelectionConfig, PublicModel):
Expand Down
1 change: 1 addition & 0 deletions src/apps/activities/tests/fixtures/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def single_select_config(default_config: DefaultConfig) -> SingleSelectionConfig
set_alerts=False,
add_tooltip=False,
set_palette=False,
response_data_identifier=False,
**default_config.dict(),
type=ResponseType.SINGLESELECT,
)
Expand Down
2 changes: 2 additions & 0 deletions src/apps/activities/tests/unit/test_activity_item_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def test_initial_single_selection_config_change(
"Add Text Input Option was disabled",
"Input Required was disabled",
"Auto Advance was disabled",
"Response Data Identifier was disabled",
]
assert changes == exp_changes

Expand Down Expand Up @@ -488,6 +489,7 @@ def test_initial_version_changes(
"Add Text Input Option was disabled",
"Input Required was disabled",
"Auto Advance was disabled",
"Response Data Identifier was disabled",
]
changes = item_change_service.get_changes_insert(new_item)
assert changes == single_select_exp_changes
Expand Down
6 changes: 5 additions & 1 deletion src/apps/jsonld_converter/service/document/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class ReproFieldRadio(ReproFieldBase):
ld_randomize_options: bool | None = None
ld_scoring: bool | None = None
ld_response_alert: bool | None = None
ld_is_response_identifier: bool | None = None

is_multiple: bool = False
choices: list[dict] | None = None
Expand All @@ -357,7 +358,9 @@ async def _process_ld_response_options(self, options_doc: dict, drop=False):
self.ld_randomize_options = self.attr_processor.get_attr_value(options_doc, "reproschema:randomizeOptions")
self.ld_scoring = self.attr_processor.get_attr_value(options_doc, "reproschema:scoring")
self.ld_response_alert = self.attr_processor.get_attr_value(options_doc, "reproschema:responseAlert")

self.ld_is_response_identifier = self.attr_processor.get_attr_value(
options_doc, "reproschema:isResponseIdentifier"
)
self.choices = self._get_ld_choices_formatted(options_doc)

def _build_config(self, _cls: Type | None, **attrs):
Expand All @@ -367,6 +370,7 @@ def _build_config(self, _cls: Type | None, **attrs):
set_alerts=bool(self.ld_response_alert),
add_tooltip=False, # TODO
set_palette=bool(self.ld_color_palette), # TODO
response_data_identifier=bool(self.ld_is_response_identifier) if not self.is_multiple else None,
)
cfg_cls = MultiSelectionConfig if self.is_multiple else SingleSelectionConfig

Expand Down
1 change: 1 addition & 0 deletions src/apps/jsonld_converter/service/export/activity_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _build_response_options_prop(self, model: ActivityItemFull) -> dict:
"valueType": "xsd:anyURI", # todo tokens
"randomizeOptions": config.randomize_options,
"scoring": config.add_scores,
"isResponseIdentifier": config.response_data_identifier,
"responseAlert": config.set_alerts,
"colorPalette": config.set_palette,
"multipleChoice": False,
Expand Down
3 changes: 3 additions & 0 deletions src/apps/test_data/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def generate_response_value_config(type_: ResponseType):
)

result["response_values"] = None # type: ignore # noqa: E501

elif type_ == ResponseType.SINGLESELECT:
result["config"] = dict(
remove_back_button=False,
Expand All @@ -191,11 +192,13 @@ def generate_response_value_config(type_: ResponseType):
set_alerts=False,
add_tooltip=False,
set_palette=False,
response_data_identifier=False,
additional_response_option=dict( # type: ignore # noqa: E501
text_input_option=False,
text_input_required=False,
),
)

result["response_values"] = {
"options": [ # type: ignore # noqa: E501
{
Expand Down

0 comments on commit 734bd1f

Please sign in to comment.