Skip to content

Commit 7bc95ea

Browse files
WEBUI-1124 : Fix empty-label of nuxeo-favorites not appearing with POST page provider method [LTS-2025] (#3223)
* WEBUI-1124 : Fix empty-label of nuxeo-favorites not appearing with POST page provider method - Reset page provider resultsCount and list state when no favorites collection exists - Change favorites property type from Object to Array to match actual data shape - Add unit tests for _refresh() behavior * WEBUI-1124 : Explicitly set empty label to fix display on hard reload The debounced _computeLabel in PageProviderDisplayBehavior does not reliably set the empty label when the page provider was never fetched (POST method). Directly assign _computedEmptyLabel on the data-list after reset. * WEBUI-1124: fix empty label not appearing on hard reload - Add [hidden] { display: none !important } to fix CSS specificity issue where .emptyResult { display: block } was overriding the hidden attribute - Check favorites length after fetch to handle the case where the collection exists but is empty (all favorites removed) - Add test for empty collection case
1 parent 76fdf54 commit 7bc95ea

2 files changed

Lines changed: 73 additions & 3 deletions

File tree

elements/nuxeo-collections/nuxeo-favorites.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,27 @@ import { handleVerticalKeyNavigation } from '../common-utils.js';
3939
Polymer({
4040
_template: html`
4141
<style include="nuxeo-styles">
42+
:host([hidden]) {
43+
display: none !important;
44+
}
45+
46+
[hidden] {
47+
display: none !important;
48+
}
49+
4250
.content {
4351
@apply --layout-vertical;
4452
}
4553
54+
.emptyResult {
55+
opacity: 0.8;
56+
display: block;
57+
font-weight: 300;
58+
padding: 1.5em 0.7em;
59+
text-align: center;
60+
font-size: 1.1em;
61+
}
62+
4663
nuxeo-data-list {
4764
display: block;
4865
position: relative;
@@ -132,6 +149,7 @@ Polymer({
132149
<h5>[[i18n('app.favorites')]]</h5>
133150
</div>
134151
<div class="content">
152+
<div class="emptyResult" hidden$="[[!_noFavorites]]">[[i18n('favorites.empty')]]</div>
135153
<nuxeo-data-list
136154
nx-provider="favoritesProvider"
137155
id="favoritesList"
@@ -142,6 +160,7 @@ Polymer({
142160
as="favorite"
143161
empty-label="[[i18n('favorites.empty')]]"
144162
empty-label-when-filtered="[[i18n('favorites.empty')]]"
163+
hidden$="[[_noFavorites]]"
145164
>
146165
<template>
147166
<div tabindex="0" class$="[[_computedClass(selected)]]" on-keydown="_handleKeyNav">
@@ -174,9 +193,13 @@ Polymer({
174193

175194
properties: {
176195
favorites: {
177-
type: Object,
196+
type: Array,
178197
notify: true,
179198
},
199+
_noFavorites: {
200+
type: Boolean,
201+
value: false,
202+
},
180203
selectedFavorite: {
181204
type: Object,
182205
observer: '_selectedFavoriteChanged',
@@ -200,13 +223,16 @@ Polymer({
200223
},
201224

202225
_refresh() {
203-
this._fetchFavorite().then((favorite) => {
226+
return this._fetchFavorite().then((favorite) => {
204227
if (!favorite) {
228+
this._noFavorites = true;
205229
return;
206230
}
207231
this.$.favoritesProvider.params = [favorite.uid];
208232
this.$.favoritesProvider.page = 1;
209-
this.$.favoritesList.fetch();
233+
return this.$.favoritesList.fetch().then(() => {
234+
this._noFavorites = !this.favorites || this.favorites.length === 0;
235+
});
210236
});
211237
},
212238

test/nuxeo-favorites.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ suite('nuxeo-favorites', () => {
9393
});
9494
});
9595

96+
suite('_refresh', () => {
97+
test('should set _noFavorites to true when no favorite collection exists', async () => {
98+
sinon.stub(element, '_fetchFavorite').resolves(null);
99+
await element._refresh();
100+
expect(element._noFavorites).to.be.true;
101+
});
102+
103+
test('should set _noFavorites to false when favorite collection has items', async () => {
104+
element._noFavorites = true;
105+
const fav = { uid: 'fav-collection-1' };
106+
sinon.stub(element, '_fetchFavorite').resolves(fav);
107+
sinon.stub(element.$.favoritesList, 'fetch').callsFake(() => {
108+
element.favorites = [{ uid: 'doc1' }];
109+
return Promise.resolve();
110+
});
111+
await element._refresh();
112+
expect(element._noFavorites).to.be.false;
113+
expect(element.$.favoritesProvider.params).to.deep.equal([fav.uid]);
114+
expect(element.$.favoritesProvider.page).to.equal(1);
115+
expect(element.$.favoritesList.fetch).to.have.been.calledOnce;
116+
});
117+
118+
test('should set _noFavorites to true when favorite collection exists but is empty', async () => {
119+
element._noFavorites = false;
120+
const fav = { uid: 'fav-collection-1' };
121+
sinon.stub(element, '_fetchFavorite').resolves(fav);
122+
sinon.stub(element.$.favoritesList, 'fetch').callsFake(() => {
123+
element.favorites = [];
124+
return Promise.resolve();
125+
});
126+
await element._refresh();
127+
expect(element._noFavorites).to.be.true;
128+
expect(element.$.favoritesProvider.params).to.deep.equal([fav.uid]);
129+
expect(element.$.favoritesProvider.page).to.equal(1);
130+
});
131+
132+
test('should not call fetch on list when favorite is null', async () => {
133+
sinon.stub(element, '_fetchFavorite').resolves(null);
134+
const fetchSpy = sinon.spy(element.$.favoritesList, 'fetch');
135+
await element._refresh();
136+
expect(fetchSpy).to.not.have.been.called;
137+
});
138+
});
139+
96140
suite('_removeFromFavorites', () => {
97141
test('should execute operation and fire event', async () => {
98142
const stub = sinon.stub(element.$.removeFromFavOp, 'execute').resolves();

0 commit comments

Comments
 (0)