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

IBX-1455: Redesign Content Tree for OSS #59

Merged
merged 16 commits into from
Nov 26, 2021
2 changes: 1 addition & 1 deletion src/bundle/Resources/encore/ez.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module.exports = (Encore) => {
path.resolve(__dirname, '../../ui-dev/src/modules/universal-discovery/components/view-switcher/view.switcher.js'),
path.resolve(
__dirname,
'../../ui-dev/src/modules/universal-discovery/components/tree-item-toggle-selection-button/tree.item.toggle.selection.button.js'
'../../ui-dev/src/modules/universal-discovery/components/tree-item-toggle-selection/tree.item.toggle.selection.js',
),
])
.addEntry('ezplatform-admin-ui-mfu-js', [
Expand Down
110 changes: 19 additions & 91 deletions src/bundle/Resources/public/js/scripts/admin.content.tree.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,26 @@
(function (global, doc, React, ReactDOM, eZ, localStorage) {
const KEY_CONTENT_TREE_EXPANDED = 'ez-content-tree-expanded';
const CLASS_CONTENT_TREE_EXPANDED = 'ez-content-tree-container--expanded';
const CLASS_CONTENT_TREE_ANIMATE = 'ez-content-tree-container--animate';
const CLASS_BTN_CONTENT_TREE_EXPANDED = 'ibexa-btn--content-tree-expanded';
(function (global, doc, React, ReactDOM, eZ) {
const token = doc.querySelector('meta[name="CSRF-Token"]').content;
const siteaccess = doc.querySelector('meta[name="SiteAccess"]').content;
const contentTreeContainer = doc.querySelector('.ez-content-tree-container');
const contentTreeWrapper = doc.querySelector('.ez-content-tree-container__wrapper');
const btn = doc.querySelector('.ibexa-btn--toggle-content-tree');
const contentTreeContainer = doc.querySelector('.ibexa-content-tree-container');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
Maybe we can change the name of the class because for me wrapper and container are interchangeable terms for HTML node that groups other nodes or some content

const contentTreeWrapper = doc.querySelector('.ibexa-content-tree-container__wrapper');
const { currentLocationPath, treeRootLocationId } = contentTreeContainer.dataset;
const userId = window.eZ.helpers.user.getId();
let frame = null;
const toggleContentTreePanel = () => {
doc.activeElement.blur();
contentTreeContainer.classList.toggle(CLASS_CONTENT_TREE_EXPANDED);
contentTreeContainer.classList.add(CLASS_CONTENT_TREE_ANIMATE);
btn.classList.toggle(CLASS_BTN_CONTENT_TREE_EXPANDED);
updateContentTreeWrapperHeight();

const isContentTreeExpanded = contentTreeContainer.classList.contains(CLASS_CONTENT_TREE_EXPANDED);

saveContentTreeExpandedState(userId, isContentTreeExpanded);
eZ.helpers.tooltips.hideAll();
};
const updateContentTreeWrapperHeight = () => {
const height = Math.min(window.innerHeight - contentTreeContainer.getBoundingClientRect().top, window.innerHeight);

contentTreeWrapper.style.height = `${height}px`;
};
const handleViewportChange = () => {
if (frame) {
cancelAnimationFrame(frame);
}

frame = requestAnimationFrame(updateContentTreeWrapperHeight);
};
const saveContentTreeExpandedState = (userId, isExpanded) => {
let expandedState = JSON.parse(localStorage.getItem(KEY_CONTENT_TREE_EXPANDED));

if (!(expandedState instanceof Object)) {
expandedState = {};
}

expandedState[userId] = isExpanded;

localStorage.setItem(KEY_CONTENT_TREE_EXPANDED, JSON.stringify(expandedState));
};
const isContentTreeExpanded = (userId) => {
const expandedState = JSON.parse(localStorage.getItem(KEY_CONTENT_TREE_EXPANDED));

return expandedState && expandedState[userId];
};

ReactDOM.render(
React.createElement(eZ.modules.ContentTree, {
userId,
currentLocationPath,
rootLocationId: parseInt(treeRootLocationId, 10),
restInfo: { token, siteaccess },
}),
contentTreeWrapper
);

btn.addEventListener('click', toggleContentTreePanel, false);

if (isContentTreeExpanded(userId)) {
contentTreeContainer.classList.add(CLASS_CONTENT_TREE_EXPANDED);
btn.classList.add(CLASS_BTN_CONTENT_TREE_EXPANDED);
const removeContentTreeContainerWidth = () => {
contentTreeContainer.style.width = null;
}
const renderTree = () => {
ReactDOM.render(
React.createElement(eZ.modules.ContentTree, {
userId,
currentLocationPath,
rootLocationId: parseInt(treeRootLocationId, 10),
restInfo: { token, siteaccess },
}),
contentTreeWrapper
);
}

updateContentTreeWrapperHeight();

let transitionCount = 0;
let transitionEventIntervalId = null;
const dispatchContentTreeResizeEvent = () => doc.body.dispatchEvent(new CustomEvent('ez-content-tree-resized'));
const handleContainerTransitionStart = () => {
if (transitionCount == 0) {
transitionEventIntervalId = setInterval(dispatchContentTreeResizeEvent, 30);
}

transitionCount += 1;
};
const handleContainerTransitionStop = () => {
transitionCount -= 1;

if (transitionCount == 0) {
clearInterval(transitionEventIntervalId);
dispatchContentTreeResizeEvent();
}
};

contentTreeContainer.addEventListener('transitionstart', handleContainerTransitionStart, false);
contentTreeContainer.addEventListener('transitioncancel', handleContainerTransitionStop, false);
contentTreeContainer.addEventListener('transitionend', handleContainerTransitionStop, false);
doc.body.addEventListener('ibexa-tb-rendered:ibexa-content-tree', removeContentTreeContainerWidth);

window.addEventListener('resize', handleViewportChange, { capture: false, passive: true });
})(window, window.document, window.React, window.ReactDOM, window.eZ, window.localStorage);
renderTree();
})(window, window.document, window.React, window.ReactDOM, window.eZ);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const form = doc.querySelector(SELECTOR_VISIBILITY_FORM);
const visibilityCheckboxes = doc.querySelectorAll(SELECTOR_VISIBILITY_CHECKBOXES);
const refreshContentTree = () => {
doc.body.dispatchEvent(new CustomEvent('ez-content-tree-refresh'));
doc.body.dispatchEvent(new CustomEvent('ibexa-content-tree-refresh'));
};
const onVisibilityUpdated = ({ target }) => {
const { checked: isVisible } = target;
Expand Down
30 changes: 2 additions & 28 deletions src/bundle/Resources/public/scss/_content-tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,18 @@
min-width: 0;
}

.ez-content-tree-container {
.ibexa-content-tree-container {
position: relative;
top: 0;
flex: 0 0 auto;
width: calculateRem(50px);
background: $ibexa-white;
color: inherit;

.c-list {
display: none;
}

&--animate {
transition: $ibexa-admin-widget-close-transition;

&.ez-content-tree-container--expanded {
transition: $ibexa-admin-widget-open-transition;
}
}

&--expanded {
display: initial;
width: 15vw;

.c-list {
display: block;
}

.ez-content-tree-container__wrapper {
opacity: 1;
}
}

&__wrapper {
position: -webkit-sticky;
position: sticky;
top: 0;
opacity: 0;
height: 100%;
overflow: auto;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/scss/_general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ select {
pointer-events: none !important;
}

.ez-is-tree-resizing {
.ibexa-is-tree-resizing {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'content-tree/list.item';
@import 'content-tree/list';
@import 'content-tree/header';
@import 'content-tree/popup.actions';
@import 'content-tree/main';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@import 'universal-discovery/breadcrumbs';
@import 'universal-discovery/search';
@import 'universal-discovery/content.table.item';
@import 'universal-discovery/toggle.selection.button';
@import 'universal-discovery/filters';
@import 'universal-discovery/bookmarks.list';
@import 'universal-discovery/translation.selector';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.c-header {
display: flex;
align-items: center;
margin-bottom: calculateRem(8px);
padding: 0 calculateRem(4px) calculateRem(8px);
border-bottom: calculateRem(1px) solid $ibexa-color-light-500;

&__expand-btn {
display: flex;
align-items: center;
justify-content: center;
margin-left: calculateRem(-4px);
padding: 0 0 0 calculateRem(8px);
width: calculateRem(65px);
height: calculateRem(65px);

.ibexa-icon + .ibexa-icon {
margin-right: calculateRem(2px);
}
}

&__name {
display: flex;
align-items: center;
font-size: $ibexa-text-font-size-large;
font-weight: bold;
line-height: calculateRem(33px);
width: 100%;
padding-left: calculateRem(16px);

.ibexa-icon {
margin-right: calculateRem(8px);
}
}

&__options {
display: flex;
justify-content: flex-end;
width: calculateRem(80px);
}
}
Loading