Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions ts/WoltLabSuite/Core/Component/Interaction/InteractionEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Represents an effect that is to be applied after an interaction has been executed.
*
* @author Marcel Werk
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/

export enum InteractionEffect {
ReloadItem = "ReloadItem",
ReloadList = "ReloadList",
RemoveItem = "RemoveItem",
}
19 changes: 14 additions & 5 deletions ts/WoltLabSuite/Core/Component/Interaction/LegacyDboAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import { dboAction } from "WoltLabSuite/Core/Ajax";
import { ConfirmationType, handleConfirmation } from "./Confirmation";
import { showDefaultSuccessSnackbar, showSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
import { getPhrase } from "WoltLabSuite/Core/Language";
import { InteractionEffect } from "./InteractionEffect";

async function handleDboAction(
container: HTMLElement,
element: HTMLElement,
objectName: string,
className: string,
actionName: string,
confirmationType: ConfirmationType,
customConfirmationMessage: string = "",
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
): Promise<void> {
const confirmationResult = await handleConfirmation(objectName, confirmationType, customConfirmationMessage);
if (!confirmationResult.result) {
Expand All @@ -31,21 +34,25 @@ async function handleDboAction(
.payload(confirmationResult.reason ? { reason: confirmationResult.reason } : {})
.dispatch();

if (confirmationType == ConfirmationType.Delete) {
if (interactionEffect === InteractionEffect.ReloadItem) {
Comment thread
BurntimeX marked this conversation as resolved.
element.dispatchEvent(
new CustomEvent("interaction:remove", {
new CustomEvent("interaction:invalidate", {
bubbles: true,
}),
);

showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
} else if (interactionEffect === InteractionEffect.ReloadList) {
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
} else {
element.dispatchEvent(
new CustomEvent("interaction:invalidate", {
new CustomEvent("interaction:remove", {
bubbles: true,
}),
);
}

if (confirmationType == ConfirmationType.Delete) {
showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
} else {
showDefaultSuccessSnackbar();
}
}
Expand All @@ -54,12 +61,14 @@ export function setup(identifier: string, container: HTMLElement): void {
container.addEventListener("interaction:execute", (event: CustomEvent) => {
if (event.detail.interaction === identifier) {
void handleDboAction(
container,
event.target as HTMLElement,
event.detail.objectName,
event.detail.className,
event.detail.actionName,
event.detail.confirmationType,
event.detail.confirmationMessage,
event.detail.interactionEffect,
);
}
});
Expand Down
27 changes: 14 additions & 13 deletions ts/WoltLabSuite/Core/Component/Interaction/Rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { postObject } from "WoltLabSuite/Core/Api/PostObject";
import { ConfirmationType, handleConfirmation } from "./Confirmation";
import { showDefaultSuccessSnackbar, showSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
import { getPhrase } from "WoltLabSuite/Core/Language";
import { InteractionEffect } from "./InteractionEffect";

async function handleRpcInteraction(
container: HTMLElement,
Expand All @@ -20,7 +21,7 @@ async function handleRpcInteraction(
endpoint: string,
confirmationType: ConfirmationType,
customConfirmationMessage: string = "",
invalidatesAllItems = false,
interactionEffect: InteractionEffect = InteractionEffect.ReloadItem,
): Promise<void> {
const confirmationResult = await handleConfirmation(objectName, confirmationType, customConfirmationMessage);
if (!confirmationResult.result) {
Expand All @@ -42,25 +43,25 @@ async function handleRpcInteraction(
}
}

if (confirmationType === ConfirmationType.Delete) {
if (interactionEffect === InteractionEffect.ReloadItem) {
Comment thread
BurntimeX marked this conversation as resolved.
element.dispatchEvent(
new CustomEvent("interaction:invalidate", {
bubbles: true,
}),
);
} else if (interactionEffect === InteractionEffect.ReloadList) {
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
} else {
element.dispatchEvent(
new CustomEvent("interaction:remove", {
bubbles: true,
}),
);
}

if (confirmationType === ConfirmationType.Delete) {
showSuccessSnackbar(getPhrase("wcf.global.success.delete"));
} else {
if (invalidatesAllItems) {
container.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
} else {
element.dispatchEvent(
new CustomEvent("interaction:invalidate", {
bubbles: true,
}),
);
}

showDefaultSuccessSnackbar();
}
}
Expand All @@ -75,7 +76,7 @@ export function setup(identifier: string, container: HTMLElement): void {
event.detail.endpoint,
event.detail.confirmationType,
event.detail.confirmationMessage,
event.detail.invalidatesAllItems === "true",
event.detail.interactionEffect,
);
}
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function __construct(
'wcf.global.button.delete',
InteractionConfirmationType::Delete,
'',
$isAvailableCallback
$isAvailableCallback,
InteractionEffect::RemoveItem
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace wcf\system\interaction;

/**
* Represents an effect that is to be applied after an interaction has been executed.
*
* @author Marcel Werk
* @copyright 2001-2025 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
enum InteractionEffect
{
case ReloadItem;
case ReloadList;
case RemoveItem;

public function toString(): string
{
return match ($this) {
self::ReloadItem => 'ReloadItem',
self::ReloadList => 'ReloadList',
self::RemoveItem => 'RemoveItem',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
protected readonly string|\Closure $languageItem,
protected readonly InteractionConfirmationType $confirmationType = InteractionConfirmationType::None,
protected readonly string|\Closure $confirmationMessage = '',
?\Closure $isAvailableCallback = null
?\Closure $isAvailableCallback = null,
protected readonly InteractionEffect $interactionEffect = InteractionEffect::ReloadItem,
) {
parent::__construct($identifier, $isAvailableCallback);
}
Expand Down Expand Up @@ -67,6 +68,7 @@ public function render(DatabaseObject $object): string
data-action-name="{$actionName}"
data-confirmation-type="{$this->confirmationType->toString()}"
data-confirmation-message="{$confirmationMessage}"
data-interaction-effect="{$this->interactionEffect->toString()}"
>
{$label}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
protected readonly InteractionConfirmationType $confirmationType = InteractionConfirmationType::None,
protected readonly string|\Closure $confirmationMessage = '',
?\Closure $isAvailableCallback = null,
protected readonly bool $invalidatesAllItems = false,
protected readonly InteractionEffect $interactionEffect = InteractionEffect::ReloadItem,
) {
parent::__construct($identifier, $isAvailableCallback);
}
Expand Down Expand Up @@ -68,8 +68,6 @@ public function render(DatabaseObject $object): string
}
}

$invalidatesAllItems = $this->invalidatesAllItems ? 'true' : 'false';

return <<<HTML
<button
type="button"
Expand All @@ -78,7 +76,7 @@ public function render(DatabaseObject $object): string
data-endpoint="{$endpoint}"
data-confirmation-type="{$this->confirmationType->toString()}"
data-confirmation-message="{$confirmationMessage}"
data-invalidates-all-items="{$invalidatesAllItems}"
data-interaction-effect="{$this->interactionEffect->toString()}"
>
{$label}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use wcf\system\event\EventHandler;
use wcf\system\interaction\AbstractInteractionProvider;
use wcf\system\interaction\DeleteInteraction;
use wcf\system\interaction\InteractionEffect;
use wcf\system\interaction\LinkInteraction;
use wcf\system\interaction\RpcInteraction;

Expand All @@ -30,7 +31,7 @@ public function __construct()
"core/languages/%s/default",
"wcf.acp.language.setAsDefault",
isAvailableCallback: static fn(Language $language) => !$language->isDefault,
invalidatesAllItems: true
interactionEffect: InteractionEffect::ReloadList
),
new DeleteInteraction(
"core/languages/%s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use wcf\system\interaction\AbstractInteractionProvider;
use wcf\system\interaction\DeleteInteraction;
use wcf\system\interaction\InteractionConfirmationType;
use wcf\system\interaction\InteractionEffect;
use wcf\system\interaction\LinkInteraction;
use wcf\system\interaction\RpcInteraction;
use wcf\system\WCF;
Expand All @@ -32,7 +33,7 @@ public function __construct()
'core/styles/%s/set-as-default',
'wcf.acp.style.button.setAsDefault',
isAvailableCallback: static fn(Style $object) => !$object->isDefault,
invalidatesAllItems: true
interactionEffect: InteractionEffect::ReloadList
),
new RpcInteraction(
'copy',
Expand All @@ -43,7 +44,7 @@ public function __construct()
'wcf.acp.style.copyStyle.confirmMessage',
['style' => $object]
),
invalidatesAllItems: true
interactionEffect: InteractionEffect::ReloadList
),
new LinkInteraction('export', StyleExportForm::class, 'wcf.acp.style.exportStyle'),
new RpcInteraction(
Expand Down