11import { ArrowLeftIcon , SettingsIcon , XIcon } from "lucide-react" ;
2- import { useState } from "react" ;
2+ import { useMemo , useState } from "react" ;
33
44import { useInspector } from "@/app/map/[id]/hooks/useInspector" ;
55import { cn } from "@/shadcn/utils" ;
@@ -26,12 +26,26 @@ export default function InspectorPanel() {
2626 setFocusedRecord,
2727 selectedRecords,
2828 } = useInspector ( ) ;
29+ const { dataSource, properties, type } = inspectorContent ?? { } ;
30+
31+ const safeActiveTab = useMemo ( ( ) => {
32+ if ( activeTab === "data" && type === LayerType . Cluster ) {
33+ return "markers" ;
34+ }
35+ const isMarkers = type === LayerType . Marker || type === LayerType . Member ;
36+ if ( activeTab === "markers" && isMarkers ) {
37+ return "data" ;
38+ }
39+ if ( activeTab === "config" && type !== LayerType . Boundary ) {
40+ return type === LayerType . Cluster ? "markers" : "data" ;
41+ }
42+ return activeTab ;
43+ } , [ activeTab , type ] ) ;
2944
3045 if ( ! Boolean ( inspectorContent ) ) {
3146 return < > </ > ;
3247 }
3348
34- const { dataSource, properties, type } = inspectorContent ?? { } ;
3549 const isDetailsView = Boolean (
3650 ( selectedTurf && type !== LayerType . Turf ) ||
3751 ( selectedBoundary && type !== LayerType . Boundary ) ,
@@ -49,17 +63,17 @@ export default function InspectorPanel() {
4963 className = { cn (
5064 "absolute top-0 bottom-0 right-4 / flex flex-col gap-6 py-5" ,
5165 "bottom-24" , // to avoid clash with bug report button
52- activeTab === "config" ? "h-full" : "h-fit max-h-full" ,
66+ safeActiveTab === "config" ? "h-full" : "h-fit max-h-full" ,
5367 ) }
5468 style = { {
55- minWidth : activeTab === "config" ? "400px" : "250px" ,
69+ minWidth : safeActiveTab === "config" ? "400px" : "250px" ,
5670 maxWidth : "450px" ,
5771 } }
5872 >
5973 < div
6074 className = { cn (
6175 "relative z-50 w-full overflow-auto / flex flex-col / rounded shadow-lg bg-white / text-sm font-sans" ,
62- activeTab === "config" ? "h-full" : "max-h-full" ,
76+ safeActiveTab === "config" ? "h-full" : "max-h-full" ,
6377 ) }
6478 >
6579 < div className = "flex justify-between items-center gap-4 p-3" >
@@ -98,12 +112,14 @@ export default function InspectorPanel() {
98112
99113 < UnderlineTabs
100114 defaultValue = "data"
101- value = { activeTab }
115+ value = { safeActiveTab }
102116 onValueChange = { setActiveTab }
103117 className = "flex flex-col overflow-hidden h-full"
104118 >
105119 < UnderlineTabsList className = "w-full flex gap-6 border-t px-3" >
106- < UnderlineTabsTrigger value = "data" > Data</ UnderlineTabsTrigger >
120+ { type !== LayerType . Cluster && (
121+ < UnderlineTabsTrigger value = "data" > Data</ UnderlineTabsTrigger >
122+ ) }
107123 < UnderlineTabsTrigger
108124 value = "markers"
109125 className = { cn (
@@ -116,20 +132,27 @@ export default function InspectorPanel() {
116132 < UnderlineTabsTrigger value = "notes" className = "hidden" >
117133 Notes 0
118134 </ UnderlineTabsTrigger >
119- < UnderlineTabsTrigger value = "config" className = "px-2" >
120- < SettingsIcon size = { 16 } />
121- </ UnderlineTabsTrigger >
135+ { type === LayerType . Boundary && (
136+ < UnderlineTabsTrigger value = "config" className = "px-2" >
137+ < SettingsIcon size = { 16 } />
138+ </ UnderlineTabsTrigger >
139+ ) }
122140 </ UnderlineTabsList >
123141
124- < UnderlineTabsContent value = "data" className = "grow overflow-auto p-3" >
125- < InspectorDataTab
126- dataSource = { dataSource }
127- properties = { properties }
128- isDetailsView = { isDetailsView }
129- focusedRecord = { focusedRecord }
130- type = { type }
131- />
132- </ UnderlineTabsContent >
142+ { type !== LayerType . Cluster && (
143+ < UnderlineTabsContent
144+ value = "data"
145+ className = "grow overflow-auto p-3"
146+ >
147+ < InspectorDataTab
148+ dataSource = { dataSource }
149+ properties = { properties }
150+ isDetailsView = { isDetailsView }
151+ focusedRecord = { focusedRecord }
152+ type = { type }
153+ />
154+ </ UnderlineTabsContent >
155+ ) }
133156
134157 < UnderlineTabsContent
135158 value = "markers"
@@ -145,12 +168,14 @@ export default function InspectorPanel() {
145168 < InspectorNotesTab />
146169 </ UnderlineTabsContent >
147170
148- < UnderlineTabsContent
149- value = "config"
150- className = "grow overflow-auto p-3 h-full"
151- >
152- < InspectorConfigTab />
153- </ UnderlineTabsContent >
171+ { type === LayerType . Boundary && (
172+ < UnderlineTabsContent
173+ value = "config"
174+ className = "grow overflow-auto p-3 h-full"
175+ >
176+ < InspectorConfigTab />
177+ </ UnderlineTabsContent >
178+ ) }
154179 </ UnderlineTabs >
155180 </ div >
156181 </ div >
0 commit comments