Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): show a deleted event's chip as a deleted event on desktop and phone (#8751)

gbirman6f5fa2e3afc6
diff --git a/apps/web/src/lib/core/component/AccessErrorViews/NotFound.tsx b/apps/web/src/lib/core/component/AccessErrorViews/NotFound.tsx
index d37defe98c..fad31fd0d2 100644
--- a/apps/web/src/lib/core/component/AccessErrorViews/NotFound.tsx
+++ b/apps/web/src/lib/core/component/AccessErrorViews/NotFound.tsx
@@ -2,15 +2,17 @@ import Question from '@phosphor-icons/core/regular/question.svg?component-solid'
/**
* @description This is the view for when a user tries to access an item that returns a 404 indicating it does not exist or it has been deleted.
+ * `message` names the item when it is not a file, such as a calendar event.
*/
-export default function NotFound() {
+export default function NotFound(props: { message?: string }) {
return (
<div class="flex flex-col items-center justify-center h-full space-y-4">
<div class="rounded-full">
<Question class="size-10" />
</div>
<p class="text-ink-muted">
- Whoops! It doesn't look like a file exists at this link.
+ {props.message ??
+ "Whoops! It doesn't look like a file exists at this link."}
</p>
<span class="text-accent">404</span>
</div>
diff --git a/apps/web/src/lib/core/component/DocumentPreview.test.tsx b/apps/web/src/lib/core/component/DocumentPreview.test.tsx
index 365c8b763a..1967e5f2f8 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.test.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.test.tsx
@@ -52,7 +52,9 @@ vi.mock('./AccessErrorViews/Unauthorized', () => ({
default: () => <p>You don't have access to this file</p>,
}));
vi.mock('./AccessErrorViews/NotFound', () => ({
- default: () => <p>Not found</p>,
+ default: (props: { message?: string }) => (
+ <p>{props.message ?? 'Not found'}</p>
+ ),
}));
// The actions own their calendar queries; the card only decides whether and
// for which event to show them.
@@ -173,6 +175,41 @@ describe('calendar mention preview card', () => {
expect(view.container.textContent).not.toContain('Pilates');
});
+ // The preview reports a deleted or cancelled meeting as missing; the card
+ // a click or tap shows must say so about an event, not a file.
+ it('says a deleted meeting is gone, on the card and the phone sheet', async () => {
+ mocks.item = {
+ id: 'mentioned-event',
+ type: 'calendar_event',
+ access: 'does_not_exist',
+ loading: false,
+ } satisfies PreviewItem;
+ renderCard();
+
+ expect(
+ screen.getByText('This event was deleted or cancelled.')
+ ).toBeTruthy();
+ expect(screen.queryByText('Not found')).toBeNull();
+ expect(screen.queryByRole('button', { name: 'Open' })).toBeNull();
+ cleanup();
+
+ render(() => (
+ <DocumentPreviewSheet
+ open
+ onOpenChange={vi.fn()}
+ documentInfo={{
+ id: 'mentioned-event',
+ type: 'calendar',
+ params: {},
+ isOpenable: true,
+ }}
+ />
+ ));
+ expect(
+ await screen.findByText('This event was deleted or cancelled.')
+ ).toBeTruthy();
+ });
+
it('opens description links like the event view does', () => {
mocks.item = calendarItem({
description:
diff --git a/apps/web/src/lib/core/component/DocumentPreview.tsx b/apps/web/src/lib/core/component/DocumentPreview.tsx
index 5bd6d26227..e3dcd51dce 100644
--- a/apps/web/src/lib/core/component/DocumentPreview.tsx
+++ b/apps/web/src/lib/core/component/DocumentPreview.tsx
@@ -1098,6 +1098,8 @@ export function DocumentPreviewContent(props: DocumentPreviewContentProps) {
<div class="text-sm p-4">
{noAccessItem().access === 'no_access' ? (
<Unauthorized />
+ ) : targetBlockType() === 'calendar' ? (
+ <NotFound message="This event was deleted or cancelled." />
) : (
<NotFound />
)}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
index 489a730a6c..cd6c7849ac 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/DocumentMention.tsx
@@ -675,12 +675,17 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
return lexicalWrapper?.isInteractable() ?? false;
});
- // Check if this is a recently created mention that we should show fallback for
- const isRecentMention = createMemo(() => {
- if (!props.createdAt) return false;
- const age = Date.now() - props.createdAt;
- return age < RECENT_MENTION_THRESHOLD_MS;
- });
+ // Check if this is a recently created mention that we should show fallback for.
+ // It stops being recent while mounted, so a chip for an event deleted in the
+ // meantime then reads and opens as deleted without a remount.
+ const recentForMs = props.createdAt
+ ? props.createdAt + RECENT_MENTION_THRESHOLD_MS - Date.now()
+ : 0;
+ const [isRecentMention, setIsRecentMention] = createSignal(recentForMs > 0);
+ if (recentForMs > 0) {
+ const timer = setTimeout(() => setIsRecentMention(false), recentForMs);
+ onCleanup(() => clearTimeout(timer));
+ }
const showEmbedOption = createMemo(() => {
if (!lexicalWrapper?.isInteractable()) return false;
@@ -745,18 +750,32 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
: undefined
);
+ // A just-created mention can briefly preview as missing; it still opens
+ // the calendar rather than reading as deleted.
+ const isDeletedCalendarEvent = () => {
+ const i = item();
+ return (
+ verifyBlockName(props.blockName) === 'calendar' &&
+ !i.loading &&
+ i.access === 'does_not_exist' &&
+ !isRecentMention()
+ );
+ };
+ const showsPreviewOnOpen = () =>
+ calendarOpen()?.kind === 'read_only' || isDeletedCalendarEvent();
+
const open = createCallback((e: MouseEvent | KeyboardEvent | null) => {
// The calendar is a singleton block: open it aimed at the viewer's own
// copy of the meeting. A meeting shared through the channel but absent
- // from the viewer's calendars has nothing to open, so its read-only
- // preview card is shown instead, as a sheet on touch devices.
+ // from the viewer's calendars, or one that is gone, has nothing to open,
+ // so its preview card is shown instead, as a sheet on touch devices.
+ if (showsPreviewOnOpen()) {
+ if (isTouchDevice()) setPreviewSheetOpen(true);
+ else setPreviewCardOpen(true);
+ return;
+ }
const target = calendarOpen();
- if (target) {
- if (target.kind === 'read_only') {
- if (isTouchDevice()) setPreviewSheetOpen(true);
- else setPreviewCardOpen(true);
- return;
- }
+ if (target?.kind === 'calendar') {
fireAndForget(
openCalendarEventSplit({
...target.target,
@@ -845,9 +864,10 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
e.stopPropagation();
const i = item();
if (
- !i.loading &&
- (i.access === 'access' ||
- shouldUseFallbackForRecentMention(i, isRecentMention()))
+ isDeletedCalendarEvent() ||
+ (!i.loading &&
+ (i.access === 'access' ||
+ shouldUseFallbackForRecentMention(i, isRecentMention())))
) {
open(e);
}
@@ -902,10 +922,7 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
{/* The sheet stays up once open, so a share the viewer adds or is
invited to meanwhile shows it is on their calendar in place. */}
<Show
- when={
- isTouchDevice() &&
- (calendarOpen()?.kind === 'read_only' || previewSheetOpen())
- }
+ when={isTouchDevice() && (showsPreviewOnOpen() || previewSheetOpen())}
>
<DocumentPreviewSheet
open={previewSheetOpen()}
@@ -916,7 +933,7 @@ function DocumentMentionInner(props: DocumentMentionDecoratorProps) {
<HoverCard
open={previewCardOpen()}
onOpenChange={setPreviewCardOpen}
- keepOpenOnTriggerPress={calendarOpen()?.kind === 'read_only'}
+ keepOpenOnTriggerPress={showsPreviewOnOpen()}
trigger={
<span class="relative">
<span
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.browser.e2e.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.browser.e2e.ts
new file mode 100644
index 0000000000..b2890bf6eb
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.browser.e2e.ts
@@ -0,0 +1,43 @@
+import { expect, test } from '@playwright/test';
+
+const fixture =
+ '/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.html';
+const gone = 'This event was deleted or cancelled.';
+
+test('clicking a deleted calendar mention keeps its card open', async ({
+ page,
+}) => {
+ await page.goto(fixture);
+ const chip = page.getByRole('link', { name: 'Deleted' });
+ await expect(chip).toBeVisible();
+
+ await chip.click();
+ await expect(page.getByText(gone, { exact: true })).toBeVisible();
+ await expect(page.getByText(/file exists/)).toBeHidden();
+
+ await page.keyboard.press('Escape');
+ await expect(page.getByText(gone, { exact: true })).toBeHidden();
+});
+
+test.describe('on a phone', () => {
+ test.use({
+ viewport: { width: 390, height: 844 },
+ hasTouch: true,
+ isMobile: true,
+ });
+
+ test('tapping a deleted calendar mention opens its card as a sheet', async ({
+ page,
+ }) => {
+ await page.goto(fixture);
+ const chip = page.getByRole('link', { name: 'Deleted' });
+ await expect(chip).toBeVisible();
+
+ // The hover card marks its trigger aria-disabled on touch, where it shows
+ // nothing; a real tap still reaches the chip.
+ await chip.tap({ force: true });
+ const sheet = page.getByRole('dialog', { name: 'Preview' });
+ await expect(sheet).toBeVisible();
+ await expect(sheet.getByText(gone, { exact: true })).toBeVisible();
+ });
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.html b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.html
new file mode 100644
index 0000000000..f39843d9b1
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<html lang="en">
+ <head><meta charset="UTF-8"><title>Calendar mention fixture</title></head>
+ <body><div id="root"></div><script type="module" src="./calendar-mention.tsx"></script></body>
+</html>
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.tsx
new file mode 100644
index 0000000000..ce7a7fd91a
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/calendar-mention.tsx
@@ -0,0 +1,58 @@
+import '@app/index.css';
+import { AnalyticsContextProvider } from '@app/lib/analytics/analytics-context';
+import { PosthogProvider } from '@app/lib/analytics/posthog';
+import { queryClient } from '@queries/client';
+import { previewKeys } from '@queries/preview/keys';
+import type { PreviewItem } from '@queries/preview/types';
+import { MemoryRouter, Route } from '@solidjs/router';
+import { QueryClientProvider } from '@tanstack/solid-query';
+import { render } from 'solid-js/web';
+import { channelTheme } from '../../../theme';
+import { StaticMarkdownContext } from '../../core/StaticMarkdown';
+import { DocumentMention } from '../DocumentMention';
+
+const id = '01a16d55-0000-7000-8000-000000000001';
+
+// The preview API answers does_not_exist for a meeting deleted or cancelled
+// since it was mentioned.
+queryClient.setQueryData(previewKeys.item(id).queryKey, {
+ id,
+ type: 'calendar_event',
+ access: 'does_not_exist',
+ loading: false,
+} satisfies PreviewItem);
+
+function Fixture() {
+ return (
+ <main class="p-4 text-ink bg-page">
+ <p>
+ Shared earlier:{' '}
+ <DocumentMention
+ key="deleted-event"
+ theme={channelTheme}
+ documentId={id}
+ documentName="Planning"
+ blockName="calendar"
+ createdAt={Date.now() - 10 * 60 * 1000}
+ />
+ </p>
+ </main>
+ );
+}
+
+render(
+ () => (
+ <AnalyticsContextProvider>
+ <PosthogProvider>
+ <QueryClientProvider client={queryClient}>
+ <StaticMarkdownContext theme={channelTheme}>
+ <MemoryRouter>
+ <Route path="*" component={Fixture} />
+ </MemoryRouter>
+ </StaticMarkdownContext>
+ </QueryClientProvider>
+ </PosthogProvider>
+ </AnalyticsContextProvider>
+ ),
+ document.getElementById('root')!
+);
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/playwright.config.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/playwright.config.ts
index c887b6f9e9..800a60471e 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/playwright.config.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/browser-test/playwright.config.ts
@@ -8,7 +8,7 @@ const port = process.env.ROUTINE_MENTION_TEST_PORT ?? '3049';
export default defineConfig({
testDir: '.',
- testMatch: 'routine-mention.browser.e2e.ts',
+ testMatch: '*.browser.e2e.ts',
workers: 1,
timeout: 60_000,
use: {
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 39c5bf0094..e787f8f2c5 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -726,7 +726,9 @@ it by posting the chip. It asks whether to share with the channel, and a yes in
writes the same channel grant. Private and confidential events are never shared this way.
Every calendar mention's hover card shows the schedule, location, organizer and attendee
count, plus the first lines of the event description (its links open), and no last-updated
-byline. When the mention names someone else's copy of a meeting the viewer also holds (a shared
+byline. A mention of a meeting that was deleted or cancelled reads `Deleted`; clicking it (a tap
+on a phone, which opens a sheet) shows `This event was deleted or cancelled.`, like a shared
+event's card, instead of doing nothing. When the mention names someone else's copy of a meeting the viewer also holds (a shared
event they added or were invited to, or a meeting someone else mentioned), the card says how:
`Your copy is on your calendar` for a snapshot, `You're invited · on your calendar` when the
viewer's copy is a guest's, and `On your calendar` otherwise (the viewer organizes it, or it sits