Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31261: UDW tree is not loaded properly when switching from Bookmarks tab #251

Merged
merged 2 commits into from
Jan 29, 2020
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
5 changes: 5 additions & 0 deletions Resources/translations/universal_discovery_widget.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<target state="new">Bookmarks</target>
<note>key: bookmarks.label</note>
</trans-unit>
<trans-unit id="2467591f8170f453c7e896466beb7bb255078cb7" resname="breadcrumbs.root_location">
<source>Root Location</source>
<target state="new">Root Location</target>
<note>key: breadcrumbs.root_location</note>
</trans-unit>
<trans-unit id="d88e188b21fc4c65a6d8bdf170e0e23dfe0712a3" resname="browse.label">
<source>Browse</source>
<target state="new">Browse</target>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/universal-discovery/bookmarks.tab.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
LoadedLocationsMapContext,
SortingContext,
SortOrderContext,
RootLocationIdContext,
} from './universal.discovery.module';
import { loadAccordionData } from './services/universal.discovery.service';

Expand All @@ -26,6 +27,7 @@ const BookmarksTabModule = () => {
const [markedLocation, setMarkedLocation] = useContext(MarkedLocationContext);
const [sorting, setSorting] = useContext(SortingContext);
const [sortOrder, setSortOrder] = useContext(SortOrderContext);
const rootLocationId = useContext(RootLocationIdContext);
const [loadedLocationsMap, dispatchLoadedLocationsAction] = useContext(LoadedLocationsMapContext);
const [bookmarkedLocationMarked, setBookmarkedLocationMarked] = useState(null);
const renderBrowseLocations = () => {
Expand All @@ -49,6 +51,7 @@ const BookmarksTabModule = () => {
sortClause: sorting,
sortOrder: sortOrder,
gridView: currentView === 'grid',
rootLocationId,
},
(locationsMap) => {
dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: locationsMap });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,28 @@ const Breadcrumbs = () => {
'c-breadcrumbs__hidden-list': true,
'c-breadcrumbs__hidden-list--visible': hiddenListVisible,
});
const toggletClassNames = createCssClassNames({
const toggleClassNames = createCssClassNames({
'c-breadcrumbs__hidden-list-toggler': true,
'c-breadcrumbs__hidden-list-toggler--active': hiddenListVisible,
});

return (
<div className="c-breadcrumbs__hidden-list-wrapper">
<button className={toggletClassNames} onClick={toggleHiddenListVisible}>
<button className={toggleClassNames} onClick={toggleHiddenListVisible}>
<Icon name="options" extraClasses="ez-icon--small-medium" />
</button>
<ul className={hiddenListClassNames}>
{hiddenItems.map((item) => {
const onClickHandler = goToLocation.bind(this, item.location.id);
const locationId = item.parentLocationId;
const locationName =
locationId === 1
? Translator.trans(/*@Desc("Root Location")*/ 'breadcrumbs.root_location', {}, 'universal_discovery_widget')
: item.location.ContentInfo.Content.Name;
const onClickHandler = goToLocation.bind(this, locationId);

return (
<li key={item.location.id} onClick={onClickHandler} className="c-breadcrumbs__hidden-list-item">
{item.location.ContentInfo.Content.Name}
<li key={locationId} onClick={onClickHandler} className="c-breadcrumbs__hidden-list-item">
{locationName}
</li>
);
})}
Expand Down Expand Up @@ -86,20 +91,21 @@ const Breadcrumbs = () => {
<div className="c-breadcrumbs__list-wrapper">
<ul className="c-breadcrumbs__list">
{visibleItems.map((item, index) => {
if (!item.location) {
return null;
}

const locationId = item.parentLocationId;
const locationName =
locationId === 1
? Translator.trans(/*@Desc("Root Location")*/ 'breadcrumbs.root_location', {}, 'universal_discovery_widget')
: item.location.ContentInfo.Content.Name;
const isLast = index === visibleItems.length - 1;
const onClickHandler = goToLocation.bind(this, item.location.id);
const onClickHandler = goToLocation.bind(this, locationId);
const className = createCssClassNames({
'c-breadcrumbs__list-item': true,
'c-breadcrumbs__list-item--last': isLast,
});

return (
<li key={item.location.id} onClick={onClickHandler} className={className}>
<span className="c-breadcrumbs__list-item-text">{item.location.ContentInfo.Content.Name}</span>
<li key={locationId} onClick={onClickHandler} className={className}>
<span className="c-breadcrumbs__list-item-text">{locationName}</span>
{!isLast && renderSeparator()}
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MultipleConfigContext,
ContainersOnlyContext,
AllowedContentTypesContext,
RootLocationIdContext,
} from '../../universal.discovery.module';

const ContentTableItem = ({ location }) => {
Expand All @@ -30,6 +31,7 @@ const ContentTableItem = ({ location }) => {
const contentTypesMap = useContext(ContentTypesMapContext);
const [selectedLocations, dispatchSelectedLocationsAction] = useContext(SelectedLocationsContext);
const [multiple, multipleItemsLimit] = useContext(MultipleConfigContext);
const rootLocationId = useContext(RootLocationIdContext);
const { formatShortDateTime } = window.eZ.helpers.timezone;
const allowedContentTypes = useContext(AllowedContentTypesContext);
const contentTypeInfo = contentTypesMap[location.ContentInfo.Content.ContentType._href];
Expand Down Expand Up @@ -57,6 +59,7 @@ const ContentTableItem = ({ location }) => {
sortClause: sorting,
sortOrder: sortOrder,
gridView: currentView === 'grid',
rootLocationId,
},
(locationsMap) => {
dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: locationsMap });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const FinderBranch = ({ locationData }) => {
let resizeStartPositionX = 0;
let branchCurrentWidth = 0;
const loadMore = ({ target }) => {
const areAllItemsLoaded = loadedLocations.location && locationData.subitems.length >= loadedLocations.location.childCount;
const areAllItemsLoaded = locationData.subitems.length >= loadedLocations.totalCount;
const isOffsetReached = target.scrollHeight - target.clientHeight - target.scrollTop < SCROLL_OFFSET;

if (areAllItemsLoaded || !isOffsetReached || isLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const GridView = () => {
true
);
const loadMore = ({ target }) => {
const areAllItemsLoaded = loadedLocations.location && locationData.subitems.length >= loadedLocations.location.childCount;
const areAllItemsLoaded = locationData.subitems.length >= loadedLocations.totalCount;
const isOffsetReached = target.scrollHeight - target.clientHeight - target.scrollTop < SCROLL_OFFSET;

if (areAllItemsLoaded || !isOffsetReached || isLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ContentCreataTabModule = () => {
const parentLocationData = clonedLoadedLocations[clonedLoadedLocations.length - 1];

parentLocationData.subitems = [];
parentLocationData.location.childCount = parentLocationData.location.childCount + 1;
parentLocationData.totalCount = parentLocationData.totalCount + 1;

dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: clonedLoadedLocations });
dispatchSelectedLocationsAction({ type: 'ADD_SELECTED_LOCATION', location: items[0] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export const useFindLocationsByParentLocationIdFetch = (locationData, { sortClau
if (
!locationData.parentLocationId ||
locationData.collapsed ||
((locationData.location && locationData.subitems.length >= locationData.location.childCount) ||
locationData.subitems.length >= limit + offset)
(locationData.subitems.length >= locationData.totalCount || locationData.subitems.length >= limit + offset)
) {
dispatch({ type: 'FETCH_END', data: {} });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const findLocationsByParentLocationId = (
fetch(request)
.then(handleRequestResponse)
.then((response) => {
const { bookmark, location, permissions, subitems, version } = response;
const { bookmarked, location, permissions, subitems, version } = response;
const subitemsData = subitems.locations.map((location) => {
const mappedSubitems = {
location: location.Location,
Expand All @@ -44,28 +44,38 @@ export const findLocationsByParentLocationId = (

return mappedSubitems;
});

callback({
location: location.Location,
version: version.Version,
const locationData = {
location: location ? location.Location : null,
version: version ? version.Version : null,
totalCount: subitems.totalCount,
subitems: subitemsData,
bookmarked: bookmark,
bookmarked,
permissions,
parentLocationId,
});
};

callback(locationData);
})
.catch(showErrorNotification);
};

export const loadAccordionData = (
{ token, parentLocationId, limit = QUERY_LIMIT, sortClause = 'DatePublished', sortOrder = 'ascending', gridView = false },
{
token,
parentLocationId,
limit = QUERY_LIMIT,
sortClause = 'DatePublished',
sortOrder = 'ascending',
gridView = false,
rootLocationId = 1,
},
callback
) => {
const routeName = gridView ? 'ezplatform.udw.accordion_gridview.data' : 'ezplatform.udw.accordion.data';
const url = window.Routing.generate(routeName, {
locationId: parentLocationId,
});
const request = new Request(`${url}?limit=${limit}&sortClause=${sortClause}&sortOrder=${sortOrder}`, {
const request = new Request(`${url}?limit=${limit}&sortClause=${sortClause}&sortOrder=${sortOrder}&rootLocationId=${rootLocationId}`, {
method: 'GET',
headers: { 'X-CSRF-Token': token },
mode: 'same-origin',
Expand All @@ -88,27 +98,20 @@ export const loadAccordionData = (
});

const lastLocationData = response.columns[parentLocationId];
const subitemsData = lastLocationData.subitems.locations.map((location) => {
const mappedSubitems = {
location: location.Location,
};

if (lastLocationData.subitems.versions) {
const version = lastLocationData.subitems.versions.find(
(version) => version.Version.VersionInfo.Content._href === location.Location.Content._href
);

mappedSubitems.version = version.Version;
}

return mappedSubitems;
});
if (response.columns[1]) {
mappedItems.unshift({
subitems: [],
parentLocationId: 1,
collapsed: false,
});
}

mappedItems.push({
location: lastLocationData.location.Location,
version: lastLocationData.version.Version,
subitems: subitemsData,
bookmarked: lastLocationData.bookmark,
subitems: [],
bookmarked: lastLocationData.bookmarked,
permissions: lastLocationData.permissions,
parentLocationId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const UniversalDiscoveryModule = (props) => {
sortClause: sorting,
sortOrder: sortOrder,
gridView: currentView === 'grid',
rootLocationId: props.rootLocationId,
},
(locationsMap) => {
dispatchLoadedLocationsAction({ type: 'SET_LOCATIONS', data: locationsMap });
Expand Down