Skip to content

Commit a39e5c4

Browse files
committed
XWIKI-23115: Page displayer in edit mode shows the document's full name instead of its title (#4058) (#4096)
* The provided fix is not enough for AWM's class editor, which needs to preview class fields before they are saved, and for this it uses a class field template that is cloned and modified by setting its name and object (xclass). The field.className we were using before is updated when the field name/xclass changes, but it's not the case for field.reference . We need to invalidate the reference cache in PropertyClass when the values used in createReference() are modified. * Improve the functional test to be able to run it multiple times on the same XWiki instance. * Even if the REST API accepts passing an absolute class reference (/rest/wikis/test/classes/test:Path.To.Class) I think it's cleaner to try to pass a local reference, to avoid the redundancy with the wiki path element. (cherry picked from commit 7c29f34)
1 parent 50996ea commit a39e5c4

File tree

6 files changed

+68
-29
lines changed
  • xwiki-platform-core
    • xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-test/xwiki-platform-appwithinminutes-test-docker/src/test/it/org/xwiki/appwithinminutes/test/ui
    • xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-resources/src/main/resources/flamingo
    • xwiki-platform-oldcore/src
    • xwiki-platform-web

6 files changed

+68
-29
lines changed

xwiki-platform-core/xwiki-platform-appwithinminutes/xwiki-platform-appwithinminutes-test/xwiki-platform-appwithinminutes-test-docker/src/test/it/org/xwiki/appwithinminutes/test/ui/UserClassFieldIT.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openqa.selenium.WebElement;
3232
import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
3333
import org.xwiki.appwithinminutes.test.po.SuggestClassFieldEditPane;
34+
import org.xwiki.model.reference.DocumentReference;
3435
import org.xwiki.test.docker.junit5.TestReference;
3536
import org.xwiki.test.docker.junit5.UITest;
3637
import org.xwiki.test.ui.TestUtils;
@@ -99,7 +100,7 @@ private void createUser(TestUtils setup, String userSuffix)
99100
void setUp(TestUtils setup, TestReference testReference)
100101
{
101102
setup.loginAsSuperAdmin();
102-
setup.deleteSpace(testReference.getLastSpaceReference());
103+
setup.deletePage(testReference, true);
103104
}
104105

105106
@Test
@@ -301,12 +302,13 @@ void applicationEntry(TestUtils setup, TestReference testReference)
301302
// Create the application entry.
302303
ClassSheetPage classSheetPage = new ClassSheetPage();
303304

304-
String className = setup.serializeReference(testReference.getLocalDocumentReference().getParent().getParent());
305-
String pageName = testReference.getLastSpaceReference().getName();
306-
InlinePage entryEditPage = classSheetPage.createNewDocument(className, pageName + "Entry");
305+
String location = setup.serializeLocalReference(testReference.getLastSpaceReference());
306+
InlinePage entryEditPage = classSheetPage.createNewDocument(location, "Entry");
307307

308308
// Assert the initial value.
309-
String id = className + "." + pageName + "_0_user1";
309+
String className = setup.serializeReference(
310+
new DocumentReference("Class", testReference.getLastSpaceReference()).getLocalDocumentReference());
311+
String id = className + "_0_user1";
310312
userPicker = new SuggestInputElement(setup.getDriver().findElement(By.id(id)));
311313
List<SuggestionElement> selectedUsers = userPicker.getSelectedSuggestions();
312314
assertEquals(1, selectedUsers.size());
@@ -327,7 +329,8 @@ void applicationEntry(TestUtils setup, TestReference testReference)
327329

328330
private ApplicationClassEditPage goToEditor(TestReference testReference)
329331
{
330-
return ApplicationClassEditPage.goToEditor(testReference.getLastSpaceReference());
332+
return ApplicationClassEditPage
333+
.goToEditor(new DocumentReference("Class", testReference.getLastSpaceReference()));
331334
}
332335

