From 31606142954c9e8629a3487fc95a9afd17440e55 Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Sun, 29 Nov 2026 22:07:10 +0100 Subject: [PATCH 1/2] feat(apps): draw app dialogs, tabs and forms with platform components Remotely rendered apps can now use ui-dialog, ui-tabs, ui-tab-panel, ui-form, ui-form-actions and the text, number, toggle and select fields. The platform holds form drafts with dirty and valid state from the field properties, guards dialog close like its own dialogs, and keeps the tab selection. An app whose root is a single ui-dialog fills the host row action dialog's title, navigation and footer instead of opening a second dialog. Shared Tabs gain per-tab disabling. Co-Authored-By: Claude Opus 5.5 --- .../AppUi/Components/AppHostActionDialog.tsx | 67 ++-- .../Components/RemoteActionElements.tsx | 31 +- .../Components/RemoteDialogElements.tsx | 171 ++++++++++ .../Components/RemoteFieldElements.tsx | 304 ++++++++++++++++++ .../Components/RemoteFormElements.tsx | 119 +++++++ .../RemoteAppView/Components/RemoteNode.tsx | 26 +- .../RemoteAppView/Hooks/useRemoteForm.ts | 94 ++++++ .../RemoteAppView/Hooks/useRemoteTabsLogic.ts | 57 ++++ .../RemoteAppView/Hooks/useRemoteUiEntry.ts | 21 +- .../Types/remote-app-view.types.ts | 40 +++ .../AppUi/Components/RemoteAppView/index.tsx | 42 ++- .../RemoteAppView/remoteElementContexts.ts | 18 ++ .../AppUi/Types/app-dialog-surface.types.ts | 18 ++ .../features/AppUi/appDialogSurfaceContext.ts | 9 + web/src/lib/AppUi/remote-forms.ts | 297 +++++++++++++++++ web/src/lib/AppUi/remote-tree.ts | 5 +- web/src/lib/Language/Locales/de.json | 5 +- web/src/lib/Language/Locales/en.json | 5 +- web/src/lib/Language/Locales/es.json | 5 +- web/src/lib/Language/Locales/fr.json | 5 +- web/src/lib/Language/Locales/it.json | 5 +- web/src/lib/Language/Locales/nl.json | 5 +- web/src/lib/Language/Locales/pl.json | 5 +- web/src/lib/Language/Locales/pt.json | 5 +- web/src/shared/Tabs/Hooks/useTabsLogic.ts | 17 +- web/src/shared/Tabs/Types/tabs.types.ts | 1 + web/src/shared/Tabs/index.tsx | 2 +- .../AppUi/remote-app-dialogs.test.tsx | 303 +++++++++++++++++ web/src/tests/lib/AppUi/remote-forms.test.ts | 179 +++++++++++ 29 files changed, 1799 insertions(+), 62 deletions(-) create mode 100644 web/src/features/AppUi/Components/RemoteAppView/Components/RemoteDialogElements.tsx create mode 100644 web/src/features/AppUi/Components/RemoteAppView/Components/RemoteFieldElements.tsx create mode 100644 web/src/features/AppUi/Components/RemoteAppView/Components/RemoteFormElements.tsx create mode 100644 web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteForm.ts create mode 100644 web/src/features/AppUi/Components/RemoteAppView/Hooks/useRemoteTabsLogic.ts create mode 100644 web/src/features/AppUi/Components/RemoteAppView/remoteElementContexts.ts create mode 100644 web/src/features/AppUi/Types/app-dialog-surface.types.ts create mode 100644 web/src/features/AppUi/appDialogSurfaceContext.ts create mode 100644 web/src/lib/AppUi/remote-forms.ts create mode 100644 web/src/tests/features/AppUi/remote-app-dialogs.test.tsx create mode 100644 web/src/tests/lib/AppUi/remote-forms.test.ts diff --git a/web/src/features/AppUi/Components/AppHostActionDialog.tsx b/web/src/features/AppUi/Components/AppHostActionDialog.tsx index 27635b831..5c87e572b 100644 --- a/web/src/features/AppUi/Components/AppHostActionDialog.tsx +++ b/web/src/features/AppUi/Components/AppHostActionDialog.tsx @@ -1,44 +1,71 @@ +import { useMemo, useState } 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 AppUiFrame from '../AppUiFrame.tsx' +import { AppDialogSurfaceContext } from '../appDialogSurfaceContext.ts' import useAppHostActionDialogLogic from '../Hooks/useAppHostActionDialogLogic.ts' import type { AppHostActionDialogProps } from '../Types/app-host-table.types.ts' +import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts' -/** A host row action of an app, opened in a platform dialog for that host. */ +/** + * A host row action of an app, opened in a platform dialog for that host. An app drawn with the UI + * kit whose root is a dialog fills this dialog's title, navigation and footer itself. + */ export default function AppHostActionDialog(props: AppHostActionDialogProps) { const { t } = useTranslationStore() const { state, handler } = useAppHostActionDialogLogic(props) + const { onOpenChange } = props + const [chrome, setChrome] = useState(null) + const [navigation, setNavigation] = useState(null) + const [footer, setFooter] = useState(null) + const surface = useMemo( + () => ({ 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 close = () => { + chrome?.onClose() + onOpenChange(false) + } return ( { + if (open) onOpenChange(true) + else close() + }} + closeDisabled={chrome?.closeDisabled ?? false} + title={chrome?.heading ?? state.title ?? t('appUi.unavailable')} + description={chrome?.description ?? props.hostDomains.join(', ')} size="xl" fixedHeight height="tall" + navigation={chrome?.navigation ?
: undefined} footer={ - + chrome?.footer ? ( +
+ ) : ( + + ) } > {state.app && state.route ? ( -
- +
+ + +
) : ( {t('appUi.unavailable')} diff --git a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx index bf37e41ba..dca173ef0 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx +++ b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx @@ -1,28 +1,43 @@ import { uiKitCatalog } from '@rentnerproxy/app-contracts' import { LoaderCircle } from 'lucide-react' -import { useMemo } from 'react' +import { useContext, useMemo } from 'react' import { ActionMenu } from '@/shared/ActionMenu/index.tsx' import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts' import { ConfirmDialog } from '@/shared/Modal/Components/ConfirmDialog.tsx' import useRemoteButtonLogic from '../Hooks/useRemoteButtonLogic.ts' +import { useRemoteFormState } from '../Hooks/useRemoteForm.ts' import useRemoteProperties from '../Hooks/useRemoteProperties.ts' +import { useRemoteAppView } from '../Hooks/useRemoteUiEntry.ts' +import { RemoteFormContext } from '../remoteElementContexts.ts' import type { RemoteElementProps } from '../Types/remote-app-view.types.ts' import RemoteUiIcon from './RemoteUiIcon.tsx' -// Submit buttons and their forms arrive with the form elements; until then every button presses. +/** + * A button that sends press. A submit button saves the form it names, or the form it sits in, and + * is enabled only while that form may be saved. + */ export function RemoteButton({ entry, emit }: RemoteElementProps) { - const { label, variant, icon, disabled, pending, pendingLabel, confirm } = useRemoteProperties( - uiKitCatalog['ui-button'].properties, - entry, - ) - const { state, handler } = useRemoteButtonLogic(confirm !== undefined, () => emit('press')) + const { label, variant, icon, disabled, pending, pendingLabel, confirm, type, form } = + useRemoteProperties(uiKitCatalog['ui-button'].properties, entry) + const { forms } = useRemoteAppView() + const surroundingForm = useContext(RemoteFormContext) + const target = type === 'submit' ? (form ?? surroundingForm) : undefined + const targetState = useRemoteFormState(target) + const { state, handler } = useRemoteButtonLogic(confirm !== undefined, () => { + if (target !== undefined) forms.submit(target) + emit('press') + }) return ( <> + + + ) +} + +export function RemoteTextField({ entry, emit }: RemoteElementProps) { + const props = useRemoteProperties(uiKitCatalog['ui-text-field'].properties, entry) + const { locale } = useTranslationStore() + const { kind, required, minLength, maxLength } = props + const rule = useMemo( + () => ({ + kind: 'text', + required: required === true, + minLength, + maxLength, + format: kind === 'email' ? 'email' : kind === 'url' ? 'url' : undefined, + }), + [kind, maxLength, minLength, required], + ) + const field = useRemoteFieldBinding({ + entry, + name: props.name, + own: props.value, + empty: '', + readOnly: props.readonly === true, + disabled: props.disabled === true, + read: readText, + rule, + }) + const common = { + id: field.id, + name: props.name, + label: , + description: props.description, + error: props.error ?? null, + value: field.value, + required: required === true, + readOnly: field.readOnly, + disabled: field.disabled, + placeholder: props.placeholder, + minLength, + maxLength, + locale, + onValueChange: (value: string) => { + field.setValue(value) + emit('change', { value }) + }, + onBlur: () => emit('blur', { value: field.value }), + } + if (kind === 'multiline') return