mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-25 05:02:57 +01:00
Use w-swap's reflect event in w-drilldown and w-link
This commit is contained in:
parent
4fedf3e2d4
commit
88bdd397cf
@ -76,25 +76,6 @@ export class DrilldownController extends Controller<HTMLElement> {
|
||||
});
|
||||
}
|
||||
|
||||
updateParams(e: Event) {
|
||||
const swapEvent = e as CustomEvent<{ requestUrl: string }>;
|
||||
if ((e.target as HTMLElement)?.id === 'listing-results') {
|
||||
const params = new URLSearchParams(
|
||||
swapEvent.detail?.requestUrl.split('?')[1],
|
||||
);
|
||||
const filteredParams = new URLSearchParams();
|
||||
params.forEach((value, key) => {
|
||||
if (value.trim() !== '' && !key.startsWith('_w_')) {
|
||||
// Check if the value is not empty after trimming white space
|
||||
filteredParams.append(key, value);
|
||||
}
|
||||
});
|
||||
const queryString = `?${filteredParams.toString()}`;
|
||||
window.history.replaceState(null, '', queryString);
|
||||
}
|
||||
this.updateCount();
|
||||
}
|
||||
|
||||
open(e: MouseEvent) {
|
||||
const toggle = (e.target as HTMLElement)?.closest(
|
||||
'button',
|
||||
|
@ -19,7 +19,7 @@ export class LinkController extends Controller<HTMLElement> {
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.setParamsFromLocation();
|
||||
this.setParams();
|
||||
}
|
||||
|
||||
get reflectAll() {
|
||||
@ -33,11 +33,13 @@ export class LinkController extends Controller<HTMLElement> {
|
||||
|
||||
const sourceParams = url.searchParams;
|
||||
sourceParams.forEach((value, key) => {
|
||||
// Skip the key if
|
||||
if (
|
||||
key.startsWith('_w_') || // Wagtail internal
|
||||
// Delete the key if we want to preserve it from the current URL, or
|
||||
// if we don't want to reflect it to the new URL
|
||||
// it's a Wagtail internal param, or
|
||||
key.startsWith('_w_') ||
|
||||
// we want to preserve it from the current URL, or
|
||||
this.preserveKeysValue.includes(key) ||
|
||||
// we don't want to reflect it to the new URL
|
||||
(!reflectAll && !this.reflectKeysValue.includes(key))
|
||||
) {
|
||||
return;
|
||||
@ -57,12 +59,14 @@ export class LinkController extends Controller<HTMLElement> {
|
||||
this.element.setAttribute(this.attrNameValue, currentUrl.toString());
|
||||
}
|
||||
|
||||
setParamsFromSwapRequest(e: CustomEvent<{ requestUrl?: string }>) {
|
||||
setParams(e?: CustomEvent<{ requestUrl?: string }>) {
|
||||
if (!e) {
|
||||
this.setParamsFromURL(new URL(window.location.href));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e.detail?.requestUrl) return;
|
||||
|
||||
this.setParamsFromURL(new URL(e.detail.requestUrl, window.location.href));
|
||||
}
|
||||
|
||||
setParamsFromLocation() {
|
||||
this.setParamsFromURL(new URL(window.location.href));
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@
|
||||
data-action="change->w-swap#submitLazy input->w-swap#submitLazy"
|
||||
data-w-swap-src-value="{{ search_url }}"
|
||||
data-w-swap-target-value="#listing-results"
|
||||
data-w-swap-reflect-value="true"
|
||||
>
|
||||
{% if search_form %}
|
||||
{% for field in search_form %}
|
||||
@ -83,7 +84,7 @@
|
||||
id="filters-drilldown"
|
||||
class="w-drilldown"
|
||||
data-controller="w-drilldown"
|
||||
data-action="w-swap:success@document->w-drilldown#updateParams w-dropdown:hide->w-drilldown#delayedClose w-dropdown:clickaway->w-drilldown#preventOutletClickaway"
|
||||
data-action="w-swap:success@document->w-drilldown#updateCount w-dropdown:hide->w-drilldown#delayedClose w-dropdown:clickaway->w-drilldown#preventOutletClickaway"
|
||||
data-w-drilldown-count-attr-value="data-w-active-filter-name"
|
||||
data-w-drilldown-w-action-outlet="[data-w-active-filter-name][data-controller='w-action']"
|
||||
data-w-drilldown-w-dropdown-outlet="#filters-drilldown [data-controller='w-dropdown']"
|
||||
|
@ -111,7 +111,7 @@ class HeaderButton(Button):
|
||||
{
|
||||
"data-controller": "w-tooltip w-link",
|
||||
"data-w-tooltip-content-value": label,
|
||||
"data-action": "w-swap:success@document->w-link#setParamsFromSwapRequest",
|
||||
"data-action": "w-swap:reflect@document->w-link#setParams",
|
||||
"aria-label": label,
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user