2025-08-08 23:23:07 +03:00
|
|
|
import { ComponentChildren } from "preact";
|
2025-08-10 17:19:39 +03:00
|
|
|
import { memo } from "preact/compat";
|
2025-08-09 10:12:26 +03:00
|
|
|
import AbstractBulkAction from "./abstract_bulk_action";
|
2025-08-27 17:53:27 +03:00
|
|
|
import HelpRemoveButtons from "../react/HelpRemoveButtons";
|
2025-08-08 23:23:07 +03:00
|
|
|
|
2025-08-07 20:08:51 +03:00
|
|
|
interface BulkActionProps {
|
2025-10-08 17:44:17 +03:00
|
|
|
label: string | ComponentChildren;
|
2025-08-09 16:47:05 +03:00
|
|
|
children?: ComponentChildren;
|
2025-08-08 23:23:07 +03:00
|
|
|
helpText?: ComponentChildren;
|
2025-08-09 10:12:26 +03:00
|
|
|
bulkAction: AbstractBulkAction;
|
2025-08-07 20:08:51 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-10 17:19:39 +03:00
|
|
|
// Define styles as constants to prevent recreation
|
|
|
|
|
const flexContainerStyle = { display: "flex", alignItems: "center" } as const;
|
|
|
|
|
const labelStyle = { marginRight: "10px" } as const;
|
2025-10-08 17:44:17 +03:00
|
|
|
const textStyle = { marginRight: "10px", marginInlineStart: "10px" } as const;
|
2025-08-10 17:19:39 +03:00
|
|
|
|
|
|
|
|
const BulkAction = memo(({ label, children, helpText, bulkAction }: BulkActionProps) => {
|
2025-08-08 23:23:07 +03:00
|
|
|
return (
|
|
|
|
|
<tr>
|
|
|
|
|
<td colSpan={2}>
|
2025-08-10 17:19:39 +03:00
|
|
|
<div style={flexContainerStyle}>
|
|
|
|
|
<div style={labelStyle} className="text-nowrap">{label}</div>
|
2025-08-08 23:23:07 +03:00
|
|
|
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
2025-08-27 17:53:27 +03:00
|
|
|
<HelpRemoveButtons
|
|
|
|
|
help={helpText}
|
|
|
|
|
removeText="Delete"
|
|
|
|
|
onRemove={() => bulkAction?.deleteAction()}
|
|
|
|
|
/>
|
2025-08-08 23:23:07 +03:00
|
|
|
</tr>
|
|
|
|
|
);
|
2025-08-10 17:19:39 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default BulkAction;
|
2025-08-07 20:08:51 +03:00
|
|
|
|
2025-08-10 17:19:39 +03:00
|
|
|
export const BulkActionText = memo(({ text }: { text: string }) => {
|
2025-08-08 23:23:07 +03:00
|
|
|
return (
|
|
|
|
|
<div
|
2025-08-10 17:19:39 +03:00
|
|
|
style={textStyle}
|
2025-08-08 23:23:07 +03:00
|
|
|
className="text-nowrap">
|
|
|
|
|
{text}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-10-08 17:44:17 +03:00
|
|
|
});
|