Skip to content

Commit a304f26

Browse files
committed
Allow the configuration of the effect that is to be applied after an interaction has been executed
1 parent 63295a1 commit a304f26

12 files changed

Lines changed: 128 additions & 46 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Represents an effect that is to be applied after an interaction has been executed.
3+
*
4+
* @author Marcel Werk
5+
* @copyright 2001-2025 WoltLab GmbH
6+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7+
* @since 6.2
8+
*/
9+
10+
export enum InteractionEffect {
11+
ReloadItem = "ReloadItem",
12+
ReloadList = "ReloadList",
13+
RemoveItem = "RemoveItem",
14+
}

ts/WoltLabSuite/Core/Component/Interaction/LegacyDboAction.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import { dboAction } from "WoltLabSuite/Core/Ajax";
1212
import { ConfirmationType, handleConfirmation } from "./Confirmation";
1313
import { showDefaultSuccessSnackbar, showSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
1414
import { getPhrase } from "WoltLabSuite/Core/Language";
15+
import { InteractionEffect } from "./InteractionEffect";
1516

1617
async function handleDboAction(
18+
container: HTMLElement,
1719
element: HTMLElement,
1820
objectName: string,
1921
className: string,
2022
actionName: string,
2123
confirmationType: ConfirmationType,
2224
customConfirmationMessage: string = "",
25+
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
2326
): Promise<void> {
2427
const confirmationResult = await handleConfirmation(objectName, confirmationType, customConfirmationMessage);
2528
if (!confirmationResult.result) {
@@ -31,21 +34,25 @@ async function handleDboAction(
3134
.payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
3235
.dispatch();
3336

34-
if (confirmationType == ConfirmationType.Delete) {
37+
if (interactionEffect === InteractionEffect.ReloadItem) {
3538
element.dispatchEvent(
36-
new CustomEvent("interaction:remove", {
39+
new CustomEvent("interaction:invalidate", {
3740
bubbles: true,
3841
}),
3942
);
40-
41-
showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
43+
} else if (interactionEffect === InteractionEffect.ReloadList) {
44+
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
4245
} else {
4346
element.dispatchEvent(
44-
new CustomEvent("interaction:invalidate", {
47+
new CustomEvent("interaction:remove", {
4548
bubbles: true,
4649
}),
4750
);
51+
}
4852

53+
if (confirmationType == ConfirmationType.Delete) {
54+
showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
55+
} else {
4956
showDefaultSuccessSnackbar();
5057
}
5158
}
@@ -54,12 +61,14 @@ export function setup(identifier: string, container: HTMLElement): void {
5461
container.addEventListener("interaction:execute", (event: CustomEvent) => {
5562
if (event.detail.interaction === identifier) {
5663
void handleDboAction(
64+
container,
5765
event.target as HTMLElement,
5866
event.detail.objectName,
5967
event.detail.className,
6068
event.detail.actionName,
6169
event.detail.confirmationType,
6270
event.detail.confirmationMessage,
71+
event.detail.interactionEffect,
6372
);
6473
}
6574
});

ts/WoltLabSuite/Core/Component/Interaction/Rpc.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { postObject } from "WoltLabSuite/Core/Api/PostObject";
1212
import { ConfirmationType, handleConfirmation } from "./Confirmation";
1313
import { showDefaultSuccessSnackbar, showSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
1414
import { getPhrase } from "WoltLabSuite/Core/Language";
15+
import { InteractionEffect } from "./InteractionEffect";
1516

1617
async function handleRpcInteraction(
1718
container: HTMLElement,
@@ -20,7 +21,7 @@ async function handleRpcInteraction(
2021
endpoint: string,
2122
confirmationType: ConfirmationType,
2223
customConfirmationMessage: string = "",
23-
invalidatesAllItems = false,
24+
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
2425
): Promise<void> {
2526
const confirmationResult = await handleConfirmation(objectName, confirmationType, customConfirmationMessage);
2627
if (!confirmationResult.result) {
@@ -42,25 +43,25 @@ async function handleRpcInteraction(
4243
}
4344
}
4445

45-
if (confirmationType === ConfirmationType.Delete) {
46+
if (interactionEffect === InteractionEffect.ReloadItem) {
47+
element.dispatchEvent(
48+
new CustomEvent("interaction:invalidate", {
49+
bubbles: true,
50+
}),
51+
);
52+
} else if (interactionEffect === InteractionEffect.ReloadList) {
53+
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
54+
} else {
4655
element.dispatchEvent(
4756
new CustomEvent("interaction:remove", {
4857
bubbles: true,
4958
}),
5059
);
60+
}
5161

62+
if (confirmationType === ConfirmationType.Delete) {
5263
showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
5364
} else {
54-
if (invalidatesAllItems) {
55-
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
56-
} else {
57-
element.dispatchEvent(
58-
new CustomEvent("interaction:invalidate", {
59-
bubbles: true,
60-
}),
61-
);
62-
}
63-
6465
showDefaultSuccessSnackbar();
6566
}
6667
}
@@ -75,7 +76,7 @@ export function setup(identifier: string, container: HTMLElement): void {
7576
event.detail.endpoint,
7677
event.detail.confirmationType,
7778
event.detail.confirmationMessage,
78-
event.detail.invalidatesAllItems === "true",
79+
event.detail.interactionEffect,
7980
);
8081
}
8182
});

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/InteractionEffect.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/LegacyDboAction.js

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Interaction/Rpc.js

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/system/interaction/DeleteInteraction.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function __construct(
2222
'wcf.global.button.delete',
2323
InteractionConfirmationType::Delete,
2424
'',
25-
$isAvailableCallback
25+
$isAvailableCallback,
26+
InteractionEffect::RemoveItem
2627
);
2728
}
2829
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace wcf\system\interaction;
4+
5+
/**
6+
* Represents an effect that is to be applied after an interaction has been executed.
7+
*
8+
* @author Marcel Werk
9+
* @copyright 2001-2025 WoltLab GmbH
10+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11+
* @since 6.2
12+
*/
13+
enum InteractionEffect
14+
{
15+
case ReloadItem;
16+
case ReloadList;
17+
case RemoveItem;
18+
19+
public function toString(): string
20+
{
21+
return match ($this) {
22+
self::ReloadItem => 'ReloadItem',
23+
self::ReloadList => 'ReloadList',
24+
self::RemoveItem => 'RemoveItem',
25+
};
26+
}
27+
}

wcfsetup/install/files/lib/system/interaction/LegacyDboInteraction.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function __construct(
2727
protected readonly string|\Closure $languageItem,
2828
protected readonly InteractionConfirmationType $confirmationType = InteractionConfirmationType::None,
2929
protected readonly string|\Closure $confirmationMessage = '',
30-
?\Closure $isAvailableCallback = null
30+
?\Closure $isAvailableCallback = null,
31+
protected readonly InteractionEffect $interactionEffect = InteractionEffect::ReloadItem,
3132
) {
3233
parent::__construct($identifier, $isAvailableCallback);
3334
}
@@ -67,6 +68,7 @@ public function render(DatabaseObject $object): string
6768
data-action-name="{$actionName}"
6869
data-confirmation-type="{$this->confirmationType->toString()}"
6970
data-confirmation-message="{$confirmationMessage}"
71+
data-interaction-effect="{$this->interactionEffect->toString()}"
7072
>
7173
{$label}
7274
</button>

wcfsetup/install/files/lib/system/interaction/RpcInteraction.class.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
protected readonly InteractionConfirmationType $confirmationType = InteractionConfirmationType::None,
2828
protected readonly string|\Closure $confirmationMessage = '',
2929
?\Closure $isAvailableCallback = null,
30-
protected readonly bool $invalidatesAllItems = false,
30+
protected readonly InteractionEffect $interactionEffect = InteractionEffect::ReloadItem,
3131
) {
3232
parent::__construct($identifier, $isAvailableCallback);
3333
}
@@ -68,8 +68,6 @@ public function render(DatabaseObject $object): string
6868
}
6969
}
7070

71-
$invalidatesAllItems = $this->invalidatesAllItems ? 'true' : 'false';
72-
7371
return <<<HTML
7472
<button
7573
type="button"
@@ -78,7 +76,7 @@ public function render(DatabaseObject $object): string
7876
data-endpoint="{$endpoint}"
7977
data-confirmation-type="{$this->confirmationType->toString()}"
8078
data-confirmation-message="{$confirmationMessage}"
81-
data-invalidates-all-items="{$invalidatesAllItems}"
79+
data-interaction-effect="{$this->interactionEffect->toString()}"
8280
>
8381
{$label}
8482
</button>

0 commit comments

Comments
 (0)