@burdenoff/microfe-calendar 2026.626.2 → 2026.704.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/EventBlock.js +6 -5
- package/dist/components/EventBlock.js.map +1 -1
- package/dist/components/TaskEventDetail.js +107 -0
- package/dist/components/TaskEventDetail.js.map +1 -0
- package/dist/graphql/calendarDocuments.js +50 -24
- package/dist/graphql/calendarDocuments.js.map +1 -1
- package/dist/hooks/useEvents.js +149 -46
- package/dist/hooks/useEvents.js.map +1 -1
- package/dist/hooks/useOpenEvent.js +9 -5
- package/dist/hooks/useOpenEvent.js.map +1 -1
- package/dist/pages/CalendarPage.js +192 -141
- package/dist/pages/CalendarPage.js.map +1 -1
- package/dist/pages/ResourcesPage.js.map +1 -1
- package/dist/providers/CalendarProvider.js +12 -10
- package/dist/providers/CalendarProvider.js.map +1 -1
- package/dist/store/calendarStore.js +3 -0
- package/dist/store/calendarStore.js.map +1 -1
- package/package.json +1 -1
package/dist/hooks/useEvents.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useCalendar as e } from "../providers/CalendarProvider.js";
|
|
2
2
|
import { useGetCalendarsQuery as t } from "../generated/wspace-operations.js";
|
|
3
3
|
import { useCalendarStore as n } from "../store/calendarStore.js";
|
|
4
|
-
import { EVENTS_IN_RANGE_QUERY as r,
|
|
5
|
-
import { useEffect as
|
|
6
|
-
import { useApolloClient as
|
|
4
|
+
import { EVENTS_IN_RANGE_QUERY as r, PLANMAGNET_MILESTONES_QUERY as i, PLANMAGNET_WORK_ITEMS_QUERY as a, SCHEDULED_JOBS_QUERY as o } from "../graphql/calendarDocuments.js";
|
|
5
|
+
import { useEffect as s, useMemo as c, useState as l } from "react";
|
|
6
|
+
import { useApolloClient as u } from "@apollo/client/react";
|
|
7
7
|
//#region src/hooks/useEvents.ts
|
|
8
|
-
|
|
8
|
+
var d = 300;
|
|
9
|
+
function f(e) {
|
|
9
10
|
return e ? e.reduce((e, t, n) => {
|
|
10
11
|
let r = t.url ?? t.fileUrl ?? "", i = t.name ?? t.fileName ?? `Attachment ${n + 1}`;
|
|
11
12
|
return !r && !t.fileId || e.push({
|
|
@@ -18,7 +19,7 @@ function l(e) {
|
|
|
18
19
|
}), e;
|
|
19
20
|
}, []) : [];
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function p(e) {
|
|
22
23
|
return {
|
|
23
24
|
id: e.id,
|
|
24
25
|
calendarId: e.calendarId,
|
|
@@ -64,7 +65,7 @@ function u(e) {
|
|
|
64
65
|
status: t.status ?? "PENDING",
|
|
65
66
|
createdAt: new Date(e.createdAt)
|
|
66
67
|
})) ?? [],
|
|
67
|
-
attachments:
|
|
68
|
+
attachments: f(e.attachments),
|
|
68
69
|
videoCallLink: e.onlineMeetingUrl ?? void 0,
|
|
69
70
|
onlineMeetingProvider: e.onlineMeetingProvider ?? void 0,
|
|
70
71
|
maxAttendees: e.maxAttendees ?? void 0,
|
|
@@ -77,7 +78,7 @@ function u(e) {
|
|
|
77
78
|
updatedAt: new Date(e.updatedAt)
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
|
-
function
|
|
81
|
+
function m(e) {
|
|
81
82
|
let t = e.nextExecutionAt ?? e.scheduledAt ?? e.lastExecutionAt;
|
|
82
83
|
if (!t) return null;
|
|
83
84
|
let n = new Date(t), r = new Date(n.getTime() + 1800 * 1e3), i = e.status === "CANCELLED" || e.status === "FAILED" || e.status === "DISABLED" ? "CANCELLED" : e.status === "PAUSED" ? "TENTATIVE" : "CONFIRMED";
|
|
@@ -108,8 +109,79 @@ function d(e) {
|
|
|
108
109
|
updatedAt: new Date(e.updatedAt)
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
+
var h = new Set(["DONE", "CANCELLED"]), g = new Set(["COMPLETED", "CANCELLED"]);
|
|
113
|
+
function _(e) {
|
|
114
|
+
if (!e) return null;
|
|
115
|
+
let t = /^(\d{4})-(\d{2})-(\d{2})/.exec(e);
|
|
116
|
+
if (!t) {
|
|
117
|
+
let t = new Date(e);
|
|
118
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
119
|
+
}
|
|
120
|
+
return new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3]));
|
|
121
|
+
}
|
|
122
|
+
function v(e, t) {
|
|
123
|
+
let n = _(e.dueDate);
|
|
124
|
+
return !n || e.status && h.has(e.status) ? null : {
|
|
125
|
+
id: `task-${e.id}`,
|
|
126
|
+
calendarId: "__tasks__",
|
|
127
|
+
calendarName: "Tasks",
|
|
128
|
+
calendarColor: "var(--color-accent-blue)",
|
|
129
|
+
title: e.title,
|
|
130
|
+
startTime: n,
|
|
131
|
+
endTime: new Date(n.getTime()),
|
|
132
|
+
isAllDay: !0,
|
|
133
|
+
privacy: "PRIVATE",
|
|
134
|
+
status: "CONFIRMED",
|
|
135
|
+
eventType: "TASK",
|
|
136
|
+
organizerId: e.assigneeId ?? "planmagnet",
|
|
137
|
+
tags: [],
|
|
138
|
+
metadata: {
|
|
139
|
+
source: "planmagnet",
|
|
140
|
+
entityType: "workItem",
|
|
141
|
+
workItemId: e.id,
|
|
142
|
+
key: e.key ?? void 0,
|
|
143
|
+
status: e.status ?? void 0,
|
|
144
|
+
priority: e.priority ?? void 0,
|
|
145
|
+
assigneeId: e.assigneeId ?? void 0
|
|
146
|
+
},
|
|
147
|
+
sourceKind: "task",
|
|
148
|
+
deepLink: `${t}?item=${encodeURIComponent(e.id)}`,
|
|
149
|
+
createdAt: n,
|
|
150
|
+
updatedAt: n
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function y(e, t) {
|
|
154
|
+
let n = _(e.dueDate);
|
|
155
|
+
return !n || e.status && g.has(e.status) ? null : {
|
|
156
|
+
id: `milestone-${e.id}`,
|
|
157
|
+
calendarId: "__milestones__",
|
|
158
|
+
calendarName: "Milestones",
|
|
159
|
+
calendarColor: "var(--color-accent-purple)",
|
|
160
|
+
title: e.name,
|
|
161
|
+
startTime: n,
|
|
162
|
+
endTime: new Date(n.getTime()),
|
|
163
|
+
isAllDay: !0,
|
|
164
|
+
privacy: "PRIVATE",
|
|
165
|
+
status: "CONFIRMED",
|
|
166
|
+
eventType: "MILESTONE",
|
|
167
|
+
organizerId: "planmagnet",
|
|
168
|
+
tags: [],
|
|
169
|
+
metadata: {
|
|
170
|
+
source: "planmagnet",
|
|
171
|
+
entityType: "milestone",
|
|
172
|
+
milestoneId: e.id,
|
|
173
|
+
status: e.status ?? void 0
|
|
174
|
+
},
|
|
175
|
+
sourceKind: "milestone",
|
|
176
|
+
deepLink: t,
|
|
177
|
+
createdAt: n,
|
|
178
|
+
updatedAt: n
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function b(e, t) {
|
|
112
182
|
return e.filter((e) => {
|
|
183
|
+
if (e.sourceKind === "task") return t.showTasks !== !1;
|
|
184
|
+
if (e.sourceKind === "milestone") return t.showMilestones !== !1;
|
|
113
185
|
if (t.calendarIds?.length && !t.calendarIds.includes(e.calendarId) || t.status?.length && !t.status.includes(e.status) || t.privacy?.length && !t.privacy.includes(e.privacy)) return !1;
|
|
114
186
|
if (t.attendeeIds?.length) {
|
|
115
187
|
let n = e.attendees?.flatMap((e) => e.userId ? [e.userId] : []) ?? [];
|
|
@@ -129,77 +201,108 @@ function f(e, t) {
|
|
|
129
201
|
return !0;
|
|
130
202
|
});
|
|
131
203
|
}
|
|
132
|
-
function
|
|
133
|
-
let
|
|
204
|
+
function x({ startDate: f, endDate: h, skip: g = !1 }) {
|
|
205
|
+
let _ = u(), { workspaceId: x, taskOverlay: S } = e(), C = n((e) => e.visibleCalendars), w = n((e) => e.eventFilter), { data: T, loading: E, refetch: D } = t({
|
|
134
206
|
variables: { pagination: { limit: 50 } },
|
|
135
|
-
skip:
|
|
207
|
+
skip: g,
|
|
136
208
|
fetchPolicy: "cache-and-network"
|
|
137
|
-
}), [
|
|
138
|
-
let e =
|
|
139
|
-
return (
|
|
209
|
+
}), [O, k] = l([]), [A, j] = l(!1), [M, N] = l(null), [P, F] = l(0), I = c(() => T?.calendars?.calendars ?? [], [T?.calendars?.calendars]), L = c(() => {
|
|
210
|
+
let e = I.map((e) => e.id), t = C.size > 0 ? Array.from(C) : e;
|
|
211
|
+
return (w.calendarIds?.length ? w.calendarIds : t).filter((t) => e.includes(t));
|
|
140
212
|
}, [
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
213
|
+
I,
|
|
214
|
+
w.calendarIds,
|
|
215
|
+
C
|
|
144
216
|
]);
|
|
145
|
-
return
|
|
217
|
+
return s(() => {
|
|
146
218
|
let e = !1;
|
|
147
219
|
return (async () => {
|
|
148
|
-
if (!(
|
|
149
|
-
|
|
220
|
+
if (!(g || E)) {
|
|
221
|
+
j(!0), N(null);
|
|
150
222
|
try {
|
|
151
|
-
let t = await Promise.allSettled(
|
|
223
|
+
let t = await Promise.allSettled(L.map((e) => _.query({
|
|
152
224
|
query: r,
|
|
153
225
|
variables: {
|
|
154
226
|
calendarId: e,
|
|
155
|
-
startDate:
|
|
156
|
-
endDate:
|
|
227
|
+
startDate: f.toISOString(),
|
|
228
|
+
endDate: h.toISOString()
|
|
157
229
|
},
|
|
158
230
|
fetchPolicy: "network-only"
|
|
159
231
|
}))), n = t.some((e) => e.status === "fulfilled");
|
|
160
|
-
if (
|
|
232
|
+
if (L.length > 0 && !n) {
|
|
161
233
|
let e = t.find((e) => e.status === "rejected")?.reason;
|
|
162
234
|
throw e instanceof Error ? e : /* @__PURE__ */ Error("Failed to load events");
|
|
163
235
|
}
|
|
164
|
-
let
|
|
165
|
-
query:
|
|
236
|
+
let s = t.flatMap((e) => e.status === "fulfilled" ? e.value.data?.eventsInRange ?? [] : []), c = ((x ? await _.query({
|
|
237
|
+
query: o,
|
|
166
238
|
variables: {
|
|
167
|
-
workspaceId:
|
|
168
|
-
nextExecutionAfter:
|
|
169
|
-
nextExecutionBefore:
|
|
239
|
+
workspaceId: x,
|
|
240
|
+
nextExecutionAfter: f.toISOString(),
|
|
241
|
+
nextExecutionBefore: h.toISOString()
|
|
170
242
|
},
|
|
171
243
|
fetchPolicy: "network-only"
|
|
172
|
-
}).catch(() => null) : null)?.data?.scheduledJobs?.jobs ?? []).map(
|
|
173
|
-
|
|
244
|
+
}).catch(() => null) : null)?.data?.scheduledJobs?.jobs ?? []).map(m).filter((e) => !!e), l = S?.tasksPath, u = [];
|
|
245
|
+
if (l && x) {
|
|
246
|
+
let [e, t] = await Promise.all([_.query({
|
|
247
|
+
query: a,
|
|
248
|
+
variables: {
|
|
249
|
+
workspaceId: x,
|
|
250
|
+
pagination: { first: d }
|
|
251
|
+
},
|
|
252
|
+
fetchPolicy: "network-only"
|
|
253
|
+
}).catch(() => null), _.query({
|
|
254
|
+
query: i,
|
|
255
|
+
variables: {
|
|
256
|
+
workspaceId: x,
|
|
257
|
+
pagination: { first: d }
|
|
258
|
+
},
|
|
259
|
+
fetchPolicy: "network-only"
|
|
260
|
+
}).catch(() => null)]), n = (e) => e.startTime.getTime() >= f.getTime() && e.startTime.getTime() <= h.getTime();
|
|
261
|
+
for (let t of e?.data?.planmagnetWorkItems?.items ?? []) {
|
|
262
|
+
let e = v(t, l);
|
|
263
|
+
e && n(e) && u.push(e);
|
|
264
|
+
}
|
|
265
|
+
for (let e of t?.data?.planmagnetMilestones?.items ?? []) {
|
|
266
|
+
let t = y(e, l);
|
|
267
|
+
t && n(t) && u.push(t);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
let g = b([
|
|
271
|
+
...s.map(p),
|
|
272
|
+
...c,
|
|
273
|
+
...u
|
|
274
|
+
].sort((e, t) => e.startTime.getTime() - t.startTime.getTime()), w);
|
|
275
|
+
e || k(g);
|
|
174
276
|
} catch (t) {
|
|
175
|
-
e || (
|
|
277
|
+
e || (N(t instanceof Error ? t.message : "Failed to load events"), k([]));
|
|
176
278
|
} finally {
|
|
177
|
-
e ||
|
|
279
|
+
e || j(!1);
|
|
178
280
|
}
|
|
179
281
|
}
|
|
180
282
|
})(), () => {
|
|
181
283
|
e = !0;
|
|
182
284
|
};
|
|
183
285
|
}, [
|
|
184
|
-
|
|
185
|
-
|
|
286
|
+
L,
|
|
287
|
+
E,
|
|
288
|
+
_,
|
|
186
289
|
h,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
290
|
+
w,
|
|
291
|
+
P,
|
|
292
|
+
g,
|
|
293
|
+
f,
|
|
294
|
+
x,
|
|
295
|
+
S?.tasksPath
|
|
193
296
|
]), {
|
|
194
|
-
events:
|
|
195
|
-
isLoading:
|
|
196
|
-
error:
|
|
297
|
+
events: O,
|
|
298
|
+
isLoading: A || E,
|
|
299
|
+
error: M,
|
|
197
300
|
refetch: async () => {
|
|
198
|
-
await
|
|
301
|
+
await D().catch(() => {}), F((e) => e + 1);
|
|
199
302
|
}
|
|
200
303
|
};
|
|
201
304
|
}
|
|
202
305
|
//#endregion
|
|
203
|
-
export {
|
|
306
|
+
export { x as useEvents };
|
|
204
307
|
|
|
205
308
|
//# sourceMappingURL=useEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvents.js","names":[],"sources":["../../src/hooks/useEvents.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useGetCalendarsQuery } from '../generated/wspace-operations';\nimport { useCalendar } from '../providers/CalendarProvider';\nimport { useCalendarStore } from '../store/calendarStore';\nimport type {\n CalendarEvent,\n CalendarFilter,\n EventAttachment,\n EventStatus,\n EventPrivacy,\n} from '../types';\nimport { EVENTS_IN_RANGE_QUERY, SCHEDULED_JOBS_QUERY } from '../graphql/calendarDocuments';\n\ninterface UseEventsOptions {\n startDate: Date;\n endDate: Date;\n skip?: boolean;\n}\n\ninterface RawCalendarEvent {\n id: string;\n calendarId: string;\n workspaceId: string;\n title: string;\n description?: string | null;\n location?: string | null;\n locationAddress?: string | null;\n locationType?: string | null;\n locationUrl?: string | null;\n startTime: string;\n endTime: string;\n allDay: boolean;\n timezone?: string | null;\n status?: string | null;\n visibility?: string | null;\n eventType?: string | null;\n isRecurring?: boolean | null;\n rrule?: string | null;\n tags?: string[] | null;\n maxAttendees?: number | null;\n currentAttendeeCount?: number | null;\n checkInEnabled?: boolean | null;\n onlineMeetingUrl?: string | null;\n onlineMeetingProvider?: string | null;\n metadata?: Record<string, unknown> | null;\n createdBy: string;\n createdAt: string;\n updatedAt: string;\n calendar?: {\n id: string;\n name: string;\n color?: string | null;\n } | null;\n attendees?: Array<{\n userId?: string | null;\n email?: string | null;\n name?: string | null;\n rsvpStatus: string;\n isOptional: boolean;\n }> | null;\n reminders?: Array<{\n id: string;\n minutesBefore: number;\n channel: string;\n }> | null;\n resourceBookings?: Array<{\n id: string;\n resourceId: string;\n startTime: string;\n endTime: string;\n status: string;\n notes?: string | null;\n resource?: {\n id: string;\n name: string;\n resourceType?: string | null;\n location?: string | null;\n capacity?: number | null;\n } | null;\n }> | null;\n attachments?: Array<{\n id?: string | null;\n fileId?: string | null;\n name?: string | null;\n fileName?: string | null;\n url?: string | null;\n fileUrl?: string | null;\n size?: number | null;\n mimeType?: string | null;\n }> | null;\n}\n\ninterface RawScheduledJob {\n id: string;\n name?: string | null;\n description?: string | null;\n scheduleType: string;\n status: string;\n priority: string;\n scheduledAt?: string | null;\n nextExecutionAt?: string | null;\n lastExecutionAt?: string | null;\n timezone?: string | null;\n tags?: string[] | null;\n actionId?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n}\n\nfunction normalizeAttachments(rawAttachments: RawCalendarEvent['attachments']): EventAttachment[] {\n if (!rawAttachments) return [];\n\n return rawAttachments.reduce<EventAttachment[]>((attachments, attachment, index) => {\n const url = attachment.url ?? attachment.fileUrl ?? '';\n const name = attachment.name ?? attachment.fileName ?? `Attachment ${index + 1}`;\n\n if (!url && !attachment.fileId) {\n return attachments;\n }\n\n attachments.push({\n id: attachment.id ?? attachment.fileId ?? `${name}-${index}`,\n fileId: attachment.fileId ?? undefined,\n name,\n url,\n size: attachment.size ?? 0,\n mimeType: attachment.mimeType ?? 'application/octet-stream',\n });\n\n return attachments;\n }, []);\n}\n\nfunction parseCalendarEvent(raw: RawCalendarEvent): CalendarEvent {\n return {\n id: raw.id,\n calendarId: raw.calendarId,\n calendarName: raw.calendar?.name ?? undefined,\n calendarColor: raw.calendar?.color ?? undefined,\n title: raw.title,\n description: raw.description ?? undefined,\n location: raw.location ?? undefined,\n locationAddress: raw.locationAddress ?? undefined,\n locationType: (raw.locationType as CalendarEvent['locationType']) ?? undefined,\n locationUrl: raw.locationUrl ?? undefined,\n startTime: new Date(raw.startTime),\n endTime: new Date(raw.endTime),\n isAllDay: raw.allDay,\n privacy: ((raw.visibility as EventPrivacy | null) ?? 'PUBLIC') as EventPrivacy,\n status: ((raw.status as EventStatus | null) ?? 'CONFIRMED') as EventStatus,\n eventType: raw.eventType as CalendarEvent['eventType'],\n isRecurring: raw.isRecurring ?? false,\n rrule: raw.rrule ?? undefined,\n organizerId: raw.createdBy,\n attendees:\n raw.attendees?.map((attendee) => ({\n userId: attendee.userId ?? '',\n email: attendee.email ?? '',\n name: attendee.name ?? attendee.email ?? attendee.userId ?? '',\n status:\n (attendee.rsvpStatus as 'ACCEPTED' | 'DECLINED' | 'TENTATIVE' | 'PENDING') ?? 'PENDING',\n isRequired: !attendee.isOptional,\n })) ?? [],\n reminders:\n raw.reminders?.map((reminder) => ({\n id: reminder.id,\n minutesBefore: reminder.minutesBefore,\n method:\n reminder.channel === 'IN_APP'\n ? 'NOTIFICATION'\n : (reminder.channel as 'EMAIL' | 'NOTIFICATION' | 'SMS'),\n })) ?? [],\n resourceBookings:\n raw.resourceBookings?.map((booking) => ({\n id: booking.id,\n resourceId: booking.resourceId,\n resourceName: booking.resource?.name ?? 'Resource',\n resourceType: booking.resource?.resourceType ?? undefined,\n resourceLocation: booking.resource?.location ?? undefined,\n notes: booking.notes ?? undefined,\n eventId: raw.id,\n startTime: new Date(booking.startTime),\n endTime: new Date(booking.endTime),\n status: (booking.status as 'PENDING' | 'APPROVED' | 'REJECTED') ?? 'PENDING',\n createdAt: new Date(raw.createdAt),\n })) ?? [],\n attachments: normalizeAttachments(raw.attachments),\n videoCallLink: raw.onlineMeetingUrl ?? undefined,\n onlineMeetingProvider: raw.onlineMeetingProvider ?? undefined,\n maxAttendees: raw.maxAttendees ?? undefined,\n currentAttendeeCount: raw.currentAttendeeCount ?? undefined,\n checkInEnabled: raw.checkInEnabled ?? false,\n tags: raw.tags ?? [],\n metadata: raw.metadata ?? undefined,\n sourceKind: 'calendar',\n createdAt: new Date(raw.createdAt),\n updatedAt: new Date(raw.updatedAt),\n };\n}\n\nfunction parseScheduledJob(job: RawScheduledJob): CalendarEvent | null {\n const anchor = job.nextExecutionAt ?? job.scheduledAt ?? job.lastExecutionAt;\n if (!anchor) return null;\n\n const startTime = new Date(anchor);\n const endTime = new Date(startTime.getTime() + 30 * 60 * 1000);\n const status: EventStatus =\n job.status === 'CANCELLED' || job.status === 'FAILED' || job.status === 'DISABLED'\n ? 'CANCELLED'\n : job.status === 'PAUSED'\n ? 'TENTATIVE'\n : 'CONFIRMED';\n\n return {\n id: `scheduler-${job.id}`,\n calendarId: '__scheduler__',\n calendarName: 'Scheduler',\n calendarColor: '#7c3aed',\n title: job.name ?? job.description ?? 'Scheduled task',\n description: job.description ?? undefined,\n startTime,\n endTime,\n isAllDay: false,\n privacy: 'PRIVATE',\n status,\n organizerId: 'scheduler',\n tags: job.tags ?? [],\n metadata: {\n schedulerJobId: job.id,\n scheduleType: job.scheduleType,\n priority: job.priority,\n actionId: job.actionId,\n ...(job.metadata ?? {}),\n },\n sourceKind: 'scheduler',\n deepLink: `/scheduler/${job.id}`,\n createdAt: new Date(job.createdAt),\n updatedAt: new Date(job.updatedAt),\n };\n}\n\nfunction filterEvents(events: CalendarEvent[], filter: CalendarFilter) {\n return events.filter((event) => {\n if (filter.calendarIds?.length && !filter.calendarIds.includes(event.calendarId)) {\n return false;\n }\n\n if (filter.status?.length && !filter.status.includes(event.status)) {\n return false;\n }\n\n if (filter.privacy?.length && !filter.privacy.includes(event.privacy)) {\n return false;\n }\n\n if (filter.attendeeIds?.length) {\n const attendeeIds =\n event.attendees?.flatMap((attendee) => (attendee.userId ? [attendee.userId] : [])) ?? [];\n if (!filter.attendeeIds.some((attendeeId) => attendeeIds.includes(attendeeId))) {\n return false;\n }\n }\n\n if (filter.search?.trim()) {\n const searchTerm = filter.search.trim().toLowerCase();\n const haystack = [\n event.title,\n event.description,\n event.location,\n event.locationAddress,\n event.calendarName,\n ...(event.tags ?? []),\n ]\n .filter(Boolean)\n .join(' ')\n .toLowerCase();\n\n if (!haystack.includes(searchTerm)) {\n return false;\n }\n }\n\n return true;\n });\n}\n\nexport function useEvents({ startDate, endDate, skip = false }: UseEventsOptions) {\n const client = useApolloClient();\n const { workspaceId } = useCalendar();\n const visibleCalendars = useCalendarStore((state) => state.visibleCalendars);\n const eventFilter = useCalendarStore((state) => state.eventFilter);\n const {\n data: calendarsData,\n loading: calendarsLoading,\n refetch: refetchCalendars,\n } = useGetCalendarsQuery({\n variables: { pagination: { limit: 50 } },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n\n const [events, setEvents] = useState<CalendarEvent[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n // Bumped by refetch() to force the load effect to re-run (events are fetched\n // with one-off client.query calls, not a watched query).\n const [reloadNonce, setReloadNonce] = useState(0);\n\n const calendars = useMemo(\n () => calendarsData?.calendars?.calendars ?? [],\n [calendarsData?.calendars?.calendars]\n );\n\n const activeCalendarIds = useMemo(() => {\n const allCalendarIds = calendars.map((calendar: { id: string }) => calendar.id);\n const selectedFromVisibility =\n visibleCalendars.size > 0 ? Array.from(visibleCalendars) : allCalendarIds;\n const selectedFromFilter = eventFilter.calendarIds?.length\n ? eventFilter.calendarIds\n : selectedFromVisibility;\n\n return selectedFromFilter.filter((calendarId: string) => allCalendarIds.includes(calendarId));\n }, [calendars, eventFilter.calendarIds, visibleCalendars]);\n\n useEffect(() => {\n let isCancelled = false;\n\n const loadEvents = async () => {\n if (skip || calendarsLoading) {\n return;\n }\n\n setIsLoading(true);\n setError(null);\n\n try {\n // Fetch each calendar independently and tolerate partial failure: a\n // single forbidden/failed calendar (e.g. one the user can't access)\n // must NOT blank the entire range. `Promise.all` rejected the whole\n // batch on any single failure; `allSettled` keeps the calendars that\n // succeeded.\n const calendarEventSettlements: PromiseSettledResult<{\n data?: { eventsInRange?: RawCalendarEvent[] };\n }>[] = await Promise.allSettled(\n activeCalendarIds.map((calendarId: string) =>\n client.query<{ eventsInRange: RawCalendarEvent[] }>({\n query: EVENTS_IN_RANGE_QUERY,\n variables: {\n calendarId,\n startDate: startDate.toISOString(),\n endDate: endDate.toISOString(),\n },\n fetchPolicy: 'network-only',\n })\n )\n );\n\n // Only treat the load as failed if EVERY calendar query rejected (with\n // at least one attempted) — otherwise surface whatever did load.\n const anySucceeded = calendarEventSettlements.some(\n (settled) => settled.status === 'fulfilled'\n );\n if (activeCalendarIds.length > 0 && !anySucceeded) {\n const firstRejected = calendarEventSettlements.find(\n (settled): settled is PromiseRejectedResult => settled.status === 'rejected'\n );\n const reason = firstRejected?.reason;\n throw reason instanceof Error ? reason : new Error('Failed to load events');\n }\n\n const calendarEvents = calendarEventSettlements.flatMap((settled) =>\n settled.status === 'fulfilled' ? (settled.value.data?.eventsInRange ?? []) : []\n );\n\n const schedulerJobResponse = workspaceId\n ? await client\n .query<{\n scheduledJobs?: { jobs?: RawScheduledJob[] };\n }>({\n query: SCHEDULED_JOBS_QUERY,\n variables: {\n workspaceId,\n nextExecutionAfter: startDate.toISOString(),\n nextExecutionBefore: endDate.toISOString(),\n },\n fetchPolicy: 'network-only',\n })\n .catch(() => null)\n : null;\n\n const schedulerEvents: CalendarEvent[] = (\n schedulerJobResponse?.data?.scheduledJobs?.jobs ?? []\n )\n .map(parseScheduledJob)\n .filter((event): event is CalendarEvent => Boolean(event));\n\n const nextEvents = filterEvents(\n [...calendarEvents.map(parseCalendarEvent), ...schedulerEvents].sort(\n (left, right) => left.startTime.getTime() - right.startTime.getTime()\n ),\n eventFilter\n );\n\n if (!isCancelled) {\n setEvents(nextEvents);\n }\n } catch (loadError) {\n if (!isCancelled) {\n setError(loadError instanceof Error ? loadError.message : 'Failed to load events');\n setEvents([]);\n }\n } finally {\n if (!isCancelled) {\n setIsLoading(false);\n }\n }\n };\n\n void loadEvents();\n\n return () => {\n isCancelled = true;\n };\n }, [\n activeCalendarIds,\n calendarsLoading,\n client,\n endDate,\n eventFilter,\n reloadNonce,\n skip,\n startDate,\n workspaceId,\n ]);\n\n return {\n events,\n isLoading: isLoading || calendarsLoading,\n error,\n refetch: async () => {\n // Re-fetch the calendar list (a watched query) and bump the nonce so the\n // load effect re-runs the per-calendar one-off event queries. Without the\n // nonce, refetchQueries alone wouldn't reload the events (they aren't a\n // watched query) — the retry button would be a no-op.\n await refetchCalendars().catch(() => {});\n setReloadNonce((nonce) => nonce + 1);\n },\n };\n}\n"],"mappings":";;;;;;;AA+GA,SAAS,EAAqB,GAAoE;AAGhG,QAFK,IAEE,EAAe,QAA2B,GAAa,GAAY,MAAU;EAClF,IAAM,IAAM,EAAW,OAAO,EAAW,WAAW,IAC9C,IAAO,EAAW,QAAQ,EAAW,YAAY,cAAc,IAAQ;AAe7E,SAbI,CAAC,KAAO,CAAC,EAAW,UAIxB,EAAY,KAAK;GACf,IAAI,EAAW,MAAM,EAAW,UAAU,GAAG,EAAK,GAAG;GACrD,QAAQ,EAAW,UAAU,KAAA;GAC7B;GACA;GACA,MAAM,EAAW,QAAQ;GACzB,UAAU,EAAW,YAAY;GAClC,CAAC,EAVO;IAaR,EAAE,CAAC,GApBsB,EAAE;;AAuBhC,SAAS,EAAmB,GAAsC;AAChE,QAAO;EACL,IAAI,EAAI;EACR,YAAY,EAAI;EAChB,cAAc,EAAI,UAAU,QAAQ,KAAA;EACpC,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U,EAAW;aAEhB,GAAW;AAClB,KAAK,MACH,EAAS,aAAqB,QAAQ,EAAU,UAAU,wBAAwB,EAClF,EAAU,EAAE,CAAC;cAEP;AACR,KAAK,KACH,EAAa,GAAM;;;MAKR,QAEJ;AACX,OAAc;;IAEf;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,EAEK;EACL;EACA,WAAW,KAAa;EACxB;EACA,SAAS,YAAY;AAMnB,GADA,MAAM,GAAkB,CAAC,YAAY,GAAG,EACxC,GAAgB,MAAU,IAAQ,EAAE;;EAEvC"}
|
|
1
|
+
{"version":3,"file":"useEvents.js","names":[],"sources":["../../src/hooks/useEvents.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useApolloClient } from '@apollo/client/react';\nimport { useGetCalendarsQuery } from '../generated/wspace-operations';\nimport { useCalendar } from '../providers/CalendarProvider';\nimport { useCalendarStore } from '../store/calendarStore';\nimport type {\n CalendarEvent,\n CalendarFilter,\n EventAttachment,\n EventStatus,\n EventPrivacy,\n} from '../types';\nimport {\n EVENTS_IN_RANGE_QUERY,\n SCHEDULED_JOBS_QUERY,\n PLANMAGNET_WORK_ITEMS_QUERY,\n PLANMAGNET_MILESTONES_QUERY,\n} from '../graphql/calendarDocuments';\n\n// How many PlanMagnet items to page for the overlay. The list queries have no\n// dueDate filter, so we fetch a generous window and filter to the visible range\n// client-side; items past this cap in a huge backlog won't overlay (acceptable\n// for the MVP — add a dueDate range filter to planmagnet-svc if it ever bites).\nconst TASK_OVERLAY_LIMIT = 300;\n\ninterface UseEventsOptions {\n startDate: Date;\n endDate: Date;\n skip?: boolean;\n}\n\ninterface RawCalendarEvent {\n id: string;\n calendarId: string;\n workspaceId: string;\n title: string;\n description?: string | null;\n location?: string | null;\n locationAddress?: string | null;\n locationType?: string | null;\n locationUrl?: string | null;\n startTime: string;\n endTime: string;\n allDay: boolean;\n timezone?: string | null;\n status?: string | null;\n visibility?: string | null;\n eventType?: string | null;\n isRecurring?: boolean | null;\n rrule?: string | null;\n tags?: string[] | null;\n maxAttendees?: number | null;\n currentAttendeeCount?: number | null;\n checkInEnabled?: boolean | null;\n onlineMeetingUrl?: string | null;\n onlineMeetingProvider?: string | null;\n metadata?: Record<string, unknown> | null;\n createdBy: string;\n createdAt: string;\n updatedAt: string;\n calendar?: {\n id: string;\n name: string;\n color?: string | null;\n } | null;\n attendees?: Array<{\n userId?: string | null;\n email?: string | null;\n name?: string | null;\n rsvpStatus: string;\n isOptional: boolean;\n }> | null;\n reminders?: Array<{\n id: string;\n minutesBefore: number;\n channel: string;\n }> | null;\n resourceBookings?: Array<{\n id: string;\n resourceId: string;\n startTime: string;\n endTime: string;\n status: string;\n notes?: string | null;\n resource?: {\n id: string;\n name: string;\n resourceType?: string | null;\n location?: string | null;\n capacity?: number | null;\n } | null;\n }> | null;\n attachments?: Array<{\n id?: string | null;\n fileId?: string | null;\n name?: string | null;\n fileName?: string | null;\n url?: string | null;\n fileUrl?: string | null;\n size?: number | null;\n mimeType?: string | null;\n }> | null;\n}\n\ninterface RawScheduledJob {\n id: string;\n name?: string | null;\n description?: string | null;\n scheduleType: string;\n status: string;\n priority: string;\n scheduledAt?: string | null;\n nextExecutionAt?: string | null;\n lastExecutionAt?: string | null;\n timezone?: string | null;\n tags?: string[] | null;\n actionId?: string | null;\n metadata?: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n}\n\nfunction normalizeAttachments(rawAttachments: RawCalendarEvent['attachments']): EventAttachment[] {\n if (!rawAttachments) return [];\n\n return rawAttachments.reduce<EventAttachment[]>((attachments, attachment, index) => {\n const url = attachment.url ?? attachment.fileUrl ?? '';\n const name = attachment.name ?? attachment.fileName ?? `Attachment ${index + 1}`;\n\n if (!url && !attachment.fileId) {\n return attachments;\n }\n\n attachments.push({\n id: attachment.id ?? attachment.fileId ?? `${name}-${index}`,\n fileId: attachment.fileId ?? undefined,\n name,\n url,\n size: attachment.size ?? 0,\n mimeType: attachment.mimeType ?? 'application/octet-stream',\n });\n\n return attachments;\n }, []);\n}\n\nfunction parseCalendarEvent(raw: RawCalendarEvent): CalendarEvent {\n return {\n id: raw.id,\n calendarId: raw.calendarId,\n calendarName: raw.calendar?.name ?? undefined,\n calendarColor: raw.calendar?.color ?? undefined,\n title: raw.title,\n description: raw.description ?? undefined,\n location: raw.location ?? undefined,\n locationAddress: raw.locationAddress ?? undefined,\n locationType: (raw.locationType as CalendarEvent['locationType']) ?? undefined,\n locationUrl: raw.locationUrl ?? undefined,\n startTime: new Date(raw.startTime),\n endTime: new Date(raw.endTime),\n isAllDay: raw.allDay,\n privacy: ((raw.visibility as EventPrivacy | null) ?? 'PUBLIC') as EventPrivacy,\n status: ((raw.status as EventStatus | null) ?? 'CONFIRMED') as EventStatus,\n eventType: raw.eventType as CalendarEvent['eventType'],\n isRecurring: raw.isRecurring ?? false,\n rrule: raw.rrule ?? undefined,\n organizerId: raw.createdBy,\n attendees:\n raw.attendees?.map((attendee) => ({\n userId: attendee.userId ?? '',\n email: attendee.email ?? '',\n name: attendee.name ?? attendee.email ?? attendee.userId ?? '',\n status:\n (attendee.rsvpStatus as 'ACCEPTED' | 'DECLINED' | 'TENTATIVE' | 'PENDING') ?? 'PENDING',\n isRequired: !attendee.isOptional,\n })) ?? [],\n reminders:\n raw.reminders?.map((reminder) => ({\n id: reminder.id,\n minutesBefore: reminder.minutesBefore,\n method:\n reminder.channel === 'IN_APP'\n ? 'NOTIFICATION'\n : (reminder.channel as 'EMAIL' | 'NOTIFICATION' | 'SMS'),\n })) ?? [],\n resourceBookings:\n raw.resourceBookings?.map((booking) => ({\n id: booking.id,\n resourceId: booking.resourceId,\n resourceName: booking.resource?.name ?? 'Resource',\n resourceType: booking.resource?.resourceType ?? undefined,\n resourceLocation: booking.resource?.location ?? undefined,\n notes: booking.notes ?? undefined,\n eventId: raw.id,\n startTime: new Date(booking.startTime),\n endTime: new Date(booking.endTime),\n status: (booking.status as 'PENDING' | 'APPROVED' | 'REJECTED') ?? 'PENDING',\n createdAt: new Date(raw.createdAt),\n })) ?? [],\n attachments: normalizeAttachments(raw.attachments),\n videoCallLink: raw.onlineMeetingUrl ?? undefined,\n onlineMeetingProvider: raw.onlineMeetingProvider ?? undefined,\n maxAttendees: raw.maxAttendees ?? undefined,\n currentAttendeeCount: raw.currentAttendeeCount ?? undefined,\n checkInEnabled: raw.checkInEnabled ?? false,\n tags: raw.tags ?? [],\n metadata: raw.metadata ?? undefined,\n sourceKind: 'calendar',\n createdAt: new Date(raw.createdAt),\n updatedAt: new Date(raw.updatedAt),\n };\n}\n\nfunction parseScheduledJob(job: RawScheduledJob): CalendarEvent | null {\n const anchor = job.nextExecutionAt ?? job.scheduledAt ?? job.lastExecutionAt;\n if (!anchor) return null;\n\n const startTime = new Date(anchor);\n const endTime = new Date(startTime.getTime() + 30 * 60 * 1000);\n const status: EventStatus =\n job.status === 'CANCELLED' || job.status === 'FAILED' || job.status === 'DISABLED'\n ? 'CANCELLED'\n : job.status === 'PAUSED'\n ? 'TENTATIVE'\n : 'CONFIRMED';\n\n return {\n id: `scheduler-${job.id}`,\n calendarId: '__scheduler__',\n calendarName: 'Scheduler',\n calendarColor: '#7c3aed',\n title: job.name ?? job.description ?? 'Scheduled task',\n description: job.description ?? undefined,\n startTime,\n endTime,\n isAllDay: false,\n privacy: 'PRIVATE',\n status,\n organizerId: 'scheduler',\n tags: job.tags ?? [],\n metadata: {\n schedulerJobId: job.id,\n scheduleType: job.scheduleType,\n priority: job.priority,\n actionId: job.actionId,\n ...(job.metadata ?? {}),\n },\n sourceKind: 'scheduler',\n deepLink: `/scheduler/${job.id}`,\n createdAt: new Date(job.createdAt),\n updatedAt: new Date(job.updatedAt),\n };\n}\n\ninterface RawWorkItem {\n id: string;\n key?: string | null;\n title: string;\n type?: string | null;\n status?: string | null;\n priority?: string | null;\n assigneeId?: string | null;\n dueDate?: string | null;\n}\n\ninterface RawMilestone {\n id: string;\n name: string;\n status?: string | null;\n dueDate?: string | null;\n}\n\n// Work item / milestone statuses that are \"done\" — hidden from the calendar.\nconst DONE_WORK_ITEM_STATUSES = new Set(['DONE', 'CANCELLED']);\nconst DONE_MILESTONE_STATUSES = new Set(['COMPLETED', 'CANCELLED']);\n\n/**\n * Parse a YYYY-MM-DD (or ISO) due date into a LOCAL midnight Date so an all-day\n * task lands on the intended calendar day. `new Date('2026-07-10')` parses as\n * UTC midnight and shows a day early in negative-offset zones — so we build the\n * date from its Y/M/D parts in local time instead.\n */\nfunction parseDueDateLocal(due: string | null | undefined): Date | null {\n if (!due) return null;\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})/.exec(due);\n if (!match) {\n const fallback = new Date(due);\n return Number.isNaN(fallback.getTime()) ? null : fallback;\n }\n return new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));\n}\n\n/**\n * Project a PlanMagnet work item into a synthetic, read-only all-day calendar\n * event on its due date, deep-linking to the host's Tasks page (opens the task\n * detail via `?item=`). Returns null when it should not appear (no due date, or\n * a done/cancelled task — hidden per product choice). Nothing is persisted;\n * PlanMagnet remains the single source of truth.\n */\nfunction parseWorkItem(item: RawWorkItem, tasksPath: string): CalendarEvent | null {\n const day = parseDueDateLocal(item.dueDate);\n if (!day) return null;\n if (item.status && DONE_WORK_ITEM_STATUSES.has(item.status)) return null;\n\n return {\n id: `task-${item.id}`,\n calendarId: '__tasks__',\n calendarName: 'Tasks',\n calendarColor: 'var(--color-accent-blue)',\n title: item.title,\n startTime: day,\n endTime: new Date(day.getTime()),\n isAllDay: true,\n privacy: 'PRIVATE',\n status: 'CONFIRMED',\n eventType: 'TASK',\n organizerId: item.assigneeId ?? 'planmagnet',\n tags: [],\n metadata: {\n source: 'planmagnet',\n entityType: 'workItem',\n workItemId: item.id,\n key: item.key ?? undefined,\n status: item.status ?? undefined,\n priority: item.priority ?? undefined,\n assigneeId: item.assigneeId ?? undefined,\n },\n sourceKind: 'task',\n deepLink: `${tasksPath}?item=${encodeURIComponent(item.id)}`,\n createdAt: day,\n updatedAt: day,\n };\n}\n\n/** Project a PlanMagnet milestone into a synthetic all-day flag on its due date. */\nfunction parseMilestone(milestone: RawMilestone, tasksPath: string): CalendarEvent | null {\n const day = parseDueDateLocal(milestone.dueDate);\n if (!day) return null;\n if (milestone.status && DONE_MILESTONE_STATUSES.has(milestone.status)) return null;\n\n return {\n id: `milestone-${milestone.id}`,\n calendarId: '__milestones__',\n calendarName: 'Milestones',\n calendarColor: 'var(--color-accent-purple)',\n title: milestone.name,\n startTime: day,\n endTime: new Date(day.getTime()),\n isAllDay: true,\n privacy: 'PRIVATE',\n status: 'CONFIRMED',\n eventType: 'MILESTONE',\n organizerId: 'planmagnet',\n tags: [],\n metadata: {\n source: 'planmagnet',\n entityType: 'milestone',\n milestoneId: milestone.id,\n status: milestone.status ?? undefined,\n },\n sourceKind: 'milestone',\n // Milestones aren't opened in the task-detail drawer; deep-link to the Tasks\n // page (its Timeline surfaces milestones) rather than an ?item= detail.\n deepLink: tasksPath,\n createdAt: day,\n updatedAt: day,\n };\n}\n\nfunction filterEvents(events: CalendarEvent[], filter: CalendarFilter) {\n return events.filter((event) => {\n // Task / milestone overlay toggles — default ON (only hidden when the\n // sidebar checkbox is explicitly unchecked). These synthetic events are not\n // real calendars, so the calendarIds filter below must not drop them.\n if (event.sourceKind === 'task') return filter.showTasks !== false;\n if (event.sourceKind === 'milestone') return filter.showMilestones !== false;\n\n if (filter.calendarIds?.length && !filter.calendarIds.includes(event.calendarId)) {\n return false;\n }\n\n if (filter.status?.length && !filter.status.includes(event.status)) {\n return false;\n }\n\n if (filter.privacy?.length && !filter.privacy.includes(event.privacy)) {\n return false;\n }\n\n if (filter.attendeeIds?.length) {\n const attendeeIds =\n event.attendees?.flatMap((attendee) => (attendee.userId ? [attendee.userId] : [])) ?? [];\n if (!filter.attendeeIds.some((attendeeId) => attendeeIds.includes(attendeeId))) {\n return false;\n }\n }\n\n if (filter.search?.trim()) {\n const searchTerm = filter.search.trim().toLowerCase();\n const haystack = [\n event.title,\n event.description,\n event.location,\n event.locationAddress,\n event.calendarName,\n ...(event.tags ?? []),\n ]\n .filter(Boolean)\n .join(' ')\n .toLowerCase();\n\n if (!haystack.includes(searchTerm)) {\n return false;\n }\n }\n\n return true;\n });\n}\n\nexport function useEvents({ startDate, endDate, skip = false }: UseEventsOptions) {\n const client = useApolloClient();\n const { workspaceId, taskOverlay } = useCalendar();\n const visibleCalendars = useCalendarStore((state) => state.visibleCalendars);\n const eventFilter = useCalendarStore((state) => state.eventFilter);\n const {\n data: calendarsData,\n loading: calendarsLoading,\n refetch: refetchCalendars,\n } = useGetCalendarsQuery({\n variables: { pagination: { limit: 50 } },\n skip,\n fetchPolicy: 'cache-and-network',\n });\n\n const [events, setEvents] = useState<CalendarEvent[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n // Bumped by refetch() to force the load effect to re-run (events are fetched\n // with one-off client.query calls, not a watched query).\n const [reloadNonce, setReloadNonce] = useState(0);\n\n const calendars = useMemo(\n () => calendarsData?.calendars?.calendars ?? [],\n [calendarsData?.calendars?.calendars]\n );\n\n const activeCalendarIds = useMemo(() => {\n const allCalendarIds = calendars.map((calendar: { id: string }) => calendar.id);\n const selectedFromVisibility =\n visibleCalendars.size > 0 ? Array.from(visibleCalendars) : allCalendarIds;\n const selectedFromFilter = eventFilter.calendarIds?.length\n ? eventFilter.calendarIds\n : selectedFromVisibility;\n\n return selectedFromFilter.filter((calendarId: string) => allCalendarIds.includes(calendarId));\n }, [calendars, eventFilter.calendarIds, visibleCalendars]);\n\n useEffect(() => {\n let isCancelled = false;\n\n const loadEvents = async () => {\n if (skip || calendarsLoading) {\n return;\n }\n\n setIsLoading(true);\n setError(null);\n\n try {\n // Fetch each calendar independently and tolerate partial failure: a\n // single forbidden/failed calendar (e.g. one the user can't access)\n // must NOT blank the entire range. `Promise.all` rejected the whole\n // batch on any single failure; `allSettled` keeps the calendars that\n // succeeded.\n const calendarEventSettlements: PromiseSettledResult<{\n data?: { eventsInRange?: RawCalendarEvent[] };\n }>[] = await Promise.allSettled(\n activeCalendarIds.map((calendarId: string) =>\n client.query<{ eventsInRange: RawCalendarEvent[] }>({\n query: EVENTS_IN_RANGE_QUERY,\n variables: {\n calendarId,\n startDate: startDate.toISOString(),\n endDate: endDate.toISOString(),\n },\n fetchPolicy: 'network-only',\n })\n )\n );\n\n // Only treat the load as failed if EVERY calendar query rejected (with\n // at least one attempted) — otherwise surface whatever did load.\n const anySucceeded = calendarEventSettlements.some(\n (settled) => settled.status === 'fulfilled'\n );\n if (activeCalendarIds.length > 0 && !anySucceeded) {\n const firstRejected = calendarEventSettlements.find(\n (settled): settled is PromiseRejectedResult => settled.status === 'rejected'\n );\n const reason = firstRejected?.reason;\n throw reason instanceof Error ? reason : new Error('Failed to load events');\n }\n\n const calendarEvents = calendarEventSettlements.flatMap((settled) =>\n settled.status === 'fulfilled' ? (settled.value.data?.eventsInRange ?? []) : []\n );\n\n const schedulerJobResponse = workspaceId\n ? await client\n .query<{\n scheduledJobs?: { jobs?: RawScheduledJob[] };\n }>({\n query: SCHEDULED_JOBS_QUERY,\n variables: {\n workspaceId,\n nextExecutionAfter: startDate.toISOString(),\n nextExecutionBefore: endDate.toISOString(),\n },\n fetchPolicy: 'network-only',\n })\n .catch(() => null)\n : null;\n\n const schedulerEvents: CalendarEvent[] = (\n schedulerJobResponse?.data?.scheduledJobs?.jobs ?? []\n )\n .map(parseScheduledJob)\n .filter((event): event is CalendarEvent => Boolean(event));\n\n // PlanMagnet task + milestone overlay (Option A: live read-through, no\n // write to calendar-svc). Opt-in via the host's taskOverlay config;\n // fetched best-effort so a missing planmagnet module or a user without\n // task-read permission simply yields no overlay (never blanks events).\n const tasksPath = taskOverlay?.tasksPath;\n const overlayEvents: CalendarEvent[] = [];\n if (tasksPath && workspaceId) {\n const [workItemsResponse, milestonesResponse] = await Promise.all([\n client\n .query<{ planmagnetWorkItems?: { items?: RawWorkItem[] } }>({\n query: PLANMAGNET_WORK_ITEMS_QUERY,\n variables: { workspaceId, pagination: { first: TASK_OVERLAY_LIMIT } },\n fetchPolicy: 'network-only',\n })\n .catch(() => null),\n client\n .query<{ planmagnetMilestones?: { items?: RawMilestone[] } }>({\n query: PLANMAGNET_MILESTONES_QUERY,\n variables: { workspaceId, pagination: { first: TASK_OVERLAY_LIMIT } },\n fetchPolicy: 'network-only',\n })\n .catch(() => null),\n ]);\n\n const inWindow = (event: CalendarEvent) =>\n event.startTime.getTime() >= startDate.getTime() &&\n event.startTime.getTime() <= endDate.getTime();\n\n for (const item of workItemsResponse?.data?.planmagnetWorkItems?.items ?? []) {\n const event = parseWorkItem(item, tasksPath);\n if (event && inWindow(event)) overlayEvents.push(event);\n }\n for (const milestone of milestonesResponse?.data?.planmagnetMilestones?.items ?? []) {\n const event = parseMilestone(milestone, tasksPath);\n if (event && inWindow(event)) overlayEvents.push(event);\n }\n }\n\n const nextEvents = filterEvents(\n [...calendarEvents.map(parseCalendarEvent), ...schedulerEvents, ...overlayEvents].sort(\n (left, right) => left.startTime.getTime() - right.startTime.getTime()\n ),\n eventFilter\n );\n\n if (!isCancelled) {\n setEvents(nextEvents);\n }\n } catch (loadError) {\n if (!isCancelled) {\n setError(loadError instanceof Error ? loadError.message : 'Failed to load events');\n setEvents([]);\n }\n } finally {\n if (!isCancelled) {\n setIsLoading(false);\n }\n }\n };\n\n void loadEvents();\n\n return () => {\n isCancelled = true;\n };\n }, [\n activeCalendarIds,\n calendarsLoading,\n client,\n endDate,\n eventFilter,\n reloadNonce,\n skip,\n startDate,\n workspaceId,\n // Key on the stable path string, not the config object identity, so an\n // inline taskOverlay prop doesn't retrigger the fetch every render.\n taskOverlay?.tasksPath,\n ]);\n\n return {\n events,\n isLoading: isLoading || calendarsLoading,\n error,\n refetch: async () => {\n // Re-fetch the calendar list (a watched query) and bump the nonce so the\n // load effect re-runs the per-calendar one-off event queries. Without the\n // nonce, refetchQueries alone wouldn't reload the events (they aren't a\n // watched query) — the retry button would be a no-op.\n await refetchCalendars().catch(() => {});\n setReload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K,CACrB,CAAC,EAEI,KAAY,MAChB,EAAM,UAAU,SAAS,IAAI,EAAU,SAAS,IAChD,EAAM,UAAU,SAAS,IAAI,EAAQ,SAAS;AAEhD,WAAK,IAAM,KAAQ,GAAmB,MAAM,qBAAqB,SAAS,EAAE,EAAE;OAC5E,IAAM,IAAQ,EAAc,GAAM,EAAU;AAC5C,OAAI,KAAS,EAAS,EAAM,IAAE,EAAc,KAAK,EAAM;;AAEzD,WAAK,IAAM,KAAa,GAAoB,MAAM,sBAAsB,SAAS,EAAE,EAAE;OACnF,IAAM,IAAQ,EAAe,GAAW,EAAU;AAClD,OAAI,KAAS,EAAS,EAAM,IAAE,EAAc,KAAK,EAAM;;;KAI3D,IAAM,IAAa,EACjB;MAAC,GAAG,EAAe,IAAI,EAAmB;MAAE,GAAG;MAAiB,GAAG;MAAc,CAAC,MAC/E,GAAM,MAAU,EAAK,UAAU,SAAS,GAAG,EAAM,UAAU,SAAS,CACtE,EACD,EACD;AAED,KAAK,KACH,EAAU,EAAW;aAEhB,GAAW;AAClB,KAAK,MACH,EAAS,aAAqB,QAAQ,EAAU,UAAU,wBAAwB,EAClF,EAAU,EAAE,CAAC;cAEP;AACR,KAAK,KACH,EAAa,GAAM;;;MAKR,QAEJ;AACX,OAAc;;IAEf;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAGA,GAAa;EACd,CAAC,EAEK;EACL;EACA,WAAW,KAAa;EACxB;EACA,SAAS,YAAY;AAMnB,GADA,MAAM,GAAkB,CAAC,YAAY,GAAG,EACxC,GAAgB,MAAU,IAAQ,EAAE;;EAEvC"}
|
|
@@ -2,20 +2,24 @@ import { useCalendar as e } from "../providers/CalendarProvider.js";
|
|
|
2
2
|
import { useCalendarStore as t } from "../store/calendarStore.js";
|
|
3
3
|
//#region src/hooks/useOpenEvent.ts
|
|
4
4
|
function n() {
|
|
5
|
-
let n = t((e) => e.selectEvent), { basePath:
|
|
5
|
+
let n = t((e) => e.selectEvent), r = t((e) => e.openTaskDetail), { basePath: i, navigate: a, onEventSelect: o } = e();
|
|
6
6
|
return (e) => {
|
|
7
|
-
if (n(e),
|
|
7
|
+
if (n(e), o?.({
|
|
8
8
|
id: e.id,
|
|
9
9
|
title: e.title,
|
|
10
10
|
startTime: e.startTime,
|
|
11
11
|
endTime: e.endTime,
|
|
12
12
|
isAllDay: e.isAllDay,
|
|
13
13
|
calendarId: e.calendarId
|
|
14
|
-
}), e.sourceKind === "
|
|
15
|
-
|
|
14
|
+
}), e.sourceKind === "task" || e.sourceKind === "milestone") {
|
|
15
|
+
r(e);
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
if (e.sourceKind && e.sourceKind !== "calendar" && e.deepLink) {
|
|
19
|
+
a(e.deepLink);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
a(`${i}/event/${e.id}`);
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpenEvent.js","names":[],"sources":["../../src/hooks/useOpenEvent.ts"],"sourcesContent":["/**\n * useOpenEvent — shared \"open this event\" behaviour.\n *\n * Selects the event in the store, notifies the host shell, and navigates to the\n * event detail route (or the scheduler deep-link for scheduler-sourced events).\n * Shared by EventBlock and the Timeline chips so every view opens events the\n * same way.\n */\n\nimport { useCalendarStore } from '../store/calendarStore';\nimport { useCalendar } from '../providers/CalendarProvider';\nimport type { CalendarEvent } from '../types';\n\nexport function useOpenEvent(): (event: CalendarEvent) => void {\n const selectEvent = useCalendarStore((state) => state.selectEvent);\n const { basePath, navigate, onEventSelect } = useCalendar();\n\n return (event: CalendarEvent) => {\n selectEvent(event);\n\n onEventSelect?.({\n id: event.id,\n title: event.title,\n startTime: event.startTime,\n endTime: event.endTime,\n isAllDay: event.isAllDay,\n calendarId: event.calendarId,\n });\n\n if (event.sourceKind === 'scheduler' && event.deepLink) {\n navigate(event.deepLink);\n return;\n }\n\n navigate(`${basePath}/event/${event.id}`);\n };\n}\n"],"mappings":";;;AAaA,SAAgB,IAA+C;CAC7D,IAAM,IAAc,GAAkB,MAAU,EAAM,YAAY,EAC5D,EAAE,aAAU,aAAU,qBAAkB,GAAa;AAE3D,SAAQ,MAAyB;
|
|
1
|
+
{"version":3,"file":"useOpenEvent.js","names":[],"sources":["../../src/hooks/useOpenEvent.ts"],"sourcesContent":["/**\n * useOpenEvent — shared \"open this event\" behaviour.\n *\n * Selects the event in the store, notifies the host shell, and navigates to the\n * event detail route (or the scheduler deep-link for scheduler-sourced events).\n * Shared by EventBlock and the Timeline chips so every view opens events the\n * same way.\n */\n\nimport { useCalendarStore } from '../store/calendarStore';\nimport { useCalendar } from '../providers/CalendarProvider';\nimport type { CalendarEvent } from '../types';\n\nexport function useOpenEvent(): (event: CalendarEvent) => void {\n const selectEvent = useCalendarStore((state) => state.selectEvent);\n const openTaskDetail = useCalendarStore((state) => state.openTaskDetail);\n const { basePath, navigate, onEventSelect } = useCalendar();\n\n return (event: CalendarEvent) => {\n selectEvent(event);\n\n onEventSelect?.({\n id: event.id,\n title: event.title,\n startTime: event.startTime,\n endTime: event.endTime,\n isAllDay: event.isAllDay,\n calendarId: event.calendarId,\n });\n\n // PlanMagnet tasks/milestones open a READ-ONLY details modal in the calendar\n // (title/due/status/priority/assignee) with an \"Open in Tasks\" button — the\n // calendar views task info, it doesn't own or edit it. The modal renders\n // from the in-memory event (no calendar-svc fetch → no 404 on a synthetic id).\n if (event.sourceKind === 'task' || event.sourceKind === 'milestone') {\n openTaskDetail(event);\n return;\n }\n\n // Other synthetic sources (scheduler jobs) still deep-link straight out.\n if (event.sourceKind && event.sourceKind !== 'calendar' && event.deepLink) {\n navigate(event.deepLink);\n return;\n }\n\n navigate(`${basePath}/event/${event.id}`);\n };\n}\n"],"mappings":";;;AAaA,SAAgB,IAA+C;CAC7D,IAAM,IAAc,GAAkB,MAAU,EAAM,YAAY,EAC5D,IAAiB,GAAkB,MAAU,EAAM,eAAe,EAClE,EAAE,aAAU,aAAU,qBAAkB,GAAa;AAE3D,SAAQ,MAAyB;AAgB/B,MAfA,EAAY,EAAM,EAElB,IAAgB;GACd,IAAI,EAAM;GACV,OAAO,EAAM;GACb,WAAW,EAAM;GACjB,SAAS,EAAM;GACf,UAAU,EAAM;GAChB,YAAY,EAAM;GACnB,CAAC,EAME,EAAM,eAAe,UAAU,EAAM,eAAe,aAAa;AACnE,KAAe,EAAM;AACrB;;AAIF,MAAI,EAAM,cAAc,EAAM,eAAe,cAAc,EAAM,UAAU;AACzE,KAAS,EAAM,SAAS;AACxB;;AAGF,IAAS,GAAG,EAAS,SAAS,EAAM,KAAK"}
|