mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 10:15:04 +02:00
fix(printer-card): confirm before HA entity toggle on printer card (#1260)
Smart plugs with "Show on Printer Card" enabled appear as a chip in the HA-entities row below the main plug controls. One click cut power to the printer instantly — including mid-print — while the main Off button right next to it already routes through a ConfirmModal. The HA-row chip was added later and skipped the same gating. Branch on entity type: script.* entities keep firing instantly (fire-once triggers, not power switches — confirming each click would be annoying), but switch/light/anything-else entities now open a ConfirmModal first. Reuses the same variant="danger" + running-print warning copy as the existing power-off confirmation when status.state === 'RUNNING'.
This commit is contained in:
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: 'Möchten Sie die Stromversorgung für "{{name}}" wirklich AUSSCHALTEN?',
|
||||
powerOffWarning: 'WARNUNG: "{{name}}" druckt gerade! Möchten Sie die Stromversorgung wirklich AUSSCHALTEN? Dies unterbricht den Druck und kann den Drucker beschädigen.',
|
||||
powerOffButton: 'Ausschalten',
|
||||
haToggleTitle: '"{{name}}" umschalten',
|
||||
haToggleMessage: 'Home-Assistant-Entität {{entity}} umschalten? Das kann die Stromversorgung ausschalten, falls sie gerade an ist.',
|
||||
haToggleWarning: 'WARNUNG: "{{name}}" druckt gerade! Umschalten von {{entity}} kann die Stromversorgung trennen und den Druck abbrechen. Fortfahren?',
|
||||
haToggleButton: 'Umschalten',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: 'Are you sure you want to turn OFF the power for "{{name}}"?',
|
||||
powerOffWarning: 'WARNING: "{{name}}" is currently printing! Are you sure you want to turn OFF the power? This will interrupt the print and may damage the printer.',
|
||||
powerOffButton: 'Power Off',
|
||||
haToggleTitle: 'Toggle "{{name}}"',
|
||||
haToggleMessage: 'Toggle the Home Assistant entity {{entity}}? This may turn power off if it is currently on.',
|
||||
haToggleWarning: 'WARNING: "{{name}}" is currently printing! Toggling {{entity}} may cut power and interrupt the print. Continue?',
|
||||
haToggleButton: 'Toggle',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: 'Éteindre "{{name}}" ?',
|
||||
powerOffWarning: 'ATTENTION : "{{name}}" imprime ! L\'éteindre maintenant peut endommager l\'imprimante.',
|
||||
powerOffButton: 'Éteindre',
|
||||
haToggleTitle: 'Basculer "{{name}}"',
|
||||
haToggleMessage: 'Basculer l\'entité Home Assistant {{entity}} ? Cela peut couper l\'alimentation si elle est actuellement activée.',
|
||||
haToggleWarning: 'ATTENTION : "{{name}}" imprime ! Basculer {{entity}} peut couper l\'alimentation et interrompre l\'impression. Continuer ?',
|
||||
haToggleButton: 'Basculer',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: 'Sei sicuro di spegnere "{{name}}"?',
|
||||
powerOffWarning: 'AVVISO: "{{name}}" sta stampando! Sei sicuro di spegnere? Questo interromperà la stampa e potrebbe danneggiare la stampante.',
|
||||
powerOffButton: 'Spegni',
|
||||
haToggleTitle: 'Commuta "{{name}}"',
|
||||
haToggleMessage: 'Commutare l\'entità Home Assistant {{entity}}? Questo potrebbe spegnere l\'alimentazione se attualmente è accesa.',
|
||||
haToggleWarning: 'AVVISO: "{{name}}" sta stampando! La commutazione di {{entity}} potrebbe togliere l\'alimentazione e interrompere la stampa. Continuare?',
|
||||
haToggleButton: 'Commuta',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -428,6 +428,10 @@ export default {
|
||||
powerOffMessage: '「{{name}}」の電源をオフにしますか?',
|
||||
powerOffWarning: '警告: 「{{name}}」は現在印刷中です!電源をオフにしますか?印刷が中断され、プリンターが損傷する可能性があります。',
|
||||
powerOffButton: '電源オフ',
|
||||
haToggleTitle: '「{{name}}」を切り替え',
|
||||
haToggleMessage: 'Home Assistant エンティティ {{entity}} を切り替えますか?現在オンの場合、電源がオフになる可能性があります。',
|
||||
haToggleWarning: '警告: 「{{name}}」は現在印刷中です!{{entity}} を切り替えると電源が切れ、印刷が中断される可能性があります。続行しますか?',
|
||||
haToggleButton: '切り替え',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: 'Tem certeza de que deseja desligar a impressora "{{name}}"?',
|
||||
powerOffWarning: 'AVISO: "{{name}}" está imprimindo no momento! Tem certeza de que deseja desligar a impressora? Isso interromperá a impressão e pode danificar a impressora.',
|
||||
powerOffButton: 'Desligar',
|
||||
haToggleTitle: 'Alternar "{{name}}"',
|
||||
haToggleMessage: 'Alternar a entidade Home Assistant {{entity}}? Isso pode desligar a energia se estiver ligada no momento.',
|
||||
haToggleWarning: 'AVISO: "{{name}}" está imprimindo no momento! Alternar {{entity}} pode cortar a energia e interromper a impressão. Continuar?',
|
||||
haToggleButton: 'Alternar',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: '确定要关闭"{{name}}"的电源吗?',
|
||||
powerOffWarning: '警告:"{{name}}"正在打印中!确定要关闭电源吗?这将中断打印并可能损坏打印机。',
|
||||
powerOffButton: '关机',
|
||||
haToggleTitle: '切换"{{name}}"',
|
||||
haToggleMessage: '切换 Home Assistant 实体 {{entity}}?如果当前为开启状态,可能会关闭电源。',
|
||||
haToggleWarning: '警告:"{{name}}"正在打印中!切换 {{entity}} 可能会切断电源并中断打印。是否继续?',
|
||||
haToggleButton: '切换',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -429,6 +429,10 @@ export default {
|
||||
powerOffMessage: '確定要關閉"{{name}}"的電源嗎?',
|
||||
powerOffWarning: '警告:"{{name}}"正在列印中!確定要關閉電源嗎?這將中斷列印並可能損壞印表機。',
|
||||
powerOffButton: '關機',
|
||||
haToggleTitle: '切換"{{name}}"',
|
||||
haToggleMessage: '切換 Home Assistant 實體 {{entity}}?如果目前為開啟狀態,可能會關閉電源。',
|
||||
haToggleWarning: '警告:"{{name}}"正在列印中!切換 {{entity}} 可能會切斷電源並中斷列印。是否繼續?',
|
||||
haToggleButton: '切換',
|
||||
},
|
||||
// Bulk actions
|
||||
bulk: {
|
||||
|
||||
@@ -65,7 +65,7 @@ import {
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { api, discoveryApi, firmwareApi, withStreamToken } from '../api/client';
|
||||
import { formatDateOnly, formatETA, formatDuration, parseUTCDate } from '../utils/date';
|
||||
import type { Printer, PrinterCreate, PrinterStatus, AMSUnit, DiscoveredPrinter, FirmwareUpdateInfo, FirmwareUploadStatus, LinkedSpoolInfo, SpoolAssignment, HMSError, InventorySpool } from '../api/client';
|
||||
import type { Printer, PrinterCreate, PrinterStatus, AMSUnit, DiscoveredPrinter, FirmwareUpdateInfo, FirmwareUploadStatus, LinkedSpoolInfo, SpoolAssignment, HMSError, InventorySpool, SmartPlug } from '../api/client';
|
||||
import { Card, CardContent } from '../components/Card';
|
||||
import { Button } from '../components/Button';
|
||||
import { ConfirmModal } from '../components/ConfirmModal';
|
||||
@@ -1470,6 +1470,7 @@ function PrinterCard({
|
||||
const [showMQTTDebug, setShowMQTTDebug] = useState(false);
|
||||
const [showPowerOnConfirm, setShowPowerOnConfirm] = useState(false);
|
||||
const [showPowerOffConfirm, setShowPowerOffConfirm] = useState(false);
|
||||
const [haToggleConfirm, setHaToggleConfirm] = useState<SmartPlug | null>(null);
|
||||
const [showHMSModal, setShowHMSModal] = useState(false);
|
||||
const [showStopConfirm, setShowStopConfirm] = useState(false);
|
||||
const [showPauseConfirm, setShowPauseConfirm] = useState(false);
|
||||
@@ -4645,7 +4646,13 @@ function PrinterCard({
|
||||
return (
|
||||
<button
|
||||
key={script.id}
|
||||
onClick={() => runScriptMutation.mutate({ id: script.id, action: isScript ? 'on' : 'toggle' })}
|
||||
onClick={() => {
|
||||
if (isScript) {
|
||||
runScriptMutation.mutate({ id: script.id, action: 'on' });
|
||||
} else {
|
||||
setHaToggleConfirm(script);
|
||||
}
|
||||
}}
|
||||
disabled={runScriptMutation.isPending}
|
||||
title={`${isScript ? 'Run' : 'Toggle'} ${script.ha_entity_id}`}
|
||||
className="px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1"
|
||||
@@ -5127,6 +5134,25 @@ function PrinterCard({
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* HA entity toggle confirmation (Show on Printer Card switches) */}
|
||||
{haToggleConfirm && (
|
||||
<ConfirmModal
|
||||
title={t('printers.confirm.haToggleTitle', { name: haToggleConfirm.name })}
|
||||
message={
|
||||
status?.state === 'RUNNING'
|
||||
? t('printers.confirm.haToggleWarning', { name: printer.name, entity: haToggleConfirm.ha_entity_id || haToggleConfirm.name })
|
||||
: t('printers.confirm.haToggleMessage', { entity: haToggleConfirm.ha_entity_id || haToggleConfirm.name })
|
||||
}
|
||||
confirmText={t('printers.confirm.haToggleButton')}
|
||||
variant={status?.state === 'RUNNING' ? 'danger' : 'default'}
|
||||
onConfirm={() => {
|
||||
runScriptMutation.mutate({ id: haToggleConfirm.id, action: 'toggle' });
|
||||
setHaToggleConfirm(null);
|
||||
}}
|
||||
onCancel={() => setHaToggleConfirm(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Stop Print Confirmation */}
|
||||
{showStopConfirm && (
|
||||
<ConfirmModal
|
||||
|
||||
Reference in New Issue
Block a user