333336
/**

xwiki-platform-core/xwiki-platform-flamingo/xwiki-platform-flamingo-skin/xwiki-platform-flamingo-skin-resources/src/main/resources/flamingo/macros.vm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@
375375
#set ($discard = $xwiki.jsfx.use('uicomponents/suggest/suggestPropertyValues.js'))
376376
<select id="xwiki-livetable-${htmlLiveTableId}-filter-${foreach.count}" name="$!escapetool.xml($column)"
377377
class="suggest-propertyValues" multiple="multiple" size="1"
378-
data-className="$!escapetool.xml($xproperty.className)" data-propertyName="$!escapetool.xml($xproperty.name)"
378+
data-className="$!escapetool.xml($services.model.serialize($xproperty.reference.parent, 'default'))"
379+
data-propertyName="$!escapetool.xml($xproperty.name)"
379380
title="$!filterTitle">
380381
</select>
381382
#end

xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/objects/classes/PropertyClass.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void setObject(BaseCollection object)
142142
{
143143
if (this.xclass != object) {
144144
this.xclass = (BaseClass) object;
145+
this.referenceCache = null;
145146

146147
if (object != null) {
147148
setOwnerDocument(object.getOwnerDocument());
@@ -429,6 +430,7 @@ public String getName()
429430
public void setName(String name)
430431
{
431432
setStringValue("name", name);
433+
this.referenceCache = null;
432434
}
433435

434436
public String getCustomDisplay()

xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/objects/classes/PropertyClassTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.xwiki.display.internal.DocumentDisplayer;
3232
import org.xwiki.display.internal.DocumentDisplayerParameters;
3333
import org.xwiki.job.event.status.JobProgressManager;
34+
import org.xwiki.model.reference.ClassPropertyReference;
3435
import org.xwiki.model.reference.DocumentReference;
3536
import org.xwiki.model.reference.DocumentReferenceResolver;
3637
import org.xwiki.model.reference.EntityReferenceSerializer;
@@ -250,4 +251,24 @@ public void getFieldFullNameForMetaProperty()
250251
propertyClass.setxWikiClass(metaClass);
251252
assertEquals("TextArea_editor", propertyClass.getFieldFullName());
252253
}
254+
255+
@Test
256+
void getReference()
257+
{
258+
PropertyClass propertyClass = new PropertyClass();
259+
propertyClass.setName("tags");
260+
propertyClass.setObject(this.xclass);
261+
assertEquals(new ClassPropertyReference("tags", this.xclass.getReference()), propertyClass.getReference());
262+
263+
// Modify the property name.
264+
propertyClass.setName("users");
265+
assertEquals(new ClassPropertyReference("users", this.xclass.getReference()), propertyClass.getReference());
266+
267+
// Modify the class reference.
268+
DocumentReference newClassReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "NewClass");
269+
BaseClass newClass = new BaseClass();
270+
newClass.setOwnerDocument(new XWikiDocument(newClassReference));
271+
propertyClass.setObject(newClass);
272+
assertEquals(new ClassPropertyReference("users", newClass.getReference()), propertyClass.getReference());
273+
}
253274
}

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/main/resources/templates/macros.vm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,8 @@ $Msz MB##
17371737
#set ($discard = $xwiki.jsfx.use('uicomponents/suggest/suggestPropertyValues.js'))
17381738
<select id="xwiki-livetable-${htmlLiveTableId}-filter-${foreach.count}" name="$!escapetool.xml($column)"
17391739
class="suggest-propertyValues" multiple="multiple" size="1"
1740-
data-className="$!escapetool.xml($xproperty.className)" data-propertyName="$!escapetool.xml($xproperty.name)"
1740+
data-className="$!escapetool.xml($services.model.serialize($xproperty.reference.parent, 'default'))"
1741+
data-propertyName="$!escapetool.xml($xproperty.name)"
17411742
title="$escapedTitle">
17421743
</select>
17431744
#end

xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-war/src/main/webapp/resources/uicomponents/suggest/suggestPropertyValues.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,40 @@
1717
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1818
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
1919
*/
20-
define('xwiki-suggestPropertyValues', ['jquery', 'xwiki-selectize'], function($) {
21-
var getSelectizeOptions = function(select) {
22-
var loadURL = [
20+
define('xwiki-suggestPropertyValues', ['jquery', 'xwiki-entityReference', 'xwiki-selectize'], function($, XWiki) {
21+
function getSelectizeOptions(select) {
22+
const classReference = XWiki.Model.resolve(
23+
select.attr('data-className'),
24+
XWiki.EntityType.DOCUMENT,
25+
// The class name is usually specified using a local document reference but it can also be an absolute reference,
26+
// so we resolve it relative to the current wiki.
27+
new XWiki.WikiReference(XWiki.currentWiki)
28+
);
29+
const wikiReference = classReference.extractReference(XWiki.EntityType.WIKI);
30+
const loadURL = [
2331
XWiki.contextPath, 'rest',
24-
'wikis', encodeURIComponent(XWiki.currentWiki),
25-
'classes', encodeURIComponent(select.attr('data-className')),
32+
'wikis', encodeURIComponent(wikiReference.getName()),
33+
'classes', encodeURIComponent(XWiki.Model.serialize(classReference.relativeTo(wikiReference))),
2634
'properties', encodeURIComponent(select.attr('data-propertyName')),
2735
'values'
2836
].join('/');
2937

30-
var getLoad = function(getOptions) {
31-
return function(text, callback) {
32-
$.getJSON(loadURL, getOptions(text)).then(function(response) {
33-
if (response && Array.isArray(response.propertyValues)) {
34-
return response.propertyValues.map(getSuggestion);
38+
function getLoad(getOptions) {
39+
return async (text, callback) => {
40+
try {
41+
const response = await $.getJSON(loadURL, getOptions(text));
42+
if (Array.isArray(response?.propertyValues)) {
43+
callback(response.propertyValues.map(getSuggestion));
3544
} else {
36-
return [];
45+
callback([]);
3746
}
38-
}).then(callback, callback);
47+
} catch {
48+
callback();
49+
}
3950
};
4051
}
4152

42-
var options = {
53+
const options = {
4354
create: true,
4455
load: getLoad(function(text) {
4556
return { 'fp': text, 'limit': 10 }
@@ -49,7 +60,7 @@ define('xwiki-suggestPropertyValues', ['jquery', 'xwiki-selectize'], function($)
4960
})
5061
};
5162

52-
var freeText = select.attr('data-freeText');
63+
let freeText = select.attr('data-freeText');
5364
if (freeText) {
5465
freeText = freeText.toLowerCase();
5566
if (freeText === 'allowed') {
@@ -60,18 +71,18 @@ define('xwiki-suggestPropertyValues', ['jquery', 'xwiki-selectize'], function($)
6071
}
6172

6273
return options;
63-
};
74+
}
6475

65-
var getSuggestion = function(propertyValue) {
66-
var metaData = propertyValue.metaData || {};
76+
function getSuggestion(propertyValue) {
77+
const metaData = propertyValue.metaData || {};
6778
return {
6879
value: propertyValue.value,
6980
label: metaData.label,
7081
icon: metaData.icon,
7182
url: metaData.url,
7283
hint: metaData.hint
7384
};
74-
};
85+
}
7586

7687
$.fn.suggestPropertyValues = function() {
7788
return this.each(function() {
@@ -81,10 +92,10 @@ define('xwiki-suggestPropertyValues', ['jquery', 'xwiki-selectize'], function($)
8192
});
8293

8394
require(['jquery', 'xwiki-suggestPropertyValues', 'xwiki-events-bridge'], function($) {
84-
var init = function(event, data) {
85-
var container = $((data && data.elements) || document);
95+
function init(event, data) {
96+
const container = $(data?.elements || document);
8697
container.find('.suggest-propertyValues').suggestPropertyValues();
87-
};
98+
}
8899

89100
$(document).on('xwiki:dom:updated', init);
90101
$(init);

0 commit comments

Comments
 (0)