Skip to content

Conversation

@veronikaslc
Copy link
Contributor

@veronikaslc veronikaslc commented May 1, 2025

@veronikaslc veronikaslc force-pushed the selectable-options branch 2 times, most recently from 0ab1fa8 to a2e97ac Compare May 1, 2025 20:27
@marta-

This comment was marked as resolved.

@veronikaslc veronikaslc force-pushed the selectable-options branch from a2e97ac to 4b67215 Compare May 2, 2025 00:41
@veronikaslc veronikaslc changed the title [misc] Populate selectable are question with body part options on variant selection CARDS-2679: Populate selectable area question with selectable zone options on variant selection May 2, 2025
Base automatically changed from mui-upgrade to dev May 4, 2025 23:29
@veronikaslc
Copy link
Contributor Author

@marta- Can you please post here what we decided to do on the last meeting? My memory is not clear

Comment on lines 159 to 160
if (optionsLoaded && fieldsReader?.variant && fieldsReader.variant.length > 0) {
let selectableZones = {}; //here we get the zones json from the JCR node corresponding to variant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of pulling variant specifically, we look through the context and see if any of the stored fields also provide defaultOptions. If yes, we use that map to load generate the answer options. If there's more than one entry in the context that specifies defaultOptions, I think it's reasonable to only take into account the first one.

@veronikaslc veronikaslc added the Test me! Ready for testing label May 15, 2025
<FormattedText variant="caption">{hint}</FormattedText>
}>
<Info color="primary" />
<Info color="primary" sx={{mb: "-2px", ml: "2px"}}/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to have any effect. Instead, adding display: flex to the Typography style helps improve and control the alignment.

//Children

// Container for the selectable zones names corresponding to the variant
+ defaultOptions (nt:unstructured)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line at the end of the file.

final Function<Node, JsonValue> serializeNode)
{
try {
if (child.getName().equals("defaultOptions")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though child is expected to have a name, flipping the two is always safer:

Suggested change
if (child.getName().equals("defaultOptions")) {
if ("defaultOptions".equals(child.getName())) {

"@path": path + "/AnswerOption" + stringToHash(key)
}));

setOptions(variantOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: every time a selectable area question is opened for editing, the options are overwritten with the ones defined by the selected variant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in b8ceeea - although I'm not very happy with the method (having a state variable that is set to true when options are generated from defaultOptions, and to false in all places that update options from user input. A more elegant solution is welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: now once user customes any variat selection it's not possible to change variant and prepopulate another set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is intentional so the user wouldn't lose their work.

However, it sounds like the right way to approach this is to enable the user to choose what they want to do with the suggested answer options. When different suggested options are available in the context, display a dialog that shows existing options (if any) and suggested options, and allow the user to merge the suggested into the existing, replace the existing with the suggested, or ignore the suggestions.

.map(([key, value]) => ({
label: value,
value: key,
noneOfTheAbove : false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noneOfTheAbove: false is unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in b8ceeea .

Comment on lines 162 to 163
label: value,
value: key,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but label = value and value = key is a bit odd. Better names for the arguments would help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed [key, value] to [key, label] in b8ceeea .

Comment on lines 156 to 172
// Pre-populate selectableQuestion answer options with selectable zones according to the selected variant if any selected
useEffect(() => {
if (fieldsReader?.variant?.[0]?.defaultOptions) {
let variantOptions = Object.entries(fieldsReader?.variant?.[0]?.defaultOptions)
.filter(([key]) => !key.startsWith("@") && !key.startsWith("jcr:"))
.map(([key, value]) => ({
label: value,
value: key,
noneOfTheAbove : false,
"@path": path + "/AnswerOption" + stringToHash(key)
}));

setOptions(variantOptions);
}
},
[fieldsReader.variant]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code still references variant specifically, and the comments mention selectable zones. Instead, it should be agnostic of the question type. Any structured property that defines defaultOptions should be able to populate the answer options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit b8ceeea - only lightly tested.

@marta-
Copy link
Contributor

marta- commented May 16, 2025

Usability issue: now that the defaultOptions are loaded from a node, their order looks random and "Left foot" may appear before "Jaw". I could not think of any quick fixes yet. Ideas to improve this are welcome @veronikaslc @sdumitriu .

@marta- marta- added the testing... Testing in progress label May 16, 2025
@veronikaslc veronikaslc added incomplete Some of the target functionality has not yet been implemented and removed Test me! Ready for testing testing... Testing in progress labels May 20, 2025
@veronikaslc veronikaslc added the on hold To be reviewed at a later time, awaiting other fixes, decisions, etc. label Jun 24, 2025
veronikaslc and others added 5 commits November 18, 2025 01:42
…tions on variant selection

Proper resource management
…tions on variant selection

Addressed codereview comments
…tions on variant selection

* Made the code that extracts defaultOptions from variant nodes more generic
* Bug fix: prevented the variant's defaultOptions from always overwriting user options
* Minor polishing of the generated options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

incomplete Some of the target functionality has not yet been implemented on hold To be reviewed at a later time, awaiting other fixes, decisions, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants