Skip to content
Merged
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
18 changes: 18 additions & 0 deletions .changeset/34589-inbox-right-panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(app-shell): the notification bell opens a full-height panel on the right, with pending approvals on top and decidable in place

Clause-②: yes (widening) — two new locale keys in the `notifications` namespace of every `@object-ui/i18n` pack (`needsYou`, `viewApprovalDetails`); nothing that worked before is refused
Metadata-protocol: none

The bell in the console header (and the `global:notifications` page block) used to open a 384 px popover whose lists stopped at 320 px, about three rows. It now opens a panel the full height of the window on the right, 440 px wide, and the lists take all the height the header and tabs leave.

- **The page stays usable.** The panel has no overlay, and a click in the page does not close it. Opening a notification takes the page to its record while the panel stays open on the next one. The panel closes from its close button, Escape or the bell, and it gives way when the record drawer opens, so the two never stack on the right.
- **Approvals come first.** The Notifications tab opens with "Needs your action": the pending approval requests the bell counts, each with its approve and reject buttons and "View details". The buttons are the request's own declared actions (`approval_approve`, `approval_reject` at `list_item`), run through the same declared-actions bar the request's record page uses. So a viewer sees a button only when its `visible` rule passes, a request that needs decision fields collects them in the action's dialog, and the request sent is the declared one. A decided request leaves the list and the badge at once, and the approvals are read again. The Approvals tab lists the same requests.
- **"Mark read" is an icon** that shows when a row is hovered or focused, instead of a column on every row. "Mark all read" and "View all notifications" stay.
- **On a phone the panel fills the screen**, and following a link closes it.

The notification data, its grouping and the three tabs are unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ vi.mock('@object-ui/components', async (importOriginal) => {
Avatar: Pass,
AvatarImage: () => null,
AvatarFallback: Pass,
Popover: Pass,
PopoverTrigger: Pass,
PopoverContent: Pass,
Sheet: Pass,
SheetTrigger: Pass,
SheetContent: Pass,
SheetTitle: Pass,
Tabs: Pass,
TabsList: Pass,
TabsTrigger: ({ children }: any) => <button type="button">{children}</button>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ describe('the approval requests behind the count (objectui#12602)', () => {
// The count is the answer's `total`, the route's own count — not a fold
// of the page (objectui#13027). This fixture's route totals its 3 rows.
expect(result.current.pendingApprovalsCount).toBe(3);
// `row` is the served row itself — the inbox panel's dispatch record for
// the request's declared actions (objectstack#34589).
expect(result.current.pendingApprovals).toEqual([
{ id: 'a1', processName: 'discount', processLabel: 'Discount approval', recordTitle: 'QUO-0007', createdAt: '2026-10-16T01:00:00Z' },
{ id: 'a2', processName: 'contract', processLabel: undefined, recordTitle: undefined, createdAt: undefined },
{ id: 'a1', processName: 'discount', processLabel: 'Discount approval', recordTitle: 'QUO-0007', createdAt: '2026-10-16T01:00:00Z', row: rows[0] },
{ id: 'a2', processName: 'contract', processLabel: undefined, recordTitle: undefined, createdAt: undefined, row: rows[2] },
]);
});

Expand Down
20 changes: 20 additions & 0 deletions ui/packages/app-shell/src/hooks/sharedUserFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,15 @@ export interface PendingApprovalRequest {
/** The flow's machine name, as served. */
processName?: string;
createdAt?: string;
/**
* The request row as the approvals list served it, carrying the
* server-computed `viewer` block (`can_act`, `can_override`). It is the
* dispatch record the inbox panel hands `DeclaredActionsBar`, so an inline
* Approve / Reject runs the request's own declared action, gated by its own
* `visible` predicate, and resolves `{id}` from this row (objectstack#34589).
* Optional so a surface that only lists titles builds the shape without it.
*/
row?: Record<string, unknown>;
}

/**
Expand Down Expand Up @@ -1019,6 +1028,7 @@ export function useSharedPendingApprovalRequests(): SharedFeedSnapshot<{
recordTitle: str(row.record_title),
processName: str(row.process_name),
createdAt: str(row.created_at),
row,
});
}
return { requests, total };
Expand Down Expand Up @@ -1615,6 +1625,16 @@ export function notifyUserFeedPushed(feed: 'inbox' | 'approvals'): void {
(feed === 'inbox' ? inboxFeed : approvalsFeed).pushedChange();
}

/**
* Read the pending approvals once, now: a decision taken in this tab changed
* them, so the bell badge and every list cut from the feed must not wait for
* the next poll to drop the decided request (objectstack#34589). Same refresh
* {@link notifyUserFeedPushed} runs for a pushed change. Package-internal.
*/
export function refreshSharedPendingApprovals(): void {
approvalsFeed.pushedChange();
}

/**
* Test seam: drop every shared feed's cached value, key and in-flight state so
* cases do not inherit each other's reads. Not part of the public surface.
Expand Down
23 changes: 20 additions & 3 deletions ui/packages/app-shell/src/hooks/useInboxBell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@
* One hook, two consumers — the two surfaces have no representable state in
* which they disagree, because there is no second read and no second overlay.
*
* NOTHING is fetched here: `useSharedInboxFeed` / `useSharedPendingApprovalsCount`
* NOTHING is fetched here: `useSharedInboxFeed` / `useSharedPendingApprovalRequests`
* own the polling, its cadence, its hidden-tab throttle and its failure backoff.
* This hook adds only the optimistic read overlay and the mark-read writes.
*
* @module
*/
import { useCallback, useMemo, useState } from 'react';
import { bearerAuthHeaders } from '../utils/authToken.js';
import { useSharedInboxFeed, useSharedPendingApprovalsCount, type SharedFeedStatus } from './sharedUserFeeds.js';
import {
refreshSharedPendingApprovals,
useSharedInboxFeed,
useSharedPendingApprovalRequests,
type PendingApprovalRequest,
type SharedFeedStatus,
} from './sharedUserFeeds.js';
import { useInboxArrivalNotifier } from './useInboxArrivalNotifier.js';
import type { InboxNotification } from '../layout/inboxGrouping.js';

Expand All @@ -54,6 +60,13 @@ export interface InboxBell {
unreadCount: number;
/** The badge's second addend — pending approvals waiting on this user. */
pendingApprovalsCount: number;
/**
* The first page of those requests, from the same one read as the count —
* the rows the inbox panel pins under "Needs your action" (objectstack#34589).
*/
pendingApprovals: PendingApprovalRequest[];
/** Re-read the approvals now — after a decision taken from the panel. */
refreshPendingApprovals: () => void;
markAllRead: () => Promise<void>;
markRead: (id: string) => Promise<void>;
markManyRead: (ids: string[]) => Promise<void>;
Expand Down Expand Up @@ -95,7 +108,9 @@ export function useInboxBell(): InboxBell {
* Shared with Home's To-do card (#4197): one polled request serves both, so
* the badge and the card can no longer disagree.
*/
const pendingApprovalsCount = useSharedPendingApprovalsCount();
const { value: approvalPage } = useSharedPendingApprovalRequests();
const pendingApprovalsCount = approvalPage.total;
const pendingApprovals = approvalPage.requests;

const unreadCount = notifications.reduce((n, x) => n + (x.is_read ? 0 : 1), 0);

Expand Down Expand Up @@ -182,6 +197,8 @@ export function useInboxBell(): InboxBell {
status,
unreadCount,
pendingApprovalsCount,
pendingApprovals,
refreshPendingApprovals: refreshSharedPendingApprovals,
markAllRead,
markRead,
markManyRead,
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/app-shell/src/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ export function AppHeader({
notifications,
unreadCount,
pendingApprovalsCount,
pendingApprovals,
refreshPendingApprovals,
markAllRead,
markRead: markNotificationRead,
markManyRead,
Expand Down Expand Up @@ -1138,6 +1140,8 @@ export function AppHeader({
onMarkAllRead={markAllRead}
onMarkRead={markNotificationRead}
onMarkManyRead={markManyRead}
pendingApprovals={pendingApprovals}
onApprovalDecided={refreshPendingApprovals}
/>
</span>

Expand Down
90 changes: 90 additions & 0 deletions ui/packages/app-shell/src/layout/InboxApprovalItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* One pending approval request in the inbox panel, decidable in place
* (objectstack#34589).
*
* The decision levers are NOT drawn here: they are the request's own declared
* actions at `list_item` (`approval_approve`, `approval_reject` on
* `sys_approval_request`), run through `DeclaredActionsBar` — the governed
* path the record page and the decision panel already run them through. So
* whether a viewer sees a lever is the action's own `visible` predicate over
* the row's server-computed `viewer` block, a request that asks for decision
* outputs collects them in the action's param dialog, and the request a click
* sends is the declared one. No third approvals client is written here.
*
* "View details" opens the request in the Approvals inbox, the target Home's
* "My work" approvals row opens.
*
* @module
*/

import { useObjectTranslation, useDisplayLocale } from '@object-ui/i18n';
import type { PendingApprovalRequest } from '../hooks/sharedUserFeeds.js';
import { DeclaredActionsBar } from '../views/DeclaredActionsBar.js';
import { timeAgo } from '../utils/relativeTime.js';

/** The object whose declared actions decide a request. */
const APPROVAL_REQUEST_OBJECT = 'sys_approval_request';

/** The declared location of the inline levers (approve / reject). */
const INLINE_DECISION_LOCATION = 'list_item';

/** The phone tap floor, as the rest of the panel spells it. */
const PHONE_TAP = 'max-md:min-h-11';

/** The flow's label and the record's title, as Home's approvals row names it. */
export function approvalRequestTitle(r: PendingApprovalRequest): string {
return [r.processLabel || r.processName, r.recordTitle].filter(Boolean).join(' · ') || r.id;
}

export interface InboxApprovalItemProps {
request: PendingApprovalRequest;
/** Open the request in the Approvals inbox. */
onOpen: (request: PendingApprovalRequest) => void;
/** A declared action on this request succeeded. */
onDecided: (request: PendingApprovalRequest) => void;
}

export function InboxApprovalItem({ request, onOpen, onDecided }: InboxApprovalItemProps) {
const { t } = useObjectTranslation();
const displayLocale = useDisplayLocale();
return (
<div data-testid="inbox-approval-item" className="px-3 py-2.5">
<div className="flex items-start gap-2">
<span className="mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-amber-500" aria-hidden />
<div className="min-w-0 flex-1">
<div className="text-sm font-medium leading-tight truncate">{approvalRequestTitle(request)}</div>
{request.createdAt && (
<div className="text-[10px] text-muted-foreground mt-1">
{timeAgo(request.createdAt, displayLocale)}
</div>
)}
<div className="mt-2 flex flex-wrap items-center gap-2">
{request.row && (
<DeclaredActionsBar
objectName={APPROVAL_REQUEST_OBJECT}
record={request.row}
location={INLINE_DECISION_LOCATION}
onDone={() => onDecided(request)}
/>
)}
<button
type="button"
onClick={() => onOpen(request)}
className={`text-xs text-primary hover:underline ${PHONE_TAP} max-md:px-2`}
>
{t('notifications.viewApprovalDetails', { defaultValue: 'View details' })}
</button>
</div>
</div>
</div>
</div>
);
}
Loading
Loading