Closes #2788: Dataset metadata conditional rendering#2807
Conversation
… ajax disable property to block events
…onditional rendering
| } | ||
|
|
||
| public boolean hasChangeListener(DatasetField datasetField) { | ||
| return this.conditionalRendering != null && this.conditionalRendering.controlledBy(datasetField); |
There was a problem hiding this comment.
Now that we have inputRenderersByFieldType, couldn't we detect listeners automatically?
|
|
||
| for (DatasetField sibling : siblingsFields) { | ||
| InputFieldRenderer renderer = inputRenderersByFieldType.get(sibling.getDatasetFieldType()); | ||
| if (renderer.getConditionalRendering().isDefined()) { |
There was a problem hiding this comment.
I guess all siblings should have a renderer, but there being different filters in edit/create modes, I would still check for non-null.
diasf
left a comment
There was a problem hiding this comment.
Looks good 👍 But please check that hasChangeListener is correct when taking the first best sibling before merging.
|
|
||
| public boolean hasChangeListener(DatasetField vocabDatasetField, Map<DatasetFieldType, InputFieldRenderer> inputRenderersByFieldType) { | ||
| Optional<DatasetField> siblingField = vocabDatasetField.getDatasetFieldParent() | ||
| .getOrElseThrow(() -> new NullPointerException("datasetfield with type: " + vocabDatasetField.getTypeName() |
There was a problem hiding this comment.
I guess we could just return false in this case.
| .getDatasetFieldsChildren() | ||
| .stream() | ||
| .filter(df -> !df.getDatasetFieldType().getName().equals(vocabDatasetField.getDatasetFieldType().getName())) | ||
| .findFirst(); |
There was a problem hiding this comment.
Why only the first sibling? Couldn't it be any of the siblings? I think you could also combine it into one chain. Something like:
public boolean hasChangeListener(DatasetField vocabDatasetField, Map<DatasetFieldType, InputFieldRenderer> inputRenderersByFieldType) {
String typeName = vocabDatasetField.getDatasetFieldType().getName();
return vocabDatasetField
.getDatasetFieldParent()
.map(parent ->
parent.getDatasetFieldsChildren().stream()
.filter(df -> !df.getDatasetFieldType().getName().equals(typeName))
.map(df -> inputRenderersByFieldType.get(df.getDatasetFieldType()))
.anyMatch(renderer -> hasConditionalRenderingFor(typeName, renderer)))
.getOrElse(false);
}
private boolean hasConditionalRenderingFor(String fieldTypeName, InputFieldRenderer renderer) {
return Option.of(renderer)
.flatMap(InputFieldRenderer::getConditionalRendering)
.map(cr -> cr.getDatasetFieldName().equals(fieldTypeName))
.getOrElse(false);
}Just for inspiration, don't assume correctness 😅
No description provided.