|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { ComponentRegistry } from '@object-ui/core'; |
10 | | -import type { CalendarViewSchema, CalendarEvent } from '@object-ui/types'; |
11 | | -import { CalendarView } from './CalendarView'; |
| 10 | +import type { CalendarViewSchema } from '@object-ui/types'; |
| 11 | +import { CalendarView, type CalendarEvent } from './CalendarView'; |
12 | 12 | import React from 'react'; |
13 | 13 |
|
14 | 14 | // Calendar View Renderer - Airtable-style calendar for displaying records as events |
@@ -43,7 +43,7 @@ ComponentRegistry.register('calendar-view', |
43 | 43 | }, [schema.data, schema.titleField, schema.startDateField, schema.endDateField, schema.colorField, schema.allDayField]); |
44 | 44 |
|
45 | 45 | const handleEventClick = (event: CalendarEvent) => { |
46 | | - if (schema.events?.onEventClick) { |
| 46 | + if (schema.onEventClick) { |
47 | 47 | // Dispatch configured action |
48 | 48 | // This would use the action runner in a real implementation |
49 | 49 | // For now we just call onAction if provided |
@@ -73,97 +73,7 @@ ComponentRegistry.register('calendar-view', |
73 | 73 | /> |
74 | 74 | ); |
75 | 75 | } |
76 | | -); const allDayField = schema.allDayField || 'allDay'; |
77 | | - |
78 | | - const title = record[titleField] || 'Untitled'; |
79 | | - const start = record[startField] ? new Date(record[startField]) : new Date(); |
80 | | - const end = record[endField] ? new Date(record[endField]) : undefined; |
81 | | - const allDay = record[allDayField] !== undefined ? record[allDayField] : false; |
82 | | - |
83 | | - // Handle color mapping |
84 | | - let color = record[colorField]; |
85 | | - if (color && schema.colorMapping && schema.colorMapping[color]) { |
86 | | - color = schema.colorMapping[color]; |
87 | | - } |
88 | | - |
89 | | - return { |
90 | | - id: String(record.id || record._id || index), |
91 | | - title, |
92 | | - start, |
93 | | - end, |
94 | | - allDay, |
95 | | - color, |
96 | | - data: record, |
97 | | - }; |
98 | | - }); |
99 | | - }, [schema.data, schema.titleField, schema.startDateField, schema.endDateField, schema.colorField, schema.allDayField, schema.colorMapping]); |
100 | | - |
101 | | - const handleEventClick = React.useCallback((event: any) => { |
102 | | - if (onAction) { |
103 | | - onAction({ |
104 | | - type: 'event_click', |
105 | | - payload: { event: event.data, eventId: event.id } |
106 | | - }); |
107 | | - } |
108 | | - if (schema.onEventClick) { |
109 | | - schema.onEventClick(event.data); |
110 | | - } |
111 | | - }, [onAction, schema]); |
112 | | - |
113 | | - const handleDateClick = React.useCallback((date: Date) => { |
114 | | - if (onAction) { |
115 | | - onAction({ |
116 | | - type: 'date_click', |
117 | | - payload: { date } |
118 | | - }); |
119 | | - } |
120 | | - if (schema.onDateClick) { |
121 | | - schema.onDateClick(date); |
122 | | - } |
123 | | - }, [onAction, schema]); |
124 | | - |
125 | | - const handleViewChange = React.useCallback((view: "month" | "week" | "day") => { |
126 | | - if (onAction) { |
127 | | - onAction({ |
128 | | - type: 'view_change', |
129 | | - payload: { view } |
130 | | - }); |
131 | | - } |
132 | | - if (schema.onViewChange) { |
133 | | - schema.onViewChange(view); |
134 | | - } |
135 | | - }, [onAction, schema]); |
136 | | - |
137 | | - const handleNavigate = React.useCallback((date: Date) => { |
138 | | - if (onAction) { |
139 | | - onAction({ |
140 | | - type: 'navigate', |
141 | | - payload: { date } |
142 | | - }); |
143 | | - } |
144 | | - if (schema.onNavigate) { |
145 | | - schema.onNavigate(date); |
146 | | - } |
147 | | - }, [onAction, schema]); |
148 | | - |
149 | | - const validView = (schema.view && ['month', 'week', 'day'].includes(schema.view)) |
150 | | - ? (schema.view as "month" | "week" | "day") |
151 | | - : 'month'; |
152 | | - |
153 | | - return ( |
154 | | - <CalendarView |
155 | | - events={events} |
156 | | - view={validView} |
157 | | - currentDate={schema.currentDate ? new Date(schema.currentDate) : undefined} |
158 | | - onEventClick={handleEventClick} |
159 | | - onDateClick={schema.allowCreate || schema.onDateClick ? handleDateClick : undefined} |
160 | | - onViewChange={handleViewChange} |
161 | | - onNavigate={handleNavigate} |
162 | | - className={className} |
163 | | - {...props} |
164 | | - /> |
165 | | - ); |
166 | | - }, |
| 76 | +, |
167 | 77 | { |
168 | 78 | namespace: 'plugin-calendar', |
169 | 79 | label: 'Calendar View', |
|
0 commit comments