Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions xwiki-platform-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,30 @@
</differences>
</revapi.differences>
-->



<revapi.differences>
<justification>Change the annotation value of the parameter group to make it mandatory,
while it was already mandatory in the facts (the macro displays an error when no
parameter from the group is used)</justification>
<criticality>allowed</criticality>
<differences>
<item>
<ignore>true</ignore>
<code>java.annotation.attributeAdded</code>
<old>method void org.xwiki.rendering.macro.include.IncludeMacroParameters::setPage(java.lang.String)</old>
<new>method void org.xwiki.rendering.macro.include.IncludeMacroParameters::setPage(java.lang.String)</new>
<annotation>@org.xwiki.properties.annotation.PropertyFeature(value = "reference", mandatory = true)</annotation>
<attribute>mandatory</attribute>
</item>
<item>
<ignore>true</ignore>
<code>java.annotation.attributeAdded</code>
<old>method void org.xwiki.rendering.macro.include.IncludeMacroParameters::setReference(java.lang.String)</old>
<new>method void org.xwiki.rendering.macro.include.IncludeMacroParameters::setReference(java.lang.String)</new>
<annotation>@org.xwiki.properties.annotation.PropertyFeature(value = "reference", mandatory = true)</annotation>
<attribute>mandatory</attribute>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ define('macroParameterEnhancer', ['jquery'], function($) {
childrenToRemove.push(childId);
}
}
group.children = group.children.filter(element => !childrenToRemove.includes(element));
let displayedChildren = group.children.filter(element => !childrenToRemove.includes(element));
// if the group doesn't contain any children anymore we can just hide it
if (group.children.length === 0) {
if (displayedChildren.length === 0) {
group.hidden = true;
// if the group contains a single parameter then we don't consider it's a feature only.
} else if (group.children.length === 1) {
} else if (displayedChildren.length === 1) {
group.featureOnly = false;
// if the single children is a group, we actually remove it to display directly the parameters
let uniqueChildKey = displayedChildren[0];
if (isNodeAGroup(uniqueChildKey)) {
group.children = parametersMap[uniqueChildKey].children;
}
}
visitedGroups.push(group.id);
},
Expand Down Expand Up @@ -237,6 +242,7 @@ define('macroParameterTreeDisplayer', ['jquery', 'l10n!macroEditor'], function($
let paramNode = parametersMap[nodeKey];
let radioName = 'feature-radio-' + featureName;
let radioId = radioName + '-' + paramNode.id;
let hidden = paramNode.hidden;

let nodeOutput = $(macroFeatureContentTemplate);
nodeOutput.find('.feature-radio').attr({
Expand All @@ -247,7 +253,7 @@ define('macroParameterTreeDisplayer', ['jquery', 'l10n!macroEditor'], function($
nodeOutput.find('.feature-choice-name').attr('for', radioId);
nodeOutput.find('.feature-choice-name').text(translations.get('selectFeature', paramNode.name));

if (isFeature && isMandatory) {
if (isFeature && isMandatory && !hidden) {
nodeOutput.find('.feature-radio').on('change', function() {
$(this).parents('.feature-container').find('.feature-choice-body').removeClass('mandatory');
$(this).parents('.feature-parameter').find('.feature-choice-body').addClass('mandatory');
Expand Down Expand Up @@ -554,8 +560,15 @@ define(
let emptyMandatoryParams = [];
// Include the mandatory features for which no option is checked.
macroEditor.find('.feature-container.mandatory').filter(function () {
return $(this).find('.feature-radio').length > 0 &&
$(this).find('.feature-radio:checked').length === 0;
if ($(this).find('.feature-radio').length > 0) {
return $(this).find('.feature-radio:checked').length === 0;
} else {
return $(this).find('.macro-parameter:not(.hidden)').filter(function() {
let id = $(this).attr('data-id');
let value = id === '$content' ? macroCall.content : macroCall.parameters[id];
return value === undefined || value === '';
}).first().length !== 0;
}
}).map((index, elt) => emptyMandatoryParams.push(elt));
// Exclude the hidden mandatory parameters
macroEditor.find('.macro-parameter.mandatory:not(.hidden)').filter(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ ul.macro-list .macro-extension {
margin-right: 1em;
}

.macro-name::first-letter,
.macro-description::first-letter,
.macro-parameter-name::first-letter,
.macro-parameter-description::first-letter,
.macro-parameter-group-name::first-letter,
.feature-title:first-letter,
.feature-choice-name:first-letter {
.macro-name,
.macro-description,
.macro-parameter-name,
.macro-parameter-description,
.macro-parameter-group-name,
.feature-title,
.feature-choice-name {
text-transform: capitalize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum Author
*/
@PropertyDescription("the reference of the resource to display")
@PropertyDisplayType(EntityReferenceString.class)
@PropertyFeature("reference")
@PropertyFeature(value = "reference", mandatory = true)
@PropertyGroup("stringReference")
public void setReference(String reference)
{
Expand Down Expand Up @@ -223,7 +223,7 @@ public EntityType getType()
*/
@PropertyDescription("The reference of the page to include")
@PropertyDisplayType(PageReference.class)
@PropertyFeature("reference")
@PropertyFeature(value = "reference", mandatory = true)
// Display hidden because we don't want to confuse our users by proposing two ways to enter the reference to
// include and ATM we don't have a picker for PageReference types and we do have a picker for EntityReference string
// one so we choose to keep the other one visible and hide this one. We're keeping the property so that we don't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ class IncludeMacroRefactoringTest
@RegisterExtension
private LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.WARN);

@Test
void replaceDocumentReferenceWhenNoReferenceParameterSet() throws Exception
{
MacroBlock block = new MacroBlock("include", Collections.emptyMap(), false);
assertEquals(Optional.empty(), this.includeMacroRefactoring.replaceReference(block, null, null,
(DocumentReference) null, false, Map.of()));
}

@Test
void replaceDocumentReferenceWhenEmptyReferenceParameterSet() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ private void handleFeaturesAndGroups(Map<String, List<MacroUINodeGroup>> feature
}
if (!children.isEmpty()) {
groupNode.setChildren(children.stream().map(AbstractMacroUINode::getKey).toList());
children.forEach(child -> child.setParent(groupNode.getKey()));
parametersMap.put(groupNode.getKey(), groupNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class AbstractMacroUINode
private boolean hidden;
private boolean mandatory;
private int order;
private String parent;

/**
* Default constructor.
Expand Down Expand Up @@ -172,6 +173,30 @@ public <T extends AbstractMacroUINode> T setOrder(int order)
return (T) this;
}

/**
* @return the identifier of the group the parameter belongs to or {@code null} if it doesn't belong to any group.
* @since 17.9.0RC1
*/
@Unstable
public String getParent()
{
return parent;
}

/**
*
* @param parent see {@link #getParent()}.
* @param <T> the concrete type
* @return the current instance
* @since 17.9.0RC1
*/
@Unstable
public <T extends AbstractMacroUINode> T setParent(String parent)
{
this.parent = parent;
return (T) this;
}

@Override
public boolean equals(Object o)
{
Expand All @@ -193,6 +218,7 @@ public boolean equals(Object o)
.append(id, that.id)
.append(name, that.name)
.append(description, that.description)
.append(parent, that.parent)
.isEquals();
}

Expand All @@ -207,6 +233,7 @@ public int hashCode()
.append(hidden)
.append(mandatory)
.append(order)
.append(parent)
.toHashCode();
}

Expand All @@ -221,6 +248,7 @@ public String toString()
.append("hidden", hidden)
.append("mandatory", mandatory)
.append("order", order)
.append("parent", parent)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void buildMacroDescriptorUI()
nodeParam2.setDisplayType("java.lang.Boolean");
nodeParam2.setEditTemplate("<input type=\"checkbox\" name=\"param2\" value=\"true\"/>\n"
+ "<input type=\"hidden\" name=\"param2\" value=\"false\"/>");
nodeParam2.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam3 = new MacroUINodeParameter("param3");
nodeParam3.setName("rendering.macro.myMacro.parameter.param3.nameTranslated");
Expand All @@ -239,13 +240,15 @@ void buildMacroDescriptorUI()
nodeParam3.setDeprecated(true);
nodeParam3.setDisplayType("java.lang.String");
nodeParam3.setEditTemplate("<input type=\"text\" name=\"param3\" />");
nodeParam3.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam4 = new MacroUINodeParameter("param4");
nodeParam4.setName("rendering.macro.myMacro.parameter.param4.nameTranslated");
nodeParam4.setDescription("rendering.macro.myMacro.parameter.param4.descriptionTranslated");
nodeParam4.setOrder(4);
nodeParam4.setDisplayType("java.lang.String");
nodeParam4.setEditTemplate("<input type=\"text\" name=\"param4\" />");
nodeParam4.setParent("FEATURE:myFeature");

MacroUINodeParameter nodeParam5 = new MacroUINodeParameter("param5");
nodeParam5.setName("rendering.macro.myMacro.parameter.param5.nameTranslated");
Expand All @@ -266,12 +269,14 @@ void buildMacroDescriptorUI()
nodeParam6.setOrder(6);
nodeParam6.setDisplayType("java.lang.String");
nodeParam6.setEditTemplate("<input type=\"text\" name=\"param6\" />");
nodeParam6.setParent("FEATURE:myFeature");

MacroUINodeParameter nodeParam7 = new MacroUINodeParameter("param7");
nodeParam7.setName("rendering.macro.myMacro.parameter.param7.nameTranslated");
nodeParam7.setDescription("rendering.macro.myMacro.parameter.param7.descriptionTranslated");
nodeParam7.setDisplayType("java.lang.String");
nodeParam7.setEditTemplate("<input type=\"text\" name=\"param7\" />");
nodeParam7.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam8 = new MacroUINodeParameter("param8");
nodeParam8.setName("rendering.macro.myMacro.parameter.param8.nameTranslated");
Expand All @@ -285,13 +290,15 @@ void buildMacroDescriptorUI()
nodeParam9.setDescription("rendering.macro.myMacro.parameter.param9.descriptionTranslated");
nodeParam9.setDisplayType("java.lang.String");
nodeParam9.setEditTemplate("<input type=\"text\" name=\"param9\" />");
nodeParam9.setParent("GROUP:someGroup");

MacroUINodeParameter nodeParam10 = new MacroUINodeParameter("param10");
nodeParam10.setName("rendering.macro.myMacro.parameter.param10.nameTranslated");
nodeParam10.setDescription("rendering.macro.myMacro.parameter.param10.descriptionTranslated");
nodeParam10.setOrder(8);
nodeParam10.setDisplayType("java.lang.String");
nodeParam10.setEditTemplate("<input type=\"text\" name=\"param10\" />");
nodeParam10.setParent("GROUP:someGroup");

MacroUINodeParameter nodeParam11 = new MacroUINodeParameter("param11");
nodeParam11.setName("rendering.macro.myMacro.parameter.param11.nameTranslated");
Expand All @@ -300,6 +307,7 @@ void buildMacroDescriptorUI()
nodeParam11.setHidden(true);
nodeParam11.setDisplayType("java.lang.String");
nodeParam11.setEditTemplate("<input type=\"text\" name=\"param11\" />");
nodeParam11.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam12 = new MacroUINodeParameter("param12");
nodeParam12.setName("rendering.macro.myMacro.parameter.param12.nameTranslated");
Expand All @@ -308,33 +316,38 @@ void buildMacroDescriptorUI()
nodeParam12.setAdvanced(true);
nodeParam12.setDisplayType("java.lang.String");
nodeParam12.setEditTemplate("<input type=\"text\" name=\"param12\" />");
nodeParam12.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam13 = new MacroUINodeParameter("param13");
nodeParam13.setName("rendering.macro.myMacro.parameter.param13.nameTranslated");
nodeParam13.setDescription("rendering.macro.myMacro.parameter.param13.descriptionTranslated");
nodeParam13.setOrder(11);
nodeParam13.setDisplayType("java.lang.String");
nodeParam13.setEditTemplate("<input type=\"text\" name=\"param13\" />");
nodeParam13.setParent("GROUP:someGroup");

MacroUINodeParameter nodeParam14 = new MacroUINodeParameter("param14");
nodeParam14.setName("rendering.macro.myMacro.parameter.param14.nameTranslated");
nodeParam14.setDescription("rendering.macro.myMacro.parameter.param14.descriptionTranslated");
nodeParam14.setAdvanced(true);
nodeParam14.setDisplayType("java.lang.String");
nodeParam14.setEditTemplate("<input type=\"text\" name=\"param14\" />");
nodeParam14.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam15 = new MacroUINodeParameter("param15");
nodeParam15.setName("rendering.macro.myMacro.parameter.param15.nameTranslated");
nodeParam15.setDescription("rendering.macro.myMacro.parameter.param15.descriptionTranslated");
nodeParam15.setDisplayType("java.lang.String");
nodeParam15.setEditTemplate("<input type=\"text\" name=\"param15\" />");
nodeParam15.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeParam16 = new MacroUINodeParameter("param16");
nodeParam16.setName("rendering.macro.myMacro.parameter.param16.nameTranslated");
nodeParam16.setDescription("rendering.macro.myMacro.parameter.param16.descriptionTranslated");
nodeParam16.setOrder(12);
nodeParam16.setDisplayType("java.lang.String");
nodeParam16.setEditTemplate("<input type=\"text\" name=\"param16\" />");
nodeParam16.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter nodeContent = new MacroUINodeParameter("$content");
nodeContent.setName("rendering.macroContentTranslated");
Expand All @@ -343,6 +356,7 @@ void buildMacroDescriptorUI()
nodeContent.setDisplayType("java.util.List<org.xwiki.rendering.block.Block>");
nodeContent.setEditTemplate("<textarea name=\"$content\" rows=\"7\"></textarea>");
nodeContent.setOrder(0);
nodeContent.setParent("GROUP:defaultOptionalGroup");

MacroUINodeGroup featureNode = new MacroUINodeGroup("myFeature");
featureNode.setFeature(true);
Expand Down Expand Up @@ -509,23 +523,27 @@ void buildMacroDescriptorUIWithIncludeMacroParameters()

MacroUINodeParameter referenceNode = new MacroUINodeParameter("reference")
.setEditTemplate("<input type=\"text\" name=\"reference\" />")
.setDisplayType("org.xwiki.model.reference.EntityReferenceString");
.setDisplayType("org.xwiki.model.reference.EntityReferenceString")
.setParent("GROUP:stringReference");

MacroUINodeParameter sectionNode = new MacroUINodeParameter("section")
.setEditTemplate("<input type=\"text\" name=\"section\" />")
.setDisplayType("java.lang.String")
.setAdvanced(true);
.setAdvanced(true)
.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter excludeFirstHeadingNode = new MacroUINodeParameter("excludeFirstHeading")
.setEditTemplate("<input type=\"text\" name=\"excludeFirstHeading\" />")
.setDisplayType("java.lang.String")
.setAdvanced(true);
.setAdvanced(true)
.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter contextNode = new MacroUINodeParameter("context")
.setEditTemplate("<input type=\"text\" name=\"context\" />")
.setDisplayType("java.lang.String")
.setAdvanced(true)
.setDeprecated(true);
.setDeprecated(true)
.setParent("GROUP:defaultOptionalGroup");

MacroUINodeParameter typeNode = new MacroUINodeParameter("type")
.setDisplayType("org.xwiki.model.EntityType")
Expand All @@ -546,12 +564,14 @@ void buildMacroDescriptorUIWithIncludeMacroParameters()
+ "</select>")
.setCaseInsensitive(true)
.setAdvanced(true)
.setHidden(true);
.setHidden(true)
.setParent("GROUP:stringReference");

MacroUINodeParameter pageNode = new MacroUINodeParameter("page")
.setDisplayType("org.xwiki.model.reference.PageReference")
.setEditTemplate("<input type=\"text\" name=\"page\" />")
.setHidden(true);
.setHidden(true)
.setParent("FEATURE:reference");

MacroUINodeParameter authorNode = new MacroUINodeParameter("author")
.setDisplayType("org.xwiki.wysiwyg.internal.macro.MacroDescriptorUIFactoryTest$TestEnum")
Expand All @@ -560,7 +580,8 @@ void buildMacroDescriptorUIWithIncludeMacroParameters()
+ "<option value=\"VALUE1\">VALUE1</option>"
+ "<option value=\"VALUE2\">VALUE2</option>"
+ "</select>")
.setAdvanced(true);
.setAdvanced(true)
.setParent("GROUP:defaultOptionalGroup");

MacroUINodeGroup stringReferenceGroup = new MacroUINodeGroup("stringReference")
.setFeature(true)
Expand All @@ -569,6 +590,7 @@ void buildMacroDescriptorUIWithIncludeMacroParameters()
"PARAMETER:reference",
"PARAMETER:type"
))
.setParent("FEATURE:reference")
.setName("stringReference");

MacroUINodeGroup referenceFeature = new MacroUINodeGroup("reference")
Expand Down
Loading