Skip to content

Commit cf2c610

Browse files
committed
Refactor available view types logic in ListView to enhance flexibility based on schema options
1 parent 89bd89c commit cf2c610

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

packages/plugin-list/src/ListView.tsx

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,50 @@ export const ListView: React.FC<ListViewProps> = ({
192192
return () => { isMounted = false; };
193193
}, [schema.objectName, dataSource, schema.filters, currentSort, currentFilters]); // Re-fetch on filter/sort change
194194

195+
// Available view types based on schema configuration
196+
const availableViews = React.useMemo(() => {
197+
const views: ViewType[] = ['grid'];
198+
199+
// Check for Kanban capabilities
200+
if (schema.options?.kanban?.groupField) {
201+
views.push('kanban');
202+
}
203+
204+
// Check for Gallery capabilities
205+
if (schema.options?.gallery?.imageField) {
206+
views.push('gallery');
207+
}
208+
209+
// Check for Calendar capabilities
210+
if (schema.options?.calendar?.startDateField) {
211+
views.push('calendar');
212+
}
213+
214+
// Check for Timeline capabilities
215+
if (schema.options?.timeline?.dateField || schema.options?.calendar?.startDateField) {
216+
views.push('timeline');
217+
}
218+
219+
// Check for Gantt capabilities
220+
if (schema.options?.gantt?.startDateField) {
221+
views.push('gantt');
222+
}
223+
224+
// Check for Map capabilities
225+
if (schema.options?.map?.locationField || (schema.options?.map?.latitudeField && schema.options?.map?.longitudeField)) {
226+
views.push('map');
227+
}
228+
229+
// Always allow switching back to the viewType defined in schema if it's one of the supported types
230+
// This ensures that if a view is configured as "map", the map button is shown even if we missed the options check above
231+
if (schema.viewType && !views.includes(schema.viewType as ViewType) &&
232+
['grid', 'kanban', 'calendar', 'timeline', 'gantt', 'map', 'gallery'].includes(schema.viewType)) {
233+
views.push(schema.viewType as ViewType);
234+
}
235+
236+
return views;
237+
}, [schema.options, schema.viewType]);
238+
195239
// Load saved view preference
196240
React.useEffect(() => {
197241
try {
@@ -297,50 +341,6 @@ export const ListView: React.FC<ListViewProps> = ({
297341
}
298342
}, [currentView, schema, currentSort]);
299343

300-
// Available view types based on schema configuration
301-
const availableViews = React.useMemo(() => {
302-
const views: ViewType[] = ['grid'];
303-
304-
// Check for Kanban capabilities
305-
if (schema.options?.kanban?.groupField) {
306-
views.push('kanban');
307-
}
308-
309-
// Check for Gallery capabilities
310-
if (schema.options?.gallery?.imageField) {
311-
views.push('gallery');
312-
}
313-
314-
// Check for Calendar capabilities
315-
if (schema.options?.calendar?.startDateField) {
316-
views.push('calendar');
317-
}
318-
319-
// Check for Timeline capabilities
320-
if (schema.options?.timeline?.dateField || schema.options?.calendar?.startDateField) {
321-
views.push('timeline');
322-
}
323-
324-
// Check for Gantt capabilities
325-
if (schema.options?.gantt?.startDateField) {
326-
views.push('gantt');
327-
}
328-
329-
// Check for Map capabilities
330-
if (schema.options?.map?.locationField || (schema.options?.map?.latitudeField && schema.options?.map?.longitudeField)) {
331-
views.push('map');
332-
}
333-
334-
// Always allow switching back to the viewType defined in schema if it's one of the supported types
335-
// This ensures that if a view is configured as "map", the map button is shown even if we missed the options check above
336-
if (schema.viewType && !views.includes(schema.viewType as ViewType) &&
337-
['grid', 'kanban', 'calendar', 'timeline', 'gantt', 'map', 'gallery'].includes(schema.viewType)) {
338-
views.push(schema.viewType as ViewType);
339-
}
340-
341-
return views;
342-
}, [schema.options, schema.viewType]);
343-
344344
const hasFilters = currentFilters.conditions && currentFilters.conditions.length > 0;
345345

346346
const filterFields = React.useMemo(() => {

0 commit comments

Comments
 (0)