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

Add sidebar panel to element edit pages #690

Merged
merged 14 commits into from
Aug 4, 2024
Merged

Conversation

bencroker
Copy link
Collaborator

@bencroker bencroker commented Jul 31, 2024

This PR adds a sidebar panel to element edit pages for elements that have URLs, showing the current cache status of the page (cached/expired/uncached). If the status is cached or expired then a Refresh button appears next to it that refreshes the cached page in the background.

screenshot-puf5LICd@2x

Displaying the cache date is only possible if the ”Cached by” comment has been enabled, therefore I’m opting against including it in the sidebar panel.

A new user permission determines which users can view the sidebar panel.

screenshot-eCKxHtLR@2x

@bencroker bencroker changed the title Add sidebar panel to entries Add sidebar panel to element edit pages Jul 31, 2024
@justenh
Copy link

justenh commented Jul 31, 2024

@bencroker Thank you for putting this PR up! Would it be possible to have the widget display timestamp information from the connected cache file? This is the crux of most of our customer issues. We field a lot of questions about why a particular page didn't refresh properly, and it would be helpful to see, at a glance, the date the cache file was created/updated.

@bencroker
Copy link
Collaborator Author

bencroker commented Jul 31, 2024

@justenh See my note above.

Displaying the cache date is only possible if the ”Cached by” comment has been enabled, therefore I’m opting against including it in the sidebar panel.

Relying on the filesystem is not possible either, since cached data can be stored in Redis, the DB, etc. where no timestamp exists.

@bencroker
Copy link
Collaborator Author

It might be possible to add a timestamp column to the database for easier tracking of this here and in the Blitz diagnostics utility, I’ll look into it.

@justenh
Copy link

justenh commented Jul 31, 2024

@bencroker Appreciate you looking into that. It would be a really big help for our customer support process.

@bencroker
Copy link
Collaborator Author

bencroker commented Jul 31, 2024

Added a dateCached column to the cache record so we can now display this info in the sidebar panel and the Blitz diagnostics utility.

screenshot-uehzuojI@2x

@russback
Copy link

@bencroker thanks for this. Is this based on the DB record or the actual file returned by an HTTP request?

@russback
Copy link

@bencroker just adding here from email conversation, it would be great to be able to see an indication of why a page is not cached too (e.g. because of an exclusion rule) and also the cache strategy (i.e. purge on save, expire on save).

@bencroker
Copy link
Collaborator Author

bencroker commented Jul 31, 2024

@bencroker thanks for this. Is this based on the DB record or the actual file returned by an HTTP request?

This is based on the DB record, which provided a cached value exists, should be an accurate indication of when the page was last cached.

@bencroker just adding here from email conversation, it would be great to be able to see an indication of why a page is not cached too (e.g. because of an exclusion rule) and also the cache strategy (i.e. purge on save, expire on save).

Honestly, that feels too developer centric to be shown to content authors (which is what the sidebar panel is aimed at). The diagnostics utility feels more appropriate for finding implementation details.

@justenh
Copy link

justenh commented Jul 31, 2024

@bencroker The addition of the "Cached At" and "Expires At" fields are perfect for our needs. I agree that the refresh strategy wouldn't be too helpful considering it's set site-wide and not specific to a particular element. We rarely leverage the exclusion rules, but I could see where that would be helpful.

@russback
Copy link

Thanks again @bencroker.

I would suggest that the diagnostics utility is the developer-centric area and not one we would direct editors to, and instead having an indication of what will happen when you save an entry - in situ - is very much in the interests of the editor rather than the developer.

The most common issue we're finding is that there is confusion over why entry changes aren't displaying, so clearly showing this info (regardless of whether that's down to developer config or not) is something we think will help.

But we can always add our own sidebar or UI element to add our own flavour if this isn't the general view.

@bencroker
Copy link
Collaborator Author

having an indication of what will happen when you save an entry - in situ - is very much in the interests of the editor rather than the developer.

Agreed, but I don’t think editors should be expected to understand Blitz settings and I’m not sure how this could be displayed in layperson terms.

I’ll be sure to add an event that you can use to easily add to, or overwrite, the contents of the sidebar.

@bencroker
Copy link
Collaborator Author

bencroker commented Aug 1, 2024

@russback You’ll be able to overwrite or add to the sidebar panel markup using the EVENT_DEFINE_META_FIELDS_HTML event as follows.

use craft\events\DefineElementEditorHtmlEvent;
use putyourlightson\blitz\helpers\ElementSidebarHelper;
use yii\base\Event;

Event::on(
    ElementSidebarHelper::class,
    ElementSidebarHelper::EVENT_DEFINE_META_FIELDS_HTML,
    function(DefineElementEditorHtmlEvent $event) {
        $event->html .= '
            <div class="data">
                <div class="heading">
                    Refresh Mode
                </div>
                <div class="value">
                    Explanation here...
                </div>
            </div>';
    }
);
screenshot-uehzuojI@2x

@bencroker
Copy link
Collaborator Author

Added an indication when a page is both uncached and not cacheable due to the Blitz URI pattern settings.

354297009-5d2445f5-a77b-49c8-9df4-db8f87b401fc

@bencroker bencroker merged commit 59ae193 into 4.x Aug 4, 2024
2 checks passed
@bencroker bencroker deleted the feature/sidebar-widget branch August 4, 2024 08:29
@bencroker
Copy link
Collaborator Author

bencroker commented Aug 5, 2024

Released in 4.22.0 and 5.6.0. Thanks for all the input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants