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-3523: Introduced tabs to left sidebar in Content Edit interface #526

Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class AdminUiForms extends AbstractParser
{
public const FORM_TEMPLATES_PARAM = 'admin_ui_forms.content_edit_form_templates';
public const FIELDTYPES_PARAM = 'admin_ui_forms.content_edit.fieldtypes';
webhdx marked this conversation as resolved.
Show resolved Hide resolved

/**
* Adds semantic configuration definition.
Expand All @@ -39,13 +40,47 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder)
$nodeBuilder
->arrayNode('admin_ui_forms')
->info('Admin UI forms configuration settings')
->beforeNormalization()
->always(static function (array $array): array {
// handle deprecated config
if (isset($array['content_edit_form_templates'])) {
$array['content_edit']['form_templates'] = $array['content_edit_form_templates'];
unset($array['content_edit_form_templates']);
}

return $array;
})
->end()
->children()
->arrayNode('content_edit_form_templates')
->info('A list of Content Edit (and create) default Twig form templates')
->arrayPrototype()
->children()
->scalarNode('template')->end()
->integerNode('priority')->end()
->arrayNode('content_edit')
->info('Content Edit form configuration')
->children()
->arrayNode('form_templates')
->info('A list of Content Edit (and create) default Twig form templates')
->setDeprecated(
'ibexa/admin-ui',
'4.2.0',
'Setting "admin_ui.content_edit_form_templates" is deprecated. Use "admin_ui.content_edit.form_templates" instead.'
)
->arrayPrototype()
->children()
->scalarNode('template')->end()
->integerNode('priority')->end()
->end()
->end()
->end()
->arrayNode('fieldtypes')
->info('Configuration for specific FieldTypes')
->useAttributeAsKey('identifier')
->arrayPrototype()
->children()
->scalarNode('identifier')->end()
->booleanNode('meta')
->info('Make this fieldtype a part of Meta group')
->defaultFalse()
->end()
->end()
->end()
->end()
->end()
->end()
Expand All @@ -61,18 +96,28 @@ public function mapConfig(
$currentScope,
ContextualizerInterface $contextualizer
): void {
if (!empty($scopeSettings['admin_ui_forms']['content_edit_form_templates'])) {
if (!empty($scopeSettings['admin_ui_forms']['content_edit']['form_templates'])) {
$scopeSettings['admin_ui_forms.content_edit_form_templates'] = $this->processContentEditFormTemplates(
$scopeSettings['admin_ui_forms']['content_edit_form_templates']
$scopeSettings['admin_ui_forms']['content_edit']['form_templates']
);
unset($scopeSettings['admin_ui_forms']['content_edit_form_templates']);
unset($scopeSettings['admin_ui_forms']['content_edit']['form_templates']);
}

if (!empty($scopeSettings['admin_ui_forms']['content_edit']['fieldtypes'])) {
$scopeSettings['admin_ui_forms.content_edit.fieldtypes'] = $scopeSettings['admin_ui_forms']['content_edit']['fieldtypes'];
unset($scopeSettings['admin_ui_forms']['content_edit']['fieldtypes']);
}

$contextualizer->setContextualParameter(
static::FORM_TEMPLATES_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_edit_form_templates'] ?? []
);
$contextualizer->setContextualParameter(
static::FIELDTYPES_PARAM,
$currentScope,
$scopeSettings['admin_ui_forms.content_edit.fieldtypes'] ?? []
);
}

/**
Expand All @@ -81,6 +126,7 @@ public function mapConfig(
public function postMap(array $config, ContextualizerInterface $contextualizer)
{
$contextualizer->mapConfigArray('admin_ui_forms.content_edit_form_templates', $config);
$contextualizer->mapConfigArray('admin_ui_forms.content_edit.fieldtypes', $config);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/bundle/Resources/config/admin_ui_forms.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
system:
admin_group:
admin_ui_forms:
content_edit_form_templates:
- { template: '@ibexadesign/content/form_fields.html.twig', priority: 0 }
content_edit:
form_templates:
- { template: '@ibexadesign/content/form_fields.html.twig', priority: 0 }

field_templates:
- { template: '@ibexadesign/ui/field_type/preview/content_fields.html.twig', priority: 20 }
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ services:
Ibexa\AdminUi\Component\Content\PreviewUnavailableTwigComponent:
tags:
- { name: ibexa.admin_ui.component, group: 'content-edit-form-before' }

Ibexa\AdminUi\Component\Content\ContentEditMetaFieldsComponent:
tags:
- { name: ibexa.admin_ui.component, group: 'content-edit-sections' }
12 changes: 9 additions & 3 deletions src/bundle/Resources/config/services/events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
arguments:
- '%ibexa.site_access.groups%'
tags:
- {name: kernel.event_subscriber}
- { name: kernel.event_subscriber }

Ibexa\AdminUi\EventListener\AdminExceptionListener:
arguments:
Expand All @@ -41,7 +41,7 @@ services:

Ibexa\AdminUi\EventListener\MenuPermissionsListener:
tags:
- {name: kernel.event_subscriber, priority: -250}
- { name: kernel.event_subscriber, priority: -250 }

Ibexa\AdminUi\EventListener\ViewTemplatesListener:
tags:
Expand All @@ -51,4 +51,10 @@ services:
arguments:
$siteAccessGroups: '%ibexa.site_access.groups%'
tags:
- {name: kernel.event_subscriber}
- { name: kernel.event_subscriber }

Ibexa\AdminUi\EventListener\SetViewParametersListener:
arguments:
$groupedContentFormFieldsProvider: '@Ibexa\AdminUi\Form\Provider\GroupedNonMetaFormFieldsProvider'
tags:
- { name: kernel.event_subscriber }
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/forms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,7 @@ services:
Ibexa\AdminUi\Form\Type\ContentType\FieldDefinitionsCollectionType:
tags:
- { name: form.type }

Ibexa\AdminUi\Form\Provider\GroupedNonMetaFormFieldsProvider:
arguments:
$innerGroupedContentFormFieldsProvider: '@Ibexa\Contracts\ContentForms\Content\Form\Provider\GroupedContentFormFieldsProviderInterface'
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ services:
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content_edit.sidebar_right }

Ibexa\AdminUi\Menu\ContentEditAnchorMenuBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ibexa.admin_ui.menu.content_edit.anchor_menu }

Ibexa\AdminUi\Menu\ContentCreateRightSidebarBuilder:
public: true
tags:
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/autogenerate.identifier.js'),
path.resolve(__dirname, '../public/js/scripts/admin.back.to.top.js'),
path.resolve(__dirname, '../public/js/scripts/admin.middle.ellipsis.js'),
path.resolve(__dirname, '../public/js/scripts/admin.anchor.sections.navigation'),
];
const fieldTypes = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
(function (global, doc) {
if (doc.querySelector('.ibexa-navigation-menu')) {
return;
}

const EDIT_CONTENT_TOP_PADDING = 42;
const formContainerNode = doc.querySelector('.ibexa-edit-content');
const allSections = [...doc.querySelectorAll('.ibexa-anchor-navigation-sections__section')];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
(function (global, doc) {
if (!doc.querySelector('.ibexa-navigation-menu')) {
return;
}

const SECTION_ADJUST_MARGIN_TOP = 20;
const formContainerNode = doc.querySelector('.ibexa-edit-content');
const getSecondarySectionActiveItems = () => {
const secondarySectionItems = formContainerNode.querySelectorAll(
'.ibexa-edit-content__primary-section--active .ibexa-edit-content__secondary-section',
);

return [...secondarySectionItems];
};
let currentlyVisibleSections = getSecondarySectionActiveItems();
const fitSecondarySections = () => {
const primarySection = doc.querySelector('.ibexa-edit-content__primary-section--active');
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes you are using formContainerNode and sometimes not, is there any reason behind it?

const contentColumn = doc.querySelector('.ibexa-main-container__content-column');
const firstSection = primarySection.querySelector('.ibexa-edit-content__secondary-section:first-child');
const lastSection = primarySection.querySelector('.ibexa-edit-content__secondary-section:last-child');
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be confusing because :first-child and :last-child "ignore" the class. This will return null in case .ibexa-edit-content__secondary-section is not first/last element, but it is assumed below that firstSection will never be null, so:

Suggested change
const firstSection = primarySection.querySelector('.ibexa-edit-content__secondary-section:first-child');
const lastSection = primarySection.querySelector('.ibexa-edit-content__secondary-section:last-child');
const firstSection = primarySection.firstElementChild;
const lastSection = primarySection.lastElementChild;

const contentContainer = contentColumn.querySelector('.ibexa-edit-content__container');

contentContainer.style.paddingBottom = '0px';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to set it even for a case in which we are setting it below again?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's kinda of a reset, notice that we set this style after two ifs, in all other cases it should be set to 0


if (!firstSection.isSameNode(lastSection) && lastSection && lastSection.offsetHeight) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that lastSection will never be null, given firstSection is not null.

Suggested change
if (!firstSection.isSameNode(lastSection) && lastSection && lastSection.offsetHeight) {
if (!firstSection.isSameNode(lastSection) && lastSection.offsetHeight) {

const headerContainer = doc.querySelector('.ibexa-edit-header .ibexa-edit-header__container');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this parent in selector? .ibexa-edit-header

const heightFromLastSection = contentContainer.offsetHeight - lastSection.offsetTop;
const contentColumnBodyHeight = contentColumn.offsetHeight - headerContainer.offsetHeight;
const heightDiff = contentColumnBodyHeight - heightFromLastSection;

if (heightDiff > 0) {
contentContainer.style.paddingBottom = `${heightDiff}px`;
}
}
};
const navigateTo = (targetId) => {
const secondarySectionNode = formContainerNode.querySelector(`.ibexa-edit-content__secondary-section[data-id="${targetId}"]`);

formContainerNode.scrollTo({
top: secondarySectionNode.offsetTop,
behavior: 'smooth',
});
};
const setActiveSecondaryMenu = (node) => {
const secondaryMenuItems = doc.querySelectorAll(
'.ibexa-navigation-menu__secondary--active .ibexa-navigation-menu__secondary-item-btn',
);

secondaryMenuItems.forEach((item) => {
item.classList.toggle('ibexa-navigation-menu__secondary-item-btn--active', item.isSameNode(node));
});
};
const showPrimarySection = (id) => {
const primarySectionItems = formContainerNode.querySelectorAll('.ibexa-edit-content__primary-section');

primarySectionItems.forEach((item) => {
item.classList.toggle('ibexa-edit-content__primary-section--active', item.dataset.id === id);
});

currentlyVisibleSections = getSecondarySectionActiveItems();

fitSecondarySections();
};
const showSecondaryMenu = (node) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have such a function also for the primary menu.

const items = doc.querySelectorAll('.ibexa-navigation-menu__secondary');

items.forEach((item) => item.classList.toggle('ibexa-navigation-menu__secondary--active', item.isSameNode(node)));
};
const onSelectPrimaryMenuList = (event) => {
const { targetId } = event.target.dataset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { targetId } = event.target.dataset;
const { targetId } = event.currentTarget.dataset;

const secondaryMenuNode = doc.querySelector(`.ibexa-navigation-menu__secondary[data-id="${targetId}"]`);
const primaryMenuItems = doc.querySelectorAll('.ibexa-navigation-menu__primary--list .ibexa-navigation-menu__primary-item');

primaryMenuItems.forEach((item) => {
item.classList.toggle('ibexa-navigation-menu__primary-item--active', item.isSameNode(event.target));
});
showPrimarySection(targetId);

if (secondaryMenuNode) {
showSecondaryMenu(secondaryMenuNode);
}
};
const onSelectPrimaryMenuDropdown = (event) => {
const targetId = event.target.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const targetId = event.target.value;
const targetId = event.currentTarget.value;

const secondaryMenuNode = doc.querySelector(`.ibexa-navigation-menu__secondary[data-id="${targetId}"]`);

showPrimarySection(targetId);

if (secondaryMenuNode) {
showSecondaryMenu(secondaryMenuNode);
}
};
const onSelectSecondaryMenu = (event) => {
const { targetId } = event.currentTarget.dataset;

navigateTo(targetId);
};
const bindPrimaryMenuListEvents = () => {
const items = doc.querySelectorAll('.ibexa-navigation-menu__primary--list .ibexa-navigation-menu__primary-item');

items.forEach((item) => item.addEventListener('click', onSelectPrimaryMenuList, false));
};
const bindPrimaryMenuDropdownEvents = () => {
const sourceSelect = doc.querySelector('.ibexa-navigation-menu__primary--dropdown .ibexa-dropdown__source .ibexa-input');

if (!sourceSelect) {
return;
}

sourceSelect.addEventListener('change', onSelectPrimaryMenuDropdown, false);
};
const bindSecondaryMenuEvents = () => {
const items = doc.querySelectorAll('.ibexa-navigation-menu .ibexa-navigation-menu__secondary-item-btn');

items.forEach((item) => item.addEventListener('click', onSelectSecondaryMenu, false));
};
const bindScrollContainerEvents = () => {
const allSections = [...doc.querySelectorAll('.ibexa-edit-content__secondary-section')];
const headerContainer = doc.querySelector('.ibexa-edit-header .ibexa-edit-header__container');
let previousFirstVisibleSection = null;

if (formContainerNode && allSections.length) {
formContainerNode.addEventListener('scroll', () => {
let firstVisibleSection = currentlyVisibleSections.find((section) => {
const { top, height } = section.getBoundingClientRect();

return top + height >= headerContainer.offsetHeight + SECTION_ADJUST_MARGIN_TOP;
});

if (!firstVisibleSection) {
firstVisibleSection = currentlyVisibleSections.at(-1);
}

if (previousFirstVisibleSection === firstVisibleSection) {
return;
}

previousFirstVisibleSection = firstVisibleSection;

const targetId = firstVisibleSection.dataset.id;

const secondaryMenuNode = doc.querySelector(
`.ibexa-navigation-menu__secondary--active .ibexa-navigation-menu__secondary-item-btn[data-target-id="${targetId}"]`,
);

setActiveSecondaryMenu(secondaryMenuNode);
});
}
};

bindPrimaryMenuListEvents();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not attach<...> as we have in other places?

bindPrimaryMenuDropdownEvents();
bindSecondaryMenuEvents();
bindScrollContainerEvents();
fitSecondarySections();
})(window, window.document);
18 changes: 0 additions & 18 deletions src/bundle/Resources/public/js/scripts/admin.content.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,6 @@
const isAutosaveEnabled = () => {
return ibexa.adminUiConfig.autosave.enabled && form.querySelector('[name="ezplatform_content_forms_content_edit[autosave]"]');
};
const fitSections = () => {
const lastSection = doc.querySelector('.ibexa-anchor-navigation-sections .ibexa-anchor-navigation-sections__section:last-child');

if (lastSection && lastSection.offsetHeight) {
const contentColumn = doc.querySelector('.ibexa-main-container__content-column');
const contentContainer = contentColumn.querySelector('.ibexa-edit-content__container');
const headerContainer = doc.querySelector('.ibexa-edit-header .ibexa-edit-header__container');
const heightFromLastSection = contentContainer.offsetHeight - lastSection.offsetTop;
const contentColumnBodyHeight = contentColumn.offsetHeight - headerContainer.offsetHeight;
const heightDiff = contentColumnBodyHeight - heightFromLastSection;

if (heightDiff > 0) {
contentContainer.style.paddingBottom = `${heightDiff}px`;
}
}
};

if (isAutosaveEnabled()) {
const AUTOSAVE_SUBMIT_BUTTON_NAME = 'ezplatform_content_forms_content_edit[autosave]';
Expand Down Expand Up @@ -232,8 +216,6 @@
btn.addEventListener('click', clickHandler, false);
});

fitSections();

menuButtonsToValidate.forEach((btn) => {
btn.addEventListener('click', validateHandler, false);
});
Expand Down
8 changes: 8 additions & 0 deletions src/bundle/Resources/public/scss/_content-edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
max-width: calculateRem(1600px);
}
}

&__primary-section {
display: none;

&--active {
display: block;
}
}
}
Loading