diff --git a/web/src/features/Admin/ProxyHostManagement/Components/ProxyHostsTable/Components/ProxyHostAppExtensionCell.tsx b/web/src/features/Admin/ProxyHostManagement/Components/ProxyHostsTable/Components/ProxyHostAppExtensionCell.tsx index ec623aa13..1083ead6e 100644 --- a/web/src/features/Admin/ProxyHostManagement/Components/ProxyHostsTable/Components/ProxyHostAppExtensionCell.tsx +++ b/web/src/features/Admin/ProxyHostManagement/Components/ProxyHostsTable/Components/ProxyHostAppExtensionCell.tsx @@ -1,19 +1,27 @@ import { useContext } from 'react' import AppHostTableCell from '@/features/AppUi/Components/AppHostTableCell.tsx' +import AppViewErrorBoundary from '@/features/AppUi/Components/AppViewErrorBoundary.tsx' import { AppHostTableContext } from '@/features/AppUi/appHostTableContext.ts' import usePrewarmAppHostAction from '@/features/AppUi/Hooks/usePrewarmAppHostAction.ts' import type { AppHostTableColumn } from '@/features/AppUi/Types/app-host-table.types.ts' import type { ProxyHostSummary } from '@/lib/Admin/ProxyHostManagement/Types/proxy-hosts.types.ts' -/** One host's cell in an app column; it opens the column's row action when the host offers it. */ -export default function ProxyHostAppExtensionCell({ - host, - column, -}: { +interface ProxyHostAppExtensionCellProps { readonly host: ProxyHostSummary readonly column: AppHostTableColumn -}) { +} + +/** One host's cell in an app column; it opens the column's row action when the host offers it. */ +export default function ProxyHostAppExtensionCell(props: ProxyHostAppExtensionCellProps) { + return ( + + + + ) +} + +function ProxyHostAppExtensionCellContent({ host, column }: ProxyHostAppExtensionCellProps) { const table = useContext(AppHostTableContext) const prewarm = usePrewarmAppHostAction() const onAction = table?.onAction diff --git a/web/src/features/AppUi/AppUiFrame.tsx b/web/src/features/AppUi/AppUiFrame.tsx index a8e2a4718..50f67a012 100644 --- a/web/src/features/AppUi/AppUiFrame.tsx +++ b/web/src/features/AppUi/AppUiFrame.tsx @@ -14,6 +14,7 @@ import AppFrameView from './Components/AppFrameView.tsx' import PooledAppFrameView from './Components/PooledAppFrameView.tsx' import type { AppFrameSource as OpenedSource } from './Types/app-frame-view.types.ts' import AppContentSkeleton from './Components/AppContentSkeleton.tsx' +import AppViewErrorBoundary from './Components/AppViewErrorBoundary.tsx' type FrameProps = { app: AppUiSummary @@ -49,9 +50,10 @@ export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill if (!sessionId) return null // Routing updates the open document through the bridge. + const retry = () => setAttempt((previous) => previous + 1) return ( - setAttempt((previous) => previous + 1)} - /> + onRetry={retry} + > + + ) } diff --git a/web/src/features/AppUi/Components/AppDialogCloseConfirmation.tsx b/web/src/features/AppUi/Components/AppDialogCloseConfirmation.tsx new file mode 100644 index 000000000..895ea8c84 --- /dev/null +++ b/web/src/features/AppUi/Components/AppDialogCloseConfirmation.tsx @@ -0,0 +1,31 @@ +import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' +import { ConfirmDialog } from '@/shared/Modal/Components/ConfirmDialog.tsx' + +export default function AppDialogCloseConfirmation({ + open, + blocked, + onOpenChange, + onConfirm, +}: { + readonly open: boolean + readonly blocked: boolean + readonly onOpenChange: (open: boolean) => void + readonly onConfirm: () => void +}) { + const { t } = useTranslationStore() + return ( + + ) +} diff --git a/web/src/features/AppUi/Components/AppDialogSurfaceModal.tsx b/web/src/features/AppUi/Components/AppDialogSurfaceModal.tsx index 81d3ce5b2..d63204305 100644 --- a/web/src/features/AppUi/Components/AppDialogSurfaceModal.tsx +++ b/web/src/features/AppUi/Components/AppDialogSurfaceModal.tsx @@ -1,10 +1,12 @@ import { useMemo, useState, type ReactNode } from 'react' -import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { Modal } from '@/shared/Modal/index.tsx' +import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' import { AppDialogSurfaceContext } from '../appDialogSurfaceContext.ts' +import useAppDialogEscape from '../Hooks/useAppDialogEscape.ts' import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts' +import AppDialogCloseConfirmation from './AppDialogCloseConfirmation.tsx' /** * A platform dialog an app frame is drawn in. An app drawn with the UI kit whose root is a dialog @@ -32,39 +34,65 @@ export default function AppDialogSurfaceModal({ () => ({ setChrome, navigation, footer, close: () => onOpenChange(false) }), [footer, navigation, onOpenChange], ) - // The user closed the dialog: the app's root dialog hears of it before the platform closes it. + const closeDisabled = chrome?.closeDisabled ?? false + const { state, handler } = useAppDialogEscape(open && closeDisabled, surface.close) + // The app's root dialog hears about an ordinary close before the platform closes it. const close = () => { + if (closeDisabled) return chrome?.onClose() - onOpenChange(false) + surface.close() } return ( - { - if (next) onOpenChange(true) - else close() - }} - closeDisabled={chrome?.closeDisabled ?? false} - title={chrome?.heading ?? title} - description={chrome?.description ?? description} - size="xl" - fixedHeight - height="tall" - navigation={chrome?.navigation ?
: undefined} - footer={ - chrome?.footer ? ( -
- ) : ( - - ) - } - > -
- {children} -
- + <> + { + if (next) onOpenChange(true) + else close() + }} + closeDisabled={closeDisabled} + onBlockedEscape={handler.openConfirmation} + title={chrome?.heading ?? title} + description={chrome?.description ?? description} + size="xl" + fixedHeight + height="tall" + navigation={chrome?.navigation ?
: undefined} + footer={ + <> + {chrome?.footer ? ( +
+ ) : ( + + {t('appUi.hostTable.close')} + + )} + {state.showEscape ? ( + + {t('appUi.remote.dialog.closeAnyway')} + + ) : null} + + } + > +
+ {children} +
+ + + ) } diff --git a/web/src/features/AppUi/Components/AppViewErrorBoundary.tsx b/web/src/features/AppUi/Components/AppViewErrorBoundary.tsx new file mode 100644 index 000000000..98e86fb65 --- /dev/null +++ b/web/src/features/AppUi/Components/AppViewErrorBoundary.tsx @@ -0,0 +1,49 @@ +import { Component, type ReactNode } from 'react' + +import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' +import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' + +interface AppViewErrorBoundaryProps { + readonly children: ReactNode + readonly onRetry?: () => void + readonly compact?: boolean +} + +/** Unmounts the failed app view while leaving the host and other app views active. */ +export default class AppViewErrorBoundary extends Component { + override state = { failed: false } + + static getDerivedStateFromError() { + return { failed: true } + } + + override render() { + if (!this.state.failed) return this.props.children + return ( + this.setState({ failed: false }))} + /> + ) + } +} + +function AppViewRecovery({ compact, onRetry }: { compact: boolean; onRetry: () => void }) { + const { t } = useTranslationStore() + return ( +
+ + {t(compact ? 'appUi.hostTable.unavailable' : 'appUi.unavailable')} + + + {t('common.retry')} + +
+ ) +} diff --git a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteDialogElements.tsx b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteDialogElements.tsx index febb54a12..cf5394dee 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteDialogElements.tsx +++ b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteDialogElements.tsx @@ -2,10 +2,14 @@ import { uiKitCatalog } from '@rentnerproxy/app-contracts' import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react' import { createPortal } from 'react-dom' +import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { Modal } from '@/shared/Modal/index.tsx' +import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' import Tabs from '@/shared/Tabs/index.tsx' import { AppDialogSurfaceContext } from '../../../appDialogSurfaceContext.ts' +import useAppDialogEscape from '../../../Hooks/useAppDialogEscape.ts' import type { AppDialogSurface } from '../../../Types/app-dialog-surface.types.ts' +import AppDialogCloseConfirmation from '../../AppDialogCloseConfirmation.tsx' import { useRemoteCloseBlocked } from '../Hooks/useRemoteForm.ts' import useRemoteProperties from '../Hooks/useRemoteProperties.ts' import useRemoteTabsLogic from '../Hooks/useRemoteTabsLogic.ts' @@ -43,18 +47,43 @@ function RemoteDialogBody({ ) } -function RemoteModalDialog({ entry, children, slots, emit }: RemoteElementProps) { - const { heading, description, size, height, open } = useRemoteProperties( - uiKitCatalog['ui-dialog'].properties, - entry, - ) +function RemoteModalDialog(props: RemoteElementProps) { + const properties = useRemoteProperties(uiKitCatalog['ui-dialog'].properties, props.entry) + if (properties.open === false) return null + // An app close followed by an open mounts a fresh dialog after a local dismissal. + return +} + +function OpenRemoteModalDialog({ + entry, + children, + slots, + emit, + properties: { heading, description, size, height }, +}: RemoteElementProps & { + readonly properties: ReturnType<(typeof uiKitCatalog)['ui-dialog']['properties']['parse']> +}) { + const { t } = useTranslationStore() const blocked = useRemoteCloseBlocked(entry.id) const [body, setBody] = useState(null) - // Without a close listener the app keeps its dialog open until it removes it. + const [dismissed, setDismissed] = useState(false) + const [requested, setRequested] = useState(false) const closable = entry.listeners.includes('close') + const { state, handler } = useAppDialogEscape(!dismissed && (blocked || requested), () => + setDismissed(true), + ) + const { openConfirmation } = handler const requestClose = useCallback(() => { - if (!blocked) emit('close') - }, [blocked, emit]) + if (blocked) return + if (!closable) { + setDismissed(true) + } else if (requested) { + openConfirmation() + } else { + setRequested(true) + emit('close') + } + }, [blocked, closable, emit, openConfirmation, requested]) const dialog = useMemo( () => ({ scope: entry.id, requestClose, body }), [body, entry.id, requestClose], @@ -62,21 +91,39 @@ function RemoteModalDialog({ entry, children, slots, emit }: RemoteElementProps) return ( { if (!next) requestClose() }} - closeDisabled={blocked || !closable} + closeDisabled={blocked} + onBlockedEscape={openConfirmation} title={heading} description={description ?? null} size={size ?? 'md'} height={height ?? 'default'} fixedHeight={height === 'tall'} navigation={slots.navigation} - footer={slots.footer} + footer={ + slots.footer || state.showEscape ? ( + <> + {slots.footer} + {state.showEscape ? ( + + {t('appUi.remote.dialog.closeAnyway')} + + ) : null} + + ) : undefined + } > {children} + ) } diff --git a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteTableCell.tsx b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteTableCell.tsx index 9f8a7666c..e225860ee 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteTableCell.tsx +++ b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteTableCell.tsx @@ -3,6 +3,21 @@ import { appUiBadgeClassName, appUiTones } from '../../../appUiPresentation.ts' import type { RemoteTableCellProps } from '../Types/remote-app-view.types.ts' import RemoteUiIcon from './RemoteUiIcon.tsx' +function TimeCell({ + value, + label, +}: { + readonly value: string + readonly label: string | undefined +}) { + if (label === undefined) return {value} + return ( + + ) +} + /** One table cell an app sends, drawn by its shape; the column kind decides for plain values. */ export default function RemoteTableCell({ kind, cell, formats }: RemoteTableCellProps) { if (cell === undefined || cell === null) return — @@ -11,12 +26,7 @@ export default function RemoteTableCell({ kind, cell, formats }: RemoteTableCell return {formats.number.format(cell)} } if (typeof cell === 'string') { - if (kind === 'time') - return ( - - ) + if (kind === 'time') return return ( {cell} ) @@ -34,12 +44,7 @@ export default function RemoteTableCell({ kind, cell, formats }: RemoteTableCell ) } - if ('time' in cell) - return ( - - ) + if ('time' in cell) return if ('measure' in cell) return ( diff --git a/web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteDataTableLogic.ts b/web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteDataTableLogic.ts index 10f928aea..2d8b68957 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteDataTableLogic.ts +++ b/web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteDataTableLogic.ts @@ -13,6 +13,7 @@ import type { TableColumnFilterConfigs, } from '@/shared/Table/Types/table.types.ts' import type { RemoteUiElementEntry } from '@/lib/AppUi/remote-tree.ts' +import { remoteTableDate } from '@/lib/AppUi/remote-table-time.ts' import { appUiMeasureFormats } from '../../../appUiPresentation.ts' import RemoteTableCell from '../Components/RemoteTableCell.tsx' import type { @@ -31,10 +32,10 @@ const dateFilter = createDateRangeFilter() /** The value a cell sorts and filters by; time columns sort as dates. */ function sortValue(column: RemoteTableColumn, cell: RemoteTableCellValue | undefined) { if (cell === undefined || cell === null) return undefined - if (typeof cell === 'string') return column.kind === 'time' ? new Date(cell) : cell + if (typeof cell === 'string') return column.kind === 'time' ? remoteTableDate(cell) : cell if (typeof cell === 'number') return cell if ('badge' in cell) return cell.badge.label - if ('time' in cell) return new Date(cell.time) + if ('time' in cell) return remoteTableDate(cell.time) if ('measure' in cell) return cell.measure.value return cell.httpStatus } @@ -47,10 +48,11 @@ function cellText( ) { if (cell === undefined || cell === null) return '' // A plain string in a time column shows as a localized time, so it is searched as one. - if (typeof cell === 'string') return column.kind === 'time' ? formats.time(cell) : cell + if (typeof cell === 'string') + return column.kind === 'time' ? (formats.time(cell) ?? cell) : cell if (typeof cell === 'number') return formats.number.format(cell) if ('badge' in cell) return cell.badge.label - if ('time' in cell) return formats.time(cell.time) + if ('time' in cell) return formats.time(cell.time) ?? cell.time if ('measure' in cell) return formats.measure(cell.measure.value, cell.measure.unit) return String(cell.httpStatus) } @@ -95,7 +97,10 @@ export default function useRemoteDataTableLogic( const date = new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'medium' }) return { number: new Intl.NumberFormat(locale), - time: (value) => date.format(new Date(value)), + time: (value) => { + const timestamp = remoteTableDate(value) + return timestamp === undefined ? undefined : date.format(timestamp) + }, measure: (value, unit) => new Intl.NumberFormat(locale, appUiMeasureFormats[unit]).format(value), } diff --git a/web/src/features/AppUi/Components/RemoteAppView/Types/remote-app-view.types.ts b/web/src/features/AppUi/Components/RemoteAppView/Types/remote-app-view.types.ts index e5c94e5a6..799c9abf1 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Types/remote-app-view.types.ts +++ b/web/src/features/AppUi/Components/RemoteAppView/Types/remote-app-view.types.ts @@ -92,7 +92,7 @@ export type RemoteMeasureUnit = 'ms' | 's' | 'percent' | 'count' /** Locale formats shared by every cell of one table. */ export interface RemoteCellFormats { readonly number: Intl.NumberFormat - readonly time: (value: string) => string + readonly time: (value: string) => string | undefined readonly measure: (value: number, unit: RemoteMeasureUnit) => string } diff --git a/web/src/features/AppUi/Hooks/useAppDialogEscape.ts b/web/src/features/AppUi/Hooks/useAppDialogEscape.ts new file mode 100644 index 000000000..1eed46b2f --- /dev/null +++ b/web/src/features/AppUi/Hooks/useAppDialogEscape.ts @@ -0,0 +1,33 @@ +import { useCallback, useEffect, useState } from 'react' + +/** Give normal close and save actions time to finish before adding a visible escape action. */ +export default function useAppDialogEscape(waiting: boolean, onForceClose: () => void) { + const [showEscape, setShowEscape] = useState(false) + const [confirming, setConfirming] = useState(false) + const [wasWaiting, setWasWaiting] = useState(waiting) + if (wasWaiting !== waiting) { + setWasWaiting(waiting) + if (!waiting) { + setShowEscape(false) + setConfirming(false) + } + } + + useEffect(() => { + if (!waiting) return + const timer = setTimeout(() => setShowEscape(true), 2_000) + return () => clearTimeout(timer) + }, [waiting]) + + return { + state: { showEscape, confirming }, + handler: { + openConfirmation: useCallback(() => setConfirming(true), []), + setConfirming, + forceClose: () => { + setConfirming(false) + onForceClose() + }, + }, + } +} diff --git a/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts b/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts index e73b9a6bd..22e620ea6 100644 --- a/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts +++ b/web/src/features/AppUi/Hooks/useAppHostActionDialogLogic.ts @@ -24,7 +24,7 @@ export default function useAppHostActionDialogLogic({ state: { app: app && action ? app : undefined, route, - title: action ? nativeText(action.title, locale) : app?.name, + title: action ? nativeText(action.title, locale) : undefined, }, handler: { handleNavigate: (next: string) => setNavigation({ action: actionId, route: next }), diff --git a/web/src/features/AppUi/NativeAppUi.tsx b/web/src/features/AppUi/NativeAppUi.tsx index 7f544250b..16c3c0988 100644 --- a/web/src/features/AppUi/NativeAppUi.tsx +++ b/web/src/features/AppUi/NativeAppUi.tsx @@ -7,16 +7,25 @@ import NativeAppForm from './Components/NativeAppForm.tsx' import NativeAppTable from './Components/NativeAppTable.tsx' import { useNativeAppUiLogic, type NativeAppSession } from './Hooks/useNativeAppUiLogic.ts' import AppContentSkeleton from './Components/AppContentSkeleton.tsx' +import AppViewErrorBoundary from './Components/AppViewErrorBoundary.tsx' -export default function NativeAppUi({ - app, - route, - onNavigate, -}: { - app: AppUiSummary - route: string - onNavigate: (route: string) => void -}) { +interface NativeAppUiProps { + readonly app: AppUiSummary + readonly route: string + readonly onNavigate: (route: string) => void +} + +export default function NativeAppUi(props: NativeAppUiProps) { + return ( + + + + ) +} + +function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) { const { t, locale } = useTranslationStore() const { state, handler } = useNativeAppUiLogic(app) const { source, scope } = state diff --git a/web/src/lib/AppUi/remote-table-time.ts b/web/src/lib/AppUi/remote-table-time.ts new file mode 100644 index 000000000..0b8faaf02 --- /dev/null +++ b/web/src/lib/AppUi/remote-table-time.ts @@ -0,0 +1,5 @@ +/** Plain strings are allowed even in time columns, so a cell can have no sortable date. */ +export function remoteTableDate(value: string): Date | undefined { + const date = new Date(value) + return Number.isNaN(date.getTime()) ? undefined : date +} diff --git a/web/src/lib/Language/Locales/de.json b/web/src/lib/Language/Locales/de.json index 3b57094b8..5017f7417 100644 --- a/web/src/lib/Language/Locales/de.json +++ b/web/src/lib/Language/Locales/de.json @@ -420,6 +420,11 @@ "close": "Schließen" }, "remote": { + "dialog": { + "closeAnyway": "Trotzdem schließen", + "discardWarning": "Ungespeicherte Änderungen können verloren gehen. Ein laufender Speichervorgang kann noch abgeschlossen werden.", + "unansweredClose": "Der Dialog ist noch geöffnet. Möchtest du ihn jetzt schließen?" + }, "states": { "loading": "Wird geladen…", "empty": "Noch nichts vorhanden", diff --git a/web/src/lib/Language/Locales/en.json b/web/src/lib/Language/Locales/en.json index 56f08880e..91087d771 100644 --- a/web/src/lib/Language/Locales/en.json +++ b/web/src/lib/Language/Locales/en.json @@ -420,6 +420,11 @@ "close": "Close" }, "remote": { + "dialog": { + "closeAnyway": "Close anyway", + "discardWarning": "Unsaved changes may be lost. A save already in progress may still finish.", + "unansweredClose": "The dialog is still open. Close it now?" + }, "states": { "loading": "Loading…", "empty": "Nothing here yet", diff --git a/web/src/lib/Language/Locales/es.json b/web/src/lib/Language/Locales/es.json index c7cf67ea0..1b8c5e444 100644 --- a/web/src/lib/Language/Locales/es.json +++ b/web/src/lib/Language/Locales/es.json @@ -422,6 +422,11 @@ "close": "Cerrar" }, "remote": { + "dialog": { + "closeAnyway": "Cerrar de todos modos", + "discardWarning": "Es posible que se pierdan los cambios sin guardar. Si ya hay un guardado en curso, puede que termine.", + "unansweredClose": "El cuadro de diálogo sigue abierto. ¿Quieres cerrarlo ahora?" + }, "states": { "loading": "Cargando…", "empty": "Todavía no hay nada aquí", diff --git a/web/src/lib/Language/Locales/fr.json b/web/src/lib/Language/Locales/fr.json index d6ec169a0..0665fe9e1 100644 --- a/web/src/lib/Language/Locales/fr.json +++ b/web/src/lib/Language/Locales/fr.json @@ -422,6 +422,11 @@ "close": "Fermer" }, "remote": { + "dialog": { + "closeAnyway": "Fermer quand même", + "discardWarning": "Les modifications non enregistrées peuvent être perdues. Un enregistrement en cours peut encore se terminer.", + "unansweredClose": "La boîte de dialogue est toujours ouverte. Voulez-vous la fermer maintenant ?" + }, "states": { "loading": "Chargement…", "empty": "Rien pour l’instant", diff --git a/web/src/lib/Language/Locales/it.json b/web/src/lib/Language/Locales/it.json index e6cf373c1..9af1030ab 100644 --- a/web/src/lib/Language/Locales/it.json +++ b/web/src/lib/Language/Locales/it.json @@ -422,6 +422,11 @@ "close": "Chiudi" }, "remote": { + "dialog": { + "closeAnyway": "Chiudi comunque", + "discardWarning": "Le modifiche non salvate potrebbero andare perse. Un salvataggio in corso potrebbe ancora completarsi.", + "unansweredClose": "La finestra di dialogo è ancora aperta. Vuoi chiuderla ora?" + }, "states": { "loading": "Caricamento…", "empty": "Ancora niente qui", diff --git a/web/src/lib/Language/Locales/nl.json b/web/src/lib/Language/Locales/nl.json index 223ef1fd0..894ef5177 100644 --- a/web/src/lib/Language/Locales/nl.json +++ b/web/src/lib/Language/Locales/nl.json @@ -401,6 +401,11 @@ "close": "Sluiten" }, "remote": { + "dialog": { + "closeAnyway": "Toch sluiten", + "discardWarning": "Niet-opgeslagen wijzigingen kunnen verloren gaan. Een lopende opslagbewerking kan nog worden voltooid.", + "unansweredClose": "Het dialoogvenster is nog open. Wil je het nu sluiten?" + }, "states": { "loading": "Laden…", "empty": "Hier staat nog niets", diff --git a/web/src/lib/Language/Locales/pl.json b/web/src/lib/Language/Locales/pl.json index 4cafe7350..f2d8c6f9e 100644 --- a/web/src/lib/Language/Locales/pl.json +++ b/web/src/lib/Language/Locales/pl.json @@ -424,6 +424,11 @@ "close": "Zamknij" }, "remote": { + "dialog": { + "closeAnyway": "Zamknij mimo to", + "discardWarning": "Niezapisane zmiany mogą przepaść. Zapis, który już trwa, może się jeszcze zakończyć.", + "unansweredClose": "Okno dialogowe jest nadal otwarte. Czy chcesz je teraz zamknąć?" + }, "states": { "loading": "Ładowanie…", "empty": "Na razie nic tu nie ma", diff --git a/web/src/lib/Language/Locales/pt.json b/web/src/lib/Language/Locales/pt.json index c1b30405e..f87a46479 100644 --- a/web/src/lib/Language/Locales/pt.json +++ b/web/src/lib/Language/Locales/pt.json @@ -422,6 +422,11 @@ "close": "Fechar" }, "remote": { + "dialog": { + "closeAnyway": "Fechar mesmo assim", + "discardWarning": "As alterações não guardadas podem perder-se. Uma gravação em curso ainda pode ser concluída.", + "unansweredClose": "A caixa de diálogo ainda está aberta. Queres fechá-la agora?" + }, "states": { "loading": "A carregar…", "empty": "Ainda não há nada aqui", diff --git a/web/src/shared/Modal/Hooks/useModalLogic.ts b/web/src/shared/Modal/Hooks/useModalLogic.ts index 26e14e2bd..8696a6ec4 100644 --- a/web/src/shared/Modal/Hooks/useModalLogic.ts +++ b/web/src/shared/Modal/Hooks/useModalLogic.ts @@ -6,6 +6,7 @@ import type { PreventableEvent } from '../Types/modal.types.ts' export default function useModalLogic({ closeDisabled, + onBlockedEscape, onOpenAutoFocus, onClosed, onOpenChange, @@ -86,8 +87,11 @@ export default function useModalLogic({ trigger?.click() } event.preventDefault() + return } + const blockedEscape = closeDisabled && !event.defaultPrevented preventClose(event) + if (blockedEscape) onBlockedEscape?.() }, preventClose, }, diff --git a/web/src/shared/Modal/Types/modal.types.ts b/web/src/shared/Modal/Types/modal.types.ts index a48f461b0..187ace4a6 100644 --- a/web/src/shared/Modal/Types/modal.types.ts +++ b/web/src/shared/Modal/Types/modal.types.ts @@ -11,6 +11,7 @@ export interface ModalProps { readonly fixedHeight?: boolean readonly height?: ModalHeight readonly navigation?: ReactNode + readonly onBlockedEscape?: (() => void) | undefined readonly onOpenAutoFocus?: ((event: PreventableEvent) => void) | undefined readonly onClosed?: (() => void) | undefined readonly onOpenChange: (open: boolean) => void @@ -47,6 +48,7 @@ export interface ConfirmDialogLogicResult { } export interface UseModalLogicParams { readonly closeDisabled: boolean + readonly onBlockedEscape?: (() => void) | undefined readonly onOpenAutoFocus?: ((event: PreventableEvent) => void) | undefined readonly onClosed?: (() => void) | undefined readonly onOpenChange: (open: boolean) => void diff --git a/web/src/shared/Modal/index.tsx b/web/src/shared/Modal/index.tsx index 8dbe6c535..84cd82091 100644 --- a/web/src/shared/Modal/index.tsx +++ b/web/src/shared/Modal/index.tsx @@ -38,6 +38,7 @@ export function Modal({ fixedHeight = false, height = 'default', navigation, + onBlockedEscape, onOpenAutoFocus, onClosed, size = 'md', @@ -50,6 +51,7 @@ export function Modal({ handler, } = useModalLogic({ closeDisabled, + onBlockedEscape, onOpenAutoFocus, onOpenChange, onClosed, diff --git a/web/src/tests/features/AppUi/app-ui-frame.test.tsx b/web/src/tests/features/AppUi/app-ui-frame.test.tsx index 781fcf68c..b5e5c7b54 100644 --- a/web/src/tests/features/AppUi/app-ui-frame.test.tsx +++ b/web/src/tests/features/AppUi/app-ui-frame.test.tsx @@ -1,6 +1,7 @@ import { expect, mock, spyOn, test } from 'bun:test' import { GlobalRegistrator } from '@happy-dom/global-registrator' import type { UserThemeMode } from '@/config/Types/theme-config.types.ts' +import type { RemoteTableCellProps } from '@/features/AppUi/Components/RemoteAppView/Types/remote-app-view.types.ts' import type { AppUiSummary } from '@/lib/AppUi/contract.ts' import type { bindAppUiFrame } from '@/lib/AppUi/session.ts' import type { AppLanguage } from '@/shared/Language/Types/language.types.ts' @@ -51,6 +52,15 @@ await mock.module('@/lib/AppUi/session.ts', () => ({ bindAppUiFrame: bindFrame, supportsRemoteRendering: (summary: AppUiSummary) => summary.uiBridgeVersion === '1.3.0', })) +await mock.module( + '@/features/AppUi/Components/RemoteAppView/Components/RemoteTableCell.tsx', + () => ({ + default: ({ cell }: RemoteTableCellProps) => { + if (cell === 'Render failure') throw new Error('Injected cell render failure') + return {String(cell)} + }, + }), +) const { act } = await import('react') const { createRoot } = await import('react-dom/client') @@ -242,3 +252,95 @@ test('keeps a remotely rendered app in its hidden frame and draws its tree', asy success.mockRestore() } }) + +function findBinding(id: string) { + const binding = bindFrame.mock.calls.findLast((call) => call[2].installationId === id) + if (!binding) throw new Error('The app frame was not bound.') + return binding +} + +test('retires only the app frame with a render error and opens a fresh frame on retry', async () => { + sessionId = 'test-session' + const container = document.createElement('div') + const root = createRoot(container, { onCaughtError: () => undefined }) + try { + await act(async () => + root.render( + withTestLanguage( + <> + +
+ +
+
+ +
+ , + ), + ), + ) + const failing = findBinding(app.installationId) + const other = findBinding('other-installation') + const previousCloses = close.mock.calls.length + let accepted = false + await act(async () => { + failing[3].onConnected('remote') + other[3].onConnected('remote') + other[3].onRemoteMutate([ + [ + 0, + '~', + { + id: '2', + type: 1, + element: 'ui-button', + children: [], + properties: { label: 'Other app action' }, + eventListeners: { press: true }, + }, + 0, + ], + ]) + accepted = failing[3].onRemoteMutate([ + [ + 0, + '~', + { + id: '1', + type: 1, + element: 'ui-data-table', + children: [], + properties: { + columns: [{ id: 'status', header: 'Status', kind: 'text' }], + rows: [{ id: 'first', cells: { status: 'Render failure' } }], + }, + }, + 0, + ], + ]) + }) + + const failedSection = container.querySelector('[aria-label="Failing app"]') + const otherSection = container.querySelector('[aria-label="Other app"]') + expect(accepted).toBe(true) + expect(failedSection?.textContent).toContain('This app is currently unavailable.') + expect(failedSection?.querySelector('iframe')).toBeNull() + expect(close).toHaveBeenCalledTimes(previousCloses + 1) + expect(container.textContent).toContain('Host action') + await act(async () => otherSection?.querySelector('button')?.click()) + expect(sendRemoteEvent).toHaveBeenLastCalledWith('2', 'press', {}) + + await act(async () => failedSection?.querySelector('button')?.click()) + expect(failedSection?.querySelector('iframe')).not.toBeNull() + expect(findBinding(app.installationId)[1]).not.toBe(failing[1]) + expect(findBinding('other-installation')).toBe(other) + } finally { + await act(async () => root.unmount()) + } +}) diff --git a/web/src/tests/features/AppUi/remote-app-data.test.tsx b/web/src/tests/features/AppUi/remote-app-data.test.tsx index 260bfce6a..84c1a1046 100644 --- a/web/src/tests/features/AppUi/remote-app-data.test.tsx +++ b/web/src/tests/features/AppUi/remote-app-data.test.tsx @@ -263,20 +263,35 @@ test('draws an app chart and status strip with the platform components', async ( expect(blocks[1]?.className).toContain('bg-danger-text') }) -test('searches plain times as the localized dates the table shows', async () => { +test('shows and searches malformed times as text and sorts them after dates', async () => { const { container } = await mount( element('1', 'ui-data-table', { properties: { - columns: [{ id: 'checked', header: 'Checked', kind: 'time' }], + columns: [{ id: 'checked', header: 'Checked', kind: 'time', sortable: true }], rows: [ { id: 'october', cells: { checked: '2026-10-15T12:00:00.000Z' } }, + { id: 'never', cells: { checked: 'Never' } }, { id: 'november', cells: { checked: '2026-11-29T12:00:00.000Z' } }, ], + initialSort: { column: 'checked', desc: true }, searchable: true, }, }), ) - expect(bodyRows(container)).toHaveLength(2) + expect(bodyRows(container)).toHaveLength(3) + const displayedDates = () => + bodyRows(container).map((row) => row.querySelector('time')?.dateTime ?? row.textContent) + expect(displayedDates()).toEqual([ + '2026-11-29T12:00:00.000Z', + '2026-10-15T12:00:00.000Z', + 'Never', + ]) + await click(container.querySelector('th button')) + expect(displayedDates()).toEqual([ + '2026-10-15T12:00:00.000Z', + '2026-11-29T12:00:00.000Z', + 'Never', + ]) const search = container.querySelector('input[type="search"]') const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set await act(async () => { @@ -287,4 +302,10 @@ test('searches plain times as the localized dates the table shows', async () => expect(bodyRows(container)[0]?.querySelector('time')?.getAttribute('dateTime')).toBe( '2026-11-29T12:00:00.000Z', ) + await act(async () => { + setter?.call(search, 'never') + search?.dispatchEvent(new Event('input', { bubbles: true })) + }) + await waitFor(() => bodyRows(container)[0]?.textContent === 'Never') + expect(displayedDates()).toEqual(['Never']) }) diff --git a/web/src/tests/features/AppUi/remote-app-dialogs.test.tsx b/web/src/tests/features/AppUi/remote-app-dialogs.test.tsx index 7fd7746cb..8d792c61a 100644 --- a/web/src/tests/features/AppUi/remote-app-dialogs.test.tsx +++ b/web/src/tests/features/AppUi/remote-app-dialogs.test.tsx @@ -187,6 +187,121 @@ async function click(target: HTMLElement | undefined) { await act(async () => target.click()) } +async function escape(target: HTMLElement | undefined) { + if (!target) throw new Error('No dialog to dismiss.') + await act(async () => + target.dispatchEvent( + new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }), + ), + ) +} + +test('closes a standalone dialog without a listener and lets the app reopen it', async () => { + const store = createRemoteUiStore() + await render() + await apply(store, [ + [ + 0, + '~', + element('1', 'ui-dialog', { + properties: { heading: 'No close listener' }, + }), + 0, + ], + ]) + expect(button('Close dialog')?.disabled).toBe(false) + await click(button('Close dialog')) + expect(document.querySelector('[role="dialog"]')).toBeNull() + expect(onEvent).not.toHaveBeenCalled() + + await apply(store, [[3, '1', 'heading', 'New title']]) + expect(document.querySelector('[role="dialog"]')).toBeNull() + await apply(store, [[3, '1', 'open', false]]) + await apply(store, [[3, '1', 'open', true]]) + expect(document.querySelector('[role="dialog"] h2')?.textContent).toBe('New title') +}) + +test('offers a local close if an app ignores the close event', async () => { + const store = createRemoteUiStore() + await render() + await apply(store, [ + [ + 0, + '~', + element('1', 'ui-dialog', { + properties: { heading: 'Unanswered close' }, + eventListeners: { close: true }, + }), + 0, + ], + ]) + await click(button('Close dialog')) + expect(onEvent).toHaveBeenCalledTimes(1) + expect(document.querySelector('[role="dialog"] h2')?.textContent).toBe('Unanswered close') + expect(button('Close anyway')).toBeUndefined() + await act(async () => Bun.sleep(2_050)) + await click(button('Close anyway')) + const dialogs = [...document.querySelectorAll('[role="dialog"]')] + expect(dialogs).toHaveLength(2) + const confirmButton = [...(dialogs.at(-1)?.querySelectorAll('button') ?? [])].find( + (candidate) => candidate.textContent?.trim() === 'Close anyway', + ) + await click(confirmButton) + expect(document.querySelector('[role="dialog"]')).toBeNull() + expect(onEvent).toHaveBeenCalledTimes(1) +}) + +test('guards the fallback close and asks before leaving a pending app save', async () => { + const store = createRemoteUiStore() + frameStore = store + const onOpenChange = mock(() => {}) + await render( + , + ) + await apply(store, [ + [ + 0, + '~', + element('1', 'ui-dialog', { + properties: { heading: 'Saving settings' }, + eventListeners: { close: true }, + children: [ + element('7', 'ui-form', { + properties: { + id: 'policy', + values: savedValues, + version: 'v1', + pending: true, + }, + }), + ], + }), + 0, + ], + ]) + expect(button('Close')?.disabled).toBe(true) + expect(button('Close dialog')?.disabled).toBe(true) + await click(button('Close')) + expect(onOpenChange).not.toHaveBeenCalled() + + await escape(button('Close dialog')) + expect(document.body.textContent).toContain('A save already in progress may still finish.') + await click(button('Cancel')) + expect(onOpenChange).not.toHaveBeenCalled() + + await escape(button('Close dialog')) + await click(button('Close anyway')) + expect(onOpenChange).toHaveBeenCalledWith(false) + expect(onEvent).not.toHaveBeenCalled() +}) + test('draws an app dialog with platform tabs, a held draft and the footer guard', async () => { const store = createRemoteUiStore() await render()