|
26 | 26 |
|
27 | 27 | import React, { useEffect, useState, useMemo } from 'react'; |
28 | 28 | import type { ObjectGridSchema, DataSource, ViewData } from '@object-ui/types'; |
| 29 | +import { z } from 'zod'; |
| 30 | + |
| 31 | +const MapConfigSchema = z.object({ |
| 32 | + latitudeField: z.string().optional(), |
| 33 | + longitudeField: z.string().optional(), |
| 34 | + locationField: z.string().optional(), |
| 35 | + titleField: z.string().optional(), |
| 36 | + descriptionField: z.string().optional(), |
| 37 | + zoom: z.number().optional(), |
| 38 | + center: z.tuple([z.number(), z.number()]).optional(), |
| 39 | +}); |
29 | 40 |
|
30 | 41 | export interface ObjectMapProps { |
31 | 42 | schema: ObjectGridSchema; |
@@ -109,14 +120,23 @@ function convertSortToQueryParams(sort: string | any[] | undefined): Record<stri |
109 | 120 | * Helper to get map configuration from schema |
110 | 121 | */ |
111 | 122 | function getMapConfig(schema: ObjectGridSchema): MapConfig { |
| 123 | + let config: MapConfig | null = null; |
112 | 124 | // Check if schema has map configuration |
113 | 125 | if (schema.filter && typeof schema.filter === 'object' && 'map' in schema.filter) { |
114 | | - return (schema.filter as any).map as MapConfig; |
| 126 | + config = (schema.filter as any).map as MapConfig; |
115 | 127 | } |
116 | 128 |
|
117 | 129 | // For backward compatibility, check if schema has map config at root |
118 | | - if ((schema as any).map) { |
119 | | - return (schema as any).map as MapConfig; |
| 130 | + else if ((schema as any).map) { |
| 131 | + config = (schema as any).map as MapConfig; |
| 132 | + } |
| 133 | + |
| 134 | + if (config) { |
| 135 | + const result = MapConfigSchema.safeParse(config); |
| 136 | + if (!result.success) { |
| 137 | + console.warn(`[ObjectMap] Invalid map configuration:`, result.error.format()); |
| 138 | + } |
| 139 | + return config; |
120 | 140 | } |
121 | 141 |
|
122 | 142 | // Default configuration |
|
0 commit comments