ultisuite-client/lib/agenda/agenda-calendar-visibility.ts
R3D347HR4Y ad1370ea7e
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat: enhance configuration and add new demo layouts
- Introduced turbopack alias for canvas in next.config.mjs.
- Updated package.json scripts for development and branding tasks.
- Added new dependencies for Tiptap extensions.
- Implemented new demo layouts for agenda, contacts, drive, and mail applications.
- Enhanced globals.css for improved theming and splash screen animations.
- Added OAuth callback handling for drive mounts.
- Updated layout components to integrate new demo shells and improve structure.
2026-06-12 19:10:24 +02:00

120 lines
3.4 KiB
TypeScript

import type { AgendaCalendarView, AgendaExternalCalendar } from "@/lib/agenda/agenda-settings-types"
import type { AgendaCalendar } from "@/lib/agenda/agenda-types"
export const EXTERNAL_CALENDAR_ID_PREFIX = "ext:"
export function isExternalCalendarId(id: string): boolean {
return id.startsWith(EXTERNAL_CALENDAR_ID_PREFIX)
}
export function externalCalendarToAgendaCalendar(
external: AgendaExternalCalendar,
): AgendaCalendar {
return {
id: external.id,
display_name: external.display_name,
color: external.color,
path: external.url,
}
}
export function mergeAgendaCalendars(
apiCalendars: AgendaCalendar[],
externalCalendars: AgendaExternalCalendar[],
): AgendaCalendar[] {
return [
...apiCalendars,
...externalCalendars.map(externalCalendarToAgendaCalendar),
]
}
export function isCalendarEnabledForAccount(
calendarId: string,
accountId: string,
accountEnabledCalendarIds: Record<string, string[]>,
): boolean {
const enabled = accountEnabledCalendarIds[accountId]
if (!enabled) return true
return enabled.includes(calendarId)
}
export function isCalendarEnabledForAnyAccount(
calendarId: string,
accountIds: string[],
accountEnabledCalendarIds: Record<string, string[]>,
scopedAccountId: string | null = null,
): boolean {
if (accountIds.length === 0) return true
const relevantAccountIds = scopedAccountId
? accountIds.filter((accountId) => accountId === scopedAccountId)
: accountIds
if (scopedAccountId && relevantAccountIds.length === 0) return false
return relevantAccountIds.some((accountId) =>
isCalendarEnabledForAccount(calendarId, accountId, accountEnabledCalendarIds),
)
}
export function resolveActiveCalendarView(
calendarViews: AgendaCalendarView[],
activeCalendarViewId: string | null,
): AgendaCalendarView | null {
if (!activeCalendarViewId) return null
return calendarViews.find((view) => view.id === activeCalendarViewId) ?? null
}
export function resolveVisibleCalendarIds({
allCalendars,
hiddenCalendarIds,
accountIds,
accountEnabledCalendarIds,
activeView,
}: {
allCalendars: Array<{ id: string; account_id?: string | null }>
hiddenCalendarIds: string[]
accountIds: string[]
accountEnabledCalendarIds: Record<string, string[]>
activeView: AgendaCalendarView | null
}): string[] {
const hidden = new Set(hiddenCalendarIds)
return allCalendars
.map((calendar) => calendar.id)
.filter((calendarId) => {
if (hidden.has(calendarId)) return false
const scopedAccountId =
allCalendars.find((calendar) => calendar.id === calendarId)?.account_id ?? null
if (
!isCalendarEnabledForAnyAccount(
calendarId,
accountIds,
accountEnabledCalendarIds,
scopedAccountId,
)
) {
return false
}
if (activeView && !activeView.calendar_ids.includes(calendarId)) {
return false
}
return true
})
}
export function filterAgendaCalendars(
calendars: AgendaCalendar[],
visibleIds: string[],
): AgendaCalendar[] {
const visible = new Set(visibleIds)
return calendars.filter((calendar) => visible.has(calendar.id))
}
/** Libellé sidebar pour désactiver une vue — réservé, pas de vue enregistrée. */
export const ALL_AGENDAS_VIEW_LABEL = "Tous les agendas"
export function isReservedAgendaViewName(name: string): boolean {
return (
name.trim().toLocaleLowerCase("fr") ===
ALL_AGENDAS_VIEW_LABEL.toLocaleLowerCase("fr")
)
}