EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Remember last opened tab

Open a-r-m-i-n opened this issue 2 years ago • 3 comments

Currently, every refresh will reset the active tab and jump to the first tab.

It would be much more convinient, if tabs would remember their recent position, also without validation errors occuring.

For this the "Ulid" needs to get replaced. The tab-ID may not change after refresh, to make this possible.

a-r-m-i-n avatar Apr 03 '22 18:04 a-r-m-i-n

@a-r-m-i-n Yes, good feature, I have the same issue ;) Thanks

fdiedler avatar Apr 04 '22 13:04 fdiedler

This is a nice feature, and the related pull request works (but needs adjusting if #5278 lands first).

However this only sets the active tab on page refresh. Additional features might be

  • keep same tab active if switching to detail view (in combination with #5278)
  • remember active tab when navigating away and back (e.g. to the list view and back)

Any ideas about how this could be achieved?

finnef avatar Jun 27 '22 11:06 finnef

Any ideas about how this could be achieved?

TYPO3 CMS does this in its backend. There, the record/entity type and its id is stored in local storage, which remembers the last active tab and restores it.

This would not be that hard to achieve, I guess. And I would also provide the code/PR for this, but first I would like to have some response of @javiereguiluz about my current implementation.

a-r-m-i-n avatar Jun 27 '22 16:06 a-r-m-i-n

With EA 4.8 I now use this custom JS, which I add to tabbed pages using twig detail and form overrides.


const rememberActiveEaTab = {
    init() {
        const anchor = window.location.hash;
        if (anchor) {
            document.querySelector(`a[href="${anchor}"]`).click();
            rememberActiveEaTab.updateButtonHref();
            setTimeout(() => {
                window.scrollTo(0, 0);
            }, 100);
        }
        document.querySelectorAll('.nav-tabs .nav-link').forEach(navLinkTab => {
            navLinkTab.addEventListener('click', function onFormNavLinkTabClick() {
                history.pushState({}, '', navLinkTab.href);
                rememberActiveEaTab.updateButtonHref();
            });
        });

    },
    updateButtonHref() {
        document.querySelectorAll('.page-actions .action-detail.btn, .page-actions .action-edit.btn')
            .forEach(button => {
                const hash = button.href.indexOf('#');
                if (hash > -1) {
                    button.href = button.href.substring(0, hash);
                }
                const anchor = window.location.hash;
                if (anchor) {
                    button.href += anchor;
                }
            });
    },
}

document.addEventListener('DOMContentLoaded', function () {
    rememberActiveEaTab.init();
});```

finnef avatar Nov 27 '23 14:11 finnef

Closing as fixed in version 4.8.7 (https://github.com/EasyCorp/EasyAdminBundle/releases/tag/v4.8.7)

javiereguiluz avatar Jan 26 '24 18:01 javiereguiluz