Keep map theme state aligned
This commit is contained in:
@@ -308,6 +308,12 @@ function pickThemeDataset(
|
||||
return candidates[0] ?? null
|
||||
}
|
||||
|
||||
function themeIdForDataset(dataset: DatasetCreateResponse | null): DataThemeId | null {
|
||||
return dataset
|
||||
? DATA_THEMES.find((theme) => datasetMatchesTheme(dataset, theme))?.id ?? null
|
||||
: null
|
||||
}
|
||||
|
||||
function temporalSeriesLabel(items: DatasetCreateResponse[]): string {
|
||||
const configuredLabel = items.find((item) => typeof item.source_metadata?.['temporal_series_label'] === 'string')
|
||||
?.source_metadata?.['temporal_series_label']
|
||||
@@ -774,7 +780,10 @@ export function MapWorkspace({
|
||||
onClearQualityEvidence,
|
||||
}: MapWorkspaceProps): JSX.Element {
|
||||
const [advancedMode, setAdvancedMode] = useState(false)
|
||||
const [activeThemeId, setActiveThemeId] = useState<DataThemeId>('buildings')
|
||||
const [activeThemeId, setActiveThemeId] = useState<DataThemeId>(() => {
|
||||
const selectedDataset = availableMapDatasets.find((dataset) => dataset.id === selectedMapDatasetId) ?? null
|
||||
return themeIdForDataset(selectedDataset) ?? 'buildings'
|
||||
})
|
||||
const {
|
||||
themeInsights,
|
||||
themeInsightsLoading: themeResultsLoading,
|
||||
@@ -1093,9 +1102,9 @@ export function MapWorkspace({
|
||||
if (!selectedMapDataset) {
|
||||
return
|
||||
}
|
||||
const matchingTheme = DATA_THEMES.find((theme) => datasetMatchesTheme(selectedMapDataset, theme))
|
||||
if (matchingTheme) {
|
||||
setActiveThemeId(matchingTheme.id)
|
||||
const matchingThemeId = themeIdForDataset(selectedMapDataset)
|
||||
if (matchingThemeId) {
|
||||
setActiveThemeId(matchingThemeId)
|
||||
}
|
||||
}, [selectedMapDataset])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user