Repository navigation
Conversation
|
Merge after #15288. |
Dicts with plain values, e.g. dict[str, Path] or dict[str, int], are now configurable and edited as a table with Add Entry and per-row Remove buttons. Dicts of models and optional values stay connectable ports.
07d7653 to
aab3246
Compare
kriben
left a comment
There was a problem hiding this comment.
Code review (open-code-review, delegation mode). Coverage: 16/16 reviewable files reviewed (100%); docs/workflow-ui-design.md excluded by OCR but read for context.
No critical/high findings. 4 medium, 4 low; see inline comments.
Looks good: dict rows without a key are kept across syncs, round-trip through the project file works, item_enum is excluded for nullable items, dicts of models/optional values remain ports, deferred row removal via PdmPointer + singleShot is safe. Tests cover project-file round trip, sync, copy and not-a-choice values. Suggested additional tests: clearing an optional enum, explicit null, scalar default for a list field.
| if ( resinsightType == "View" ) return RimWorkflowViewBinding::classKeywordStatic(); | ||
| if ( resinsightType == "Vec3" ) return RimWorkflowVec3Binding::classKeywordStatic(); | ||
| if ( fieldSchema.contains( "dict_value_type" ) ) return RimWorkflowDictBinding::classKeywordStatic(); | ||
| if ( fieldSchema.contains( "enum" ) ) return RimWorkflowEnumBinding::classKeywordStatic(); |
There was a problem hiding this comment.
[medium] Saved values are lost in existing projects. Enum/Literal fields were RimWorkflowStringBinding, list[Literal] was RimWorkflowArrayBinding, and dict fields were ports. After this change the class keyword differs, so syncFromSchema creates a new binding. Detached values are keyed by field/classKeyword, so the user-entered value is never restored and the field silently falls back to input.yaml/model default. Consider falling back to a detached/removed value with the same field name but a different keyword, and converting it.
| if ( fieldNeedingOptions != &m_value ) return options; | ||
|
|
||
| const QJsonValue value = toJsonValue(); | ||
| if ( value.isNull() ) options.push_back( caf::PdmOptionItemInfo( "(not set)", QString() ) ); |
There was a problem hiding this comment.
[medium] Optional Enum/Literal cannot be cleared. (not set) is only offered while the value is null, so once a choice is picked there is no way back to None, although the docs list Optional[...] as supported. An explicit null from input.yaml is also not preserved (no isExplicitNull() override), so when the model default is not None the null is dropped and the default is used. Suggest always offering (not set) for nullable / non-required fields and mapping it to unset / explicit null.
| else | ||
| { | ||
| // Text that is not a JSON list is kept until a value is selected | ||
| m_value = value.isString() ? value.toString() : QString(); |
There was a problem hiding this comment.
[medium] Non-list scalar default becomes "". If input.yaml holds a number/bool for a list field (e.g. levels: 3), m_hasValue is true but m_value is empty, so toJsonValue() returns the string "" and the job silently gets "" instead of 3. Wrap scalars into a one-element list, or store the JSON text of any value.
| //-------------------------------------------------------------------------------------------------- | ||
| /// | ||
| //-------------------------------------------------------------------------------------------------- | ||
| void RimWorkflowDictBinding::removeEntryByUi( RimWorkflowDictEntry* entry ) |
There was a problem hiding this comment.
[medium] A dict cannot return to unset. After removing all rows hasValue() stays true and {} is sent rather than omitting the field. For an optional dict, {} and absent may differ semantically.
| if ( type == "path" || type == "directory-path" ) | ||
| m_pathValue = value.toString(); | ||
| else if ( type == "integer" ) | ||
| m_intValue = value.toInt(); |
There was a problem hiding this comment.
[low] value.toInt() silently yields 0 for non-integral doubles or strings, and values outside the int range overflow PdmField<int>. This also applies when the dict value type changes and rows are rebuilt from the old values.
| QJsonObject values; | ||
| for ( const RimWorkflowDictEntry* entry : m_entries.childrenByType() ) | ||
| { | ||
| if ( !entry->key().isEmpty() ) values.insert( entry->key(), entry->value() ); |
There was a problem hiding this comment.
[low] Duplicate keys are silently collapsed (last row wins). Consider flagging duplicates in the table/editor.
| { | ||
| const QJsonValue value = RimWorkflowSchemaTools::literalFromText( text ); | ||
| if ( selected.contains( value ) || selectedChoices.contains( value ) ) continue; | ||
| ( choices().contains( value ) ? selectedChoices : selected ).append( value ); |
There was a problem hiding this comment.
[low] choices() parses JSON on every loop iteration here and in the loop below. Cache it in a local once.
| //-------------------------------------------------------------------------------------------------- | ||
| /// Strings are shown without quotes | ||
| //-------------------------------------------------------------------------------------------------- | ||
| QString RimWorkflowEnumBinding::choiceLabel( const QJsonValue& choice ) |
There was a problem hiding this comment.
[low] The string "1" and the integer 1 get the same label 1. Only matters for mixed-type Literals.
Fixes #15283.