Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default function InstalledAppCard({
name,
publisher,
canOpen,
openRouteId,
actions,
blockedRelease,
updateRequiresSource,
Expand Down Expand Up @@ -113,7 +112,7 @@ export default function InstalledAppCard({
to="/apps/$installationId/{-$routeId}"
params={{
installationId: installation.installationId,
routeId: openRouteId,
routeId: undefined,
}}
search={{}}
className={buttonClassName('secondary')}
Expand Down
11 changes: 2 additions & 9 deletions web/src/features/AppCatalog/Hooks/useAppCatalogLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { toast } from '@rentnerkev/toasts'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useEffect, useRef, useState } from 'react'
import { useAppUi } from '@/features/AppUi/AppUiProvider.tsx'
import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts'
import { appPageDefaultRoute } from '@/lib/AppUi/page-access.ts'
import {
isPackageSourceOutage,
sameCatalogLifecycle,
Expand Down Expand Up @@ -164,17 +164,10 @@ export default function useAppCatalogLogic() {
installation,
name: installation.name ?? declaredApp?.name ?? app?.name ?? installation.appId,
publisher: declaredApp?.publisher,
// An app that declares extensions opens only through a page it declares.
canOpen:
installation.state === 'running' &&
app?.appId === installation.appId &&
(app.extensionCatalog === undefined || app.pages.length > 0),
openRouteId:
app?.extensionCatalog !== undefined &&
app.pages[0] &&
app.pages[0].route !== appUiDefaultRoute(app)
? app.pages[0].route
: undefined,
appPageDefaultRoute(app) !== undefined,
actions: catalogInstallationActions(
installation,
status === 'ready',
Expand Down
2 changes: 0 additions & 2 deletions web/src/features/AppCatalog/Types/app-catalog.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type CatalogInstallationView = {
name: string
publisher: string | undefined
canOpen: boolean
/** The route of the app's first page, or undefined for its default route. */
openRouteId: string | undefined
actions: CatalogLifecycleInput[]
/** The newest listed release the appliance cannot offer, with the reason. */
blockedRelease: CatalogBlockedRelease | undefined
Expand Down
35 changes: 29 additions & 6 deletions web/src/features/AppUi/AppUiFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useEffectEvent, useMemo, useState } from 'react'

import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts'
import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import type { AppUiSlot, AppUiSummary } from '@/lib/AppUi/contract.ts'
import { APP_UI_PREFIX } from '@/lib/AppUi/paths.ts'
import { supportsRemoteRendering, type AppUiRevocation } from '@/lib/AppUi/session.ts'
Expand All @@ -20,6 +21,7 @@ type FrameProps = {
app: AppUiSummary
slot?: AppUiSlot | undefined
hostId?: string | undefined
hostActionId?: string | undefined
route?: string | undefined
onNavigate?: ((route: string) => void) | undefined
/** Fill the height of a fixed-height container, such as a dialog body. */
Expand All @@ -28,26 +30,40 @@ type FrameProps = {

type AppFrameSource = OpenedSource & { frameToken: string }

export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill }: FrameProps) {
export default function AppUiFrame({
app,
slot,
hostId,
hostActionId,
route,
onNavigate,
fill,
}: FrameProps) {
const sessionId = useAppUi()?.sessionId
const [localRoute, setLocalRoute] = useState<string>()
const [attempt, setAttempt] = useState(0)
const defaultRoute = appUiDefaultRoute(app)
const current =
route ??
(localRoute && app.routes.includes(localRoute) ? localRoute : appUiDefaultRoute(app))
[localRoute, defaultRoute, ...app.routes].find(
(candidate) =>
candidate !== undefined && isAppUiRouteAllowed(app, candidate, hostActionId),
)
// A new generation, a reconnect or a retry remounts the view below; drafts the user did not
// save pass to the next view of the same session, app, slot and host, never to another.
// save pass to the next view for the same session, app, slot, host and action.
const identity = JSON.stringify([
sessionId ?? null,
app.installationId,
slot ?? null,
hostId ?? null,
hostActionId ?? null,
])
// A holder the views write after render, from their layout effects; never read while rendering.
const [kept] = useState<KeptDrafts>(() => ({ current: null }))
const handoff = useMemo(() => draftHandoff(identity, kept), [identity, kept])

if (!sessionId) return null
if (!sessionId || current === undefined || !isAppUiRouteAllowed(app, current, hostActionId))
return null

// Routing updates the open document through the bridge.
const retry = () => setAttempt((previous) => previous + 1)
Expand All @@ -60,6 +76,7 @@ export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill
app.generation,
slot,
hostId,
hostActionId,
attempt,
])}
onRetry={retry}
Expand All @@ -69,6 +86,7 @@ export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill
app={app}
slot={slot}
hostId={hostId}
hostActionId={hostActionId}
route={current}
fill={fill}
onNavigate={onNavigate ?? setLocalRoute}
Expand Down Expand Up @@ -102,11 +120,11 @@ function AppUiMount(props: MountProps) {
)
const showOwnFrame = useCallback(() => setPooled(false), [])
if (!pooled || !pool) return <OwnFrameMount {...props} />
const { app, sessionId, slot, hostId, route, fill, onNavigate, onRetry } = props
const { app, sessionId, slot, hostId, hostActionId, route, fill, onNavigate, onRetry } = props
return (
<PooledAppFrameView
pool={pool}
request={{ app, sessionId, slot, hostId, route }}
request={{ app, sessionId, slot, hostId, hostActionId, route }}
theme={ui?.theme ?? 'light'}
fill={fill}
onNavigate={onNavigate}
Expand All @@ -121,6 +139,7 @@ function OwnFrameMount({
sessionId,
slot,
hostId,
hostActionId,
route,
onNavigate,
onRetry,
Expand Down Expand Up @@ -191,6 +210,7 @@ function OwnFrameMount({
source={source}
route={route}
slot={slot}
hostActionId={hostActionId}
fill={fill}
onNavigate={onNavigate}
onDisconnect={(reason) => {
Expand All @@ -205,6 +225,7 @@ function OpenedAppFrame({
app,
source,
slot,
hostActionId,
route,
fill,
onNavigate,
Expand All @@ -213,6 +234,7 @@ function OpenedAppFrame({
app: AppUiSummary
source: AppFrameSource
slot: AppUiSlot | undefined
hostActionId: string | undefined
route: string
fill: boolean | undefined
onNavigate: (route: string) => void
Expand All @@ -225,6 +247,7 @@ function OpenedAppFrame({
app={app}
source={source}
slot={slot}
hostActionId={hostActionId}
route={route}
fill={fill}
theme={ui?.theme ?? 'light'}
Expand Down
6 changes: 5 additions & 1 deletion web/src/features/AppUi/Components/AppFrameView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react'

import type { AppUiRendering } from '@/lib/AppUi/bridge.ts'
import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import { createRemoteUiStore, type RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts'
import {
bindAppUiFrame,
Expand All @@ -22,6 +23,7 @@ export default function AppFrameView({
app,
source,
slot,
hostActionId,
route,
fill,
theme,
Expand All @@ -47,7 +49,9 @@ export default function AppFrameView({
}))
// Keys match the manifest pattern, so the joined list changes exactly when the keys do.
const permissionScope = app.permissionKeys.join(' ')
const navigate = useEffectEvent(onNavigate)
const navigate = useEffectEvent((target: string) => {
if (isAppUiRouteAllowed(app, target, hostActionId)) onNavigate(target)
})
const dialog = useEffectEvent(onDialog)
const request = useEffectEvent(onApiRequest)
const revoke = useEffectEvent((reason: AppUiRevocation) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function AppHostActionDialog(props: AppHostActionDialogProps) {
app={state.app}
slot="proxyHostTab"
hostId={props.hostId}
hostActionId={props.actionId}
route={state.route}
onNavigate={handler.handleNavigate}
fill
Expand Down
10 changes: 7 additions & 3 deletions web/src/features/AppUi/Components/PooledAppFrameView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

import type { RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts'
import type { AppUiRemoteEventDetail } from '@/lib/AppUi/session.ts'
import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts'
import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx'
import type {
Expand Down Expand Up @@ -47,12 +48,15 @@ export default function PooledAppFrameView({
readonly onRetry: () => void
}) {
const { t, locale } = useTranslationStore()
const view = useRef<PooledFrameView>({ route: request.route, onNavigate })
const { app } = request
const handleNavigate = (target: string) => {
if (isAppUiRouteAllowed(app, target, request.hostActionId)) onNavigate(target)
}
const view = useRef<PooledFrameView>({ route: request.route, onNavigate: handleNavigate })
useLayoutEffect(() => {
view.current = { route: request.route, onNavigate }
view.current = { route: request.route, onNavigate: handleNavigate }
})
const [frame, setFrame] = useState<PooledFrame>()
const { app } = request
const opened = useRef(request)

// The view takes the frame opened for its request, or opens one, and closes it when it goes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react'

import { nativeText } from '@/lib/AppUi/native-presentation.ts'
import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts'
import { useAppUi } from '../AppUiProvider.tsx'
import type { AppHostActionDialogProps } from '../Types/app-host-table.types.ts'
Expand All @@ -18,7 +19,12 @@ export default function useAppHostActionDialogLogic({
const action = app?.hostActions.find((entry) => entry.id === actionId)
const [navigation, setNavigation] = useState<{ action: string; route: string }>()
// The app may navigate inside the dialog; a new action starts at its own route again.
const route = navigation?.action === actionId ? navigation.route : action?.route
const route =
app &&
navigation?.action === actionId &&
isAppUiRouteAllowed(app, navigation.route, actionId)
? navigation.route
: action?.route

return {
state: {
Expand Down
5 changes: 4 additions & 1 deletion web/src/features/AppUi/Hooks/useNativeAppUiLogic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'
import { callAppUi } from '@/lib/AppUi/client.ts'
import type { AppUiPayload, AppUiSummary } from '@/lib/AppUi/contract.ts'
import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import { useAppUi } from '../AppUiProvider.tsx'
import { openAppUiHandler } from '../middleware.ts'

Expand Down Expand Up @@ -94,7 +95,9 @@ export function useNativeAppUiLogic(app: AppUiSummary) {
return result.payload
}

return { state: { source, scope }, handler: { call } }
const pages =
source.data?.presentation.pages.filter(({ route }) => isAppUiRouteAllowed(app, route)) ?? []
return { state: { source, scope, pages }, handler: { call } }
}

export type NativeAppSession = Pick<ReturnType<typeof useNativeAppUiLogic>, 'handler'> & {
Expand Down
16 changes: 13 additions & 3 deletions web/src/features/AppUi/Hooks/usePrewarmAppHostAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react'

import { isAppUiRouteAllowed } from '@/lib/AppUi/page-access.ts'
import { supportsRemoteRendering } from '@/lib/AppUi/session.ts'
import { useAppUi } from '../AppUiProvider.tsx'
import type { AppHostTableAction } from '../Types/app-host-table.types.ts'
Expand All @@ -11,15 +12,24 @@ import type { AppHostTableAction } from '../Types/app-host-table.types.ts'
export default function usePrewarmAppHostAction() {
const ui = useAppUi()
return useCallback(
(hostId: string, action: Pick<AppHostTableAction, 'installationId' | 'route'>) => {
(hostId: string, action: Pick<AppHostTableAction, 'installationId' | 'actionId'>) => {
const app = ui?.apps.find((entry) => entry.installationId === action.installationId)
if (!ui?.sessionId || !app || !supportsRemoteRendering(app)) return
const entry = app?.hostActions.find(({ id }) => id === action.actionId)
if (
!ui?.sessionId ||
!app ||
!entry ||
!supportsRemoteRendering(app) ||
!isAppUiRouteAllowed(app, entry.route, entry.id)
)
return
ui.framePool.prewarm({
app,
sessionId: ui.sessionId,
slot: 'proxyHostTab',
hostId,
route: action.route,
hostActionId: entry.id,
route: entry.route,
})
},
[ui],
Expand Down
8 changes: 4 additions & 4 deletions web/src/features/AppUi/NativeAppUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default function NativeAppUi(props: NativeAppUiProps) {
function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) {
const { t, locale } = useTranslationStore()
const { state, handler } = useNativeAppUiLogic(app)
const { source, scope } = state
const activePage = source.data?.presentation.pages.find((page) => page.route === route)
const { source, scope, pages } = state
const activePage = pages.find((page) => page.route === route)
const session: NativeAppSession | undefined = source.data && {
scope,
handler,
Expand Down Expand Up @@ -61,7 +61,7 @@ function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) {
) : (
<>
<nav aria-label={app.name} className="mb-6 flex flex-wrap gap-2">
{source.data.presentation.pages.map((page) => (
{pages.map((page) => (
<button
key={page.route}
type="button"
Expand All @@ -76,7 +76,7 @@ function NativeAppContent({ app, route, onNavigate }: NativeAppUiProps) {
))}
</nav>
<div key={JSON.stringify(scope)}>
{source.data.presentation.pages.map((page) => (
{pages.map((page) => (
<div key={page.route} hidden={page.route !== route}>
{page.kind === 'form' ? (
<NativeAppForm
Expand Down
1 change: 1 addition & 0 deletions web/src/features/AppUi/Types/app-frame-view.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface AppFrameViewProps {
readonly app: AppUiSummary
readonly source: AppFrameSource
readonly slot: AppUiSlot | undefined
readonly hostActionId?: string | undefined
readonly route: string
readonly fill: boolean | undefined
readonly theme: 'light' | 'dark'
Expand Down
13 changes: 11 additions & 2 deletions web/src/features/AppUi/appFramePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface AppFrameRequest {
readonly sessionId: string
readonly slot: AppUiSlot | undefined
readonly hostId: string | undefined
readonly hostActionId?: string | undefined
readonly route: string
}

Expand Down Expand Up @@ -76,16 +77,24 @@ type Entry = PooledFrame & {
const opening: PooledFrameState = { phase: 'opening' }

/**
* One key per document: the session, the app generation, the slot, the host and the route it
* One key per document: the session, app generation, slot, host, action and route it
* starts on. A frame opened for one action never shows up in the dialog of another.
*/
export function appFrameKey({ sessionId, app, slot, hostId, route }: AppFrameRequest) {
export function appFrameKey({
sessionId,
app,
slot,
hostId,
hostActionId,
route,
}: AppFrameRequest) {
return JSON.stringify([
sessionId,
app.installationId,
app.generation,
slot ?? null,
hostId ?? null,
hostActionId ?? null,
route,
])
}
Expand Down
Loading