Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 (explorer) dismiss focus state after unselecting an entity #4365

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@ourworldindata/explorer/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SlideShowManager,
DEFAULT_GRAPHER_ENTITY_TYPE,
GrapherAnalytics,
FocusArray,
} from "@ourworldindata/grapher"
import {
Bounds,
Expand Down Expand Up @@ -277,6 +278,8 @@ export class Explorer
? this.props.selection
: new SelectionArray(this.explorerProgram.selection)

focusArray = new FocusArray()

entityType = this.explorerProgram.entityType ?? DEFAULT_GRAPHER_ENTITY_TYPE

@observable.ref grapher?: Grapher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export class EntityPicker extends React.Component<{
): void {
this.manager.selection.toggleSelection(name)

// Remove focus from an entity that has been removed from the selection
if (!this.manager.selection.selectedSet.has(name)) {
this.manager.focusArray?.remove(name)
}

// Clear search input
this.searchInput = ""
this.manager.analytics?.logEntityPickerEvent(
Expand Down Expand Up @@ -644,9 +649,10 @@ export class EntityPicker extends React.Component<{
title={selectedDebugMessage}
className="ClearSelectionButton"
data-track-note="entity_picker_clear_selection"
onClick={(): void =>
onClick={(): void => {
selection.clearSelection()
}
this.manager.focusArray?.clear()
}}
>
<FontAwesomeIcon icon={faTimes} /> Clear
selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GrapherAnalytics } from "../../core/GrapherAnalytics"
import { OwidTable } from "@ourworldindata/core-table"
import { CoreColumnDef, SortOrder } from "@ourworldindata/types"
import { SelectionArray } from "../../selection/SelectionArray"
import { FocusArray } from "../../focus/FocusArray"

export interface EntityPickerManager {
entityPickerMetric?: ColumnSlug
Expand All @@ -19,4 +20,5 @@ export interface EntityPickerManager {
selection: SelectionArray
entityType?: string
analytics?: GrapherAnalytics
focusArray?: FocusArray
}
3 changes: 2 additions & 1 deletion packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export interface GrapherManager {
embedDialogUrl?: string
embedDialogAdditionalElements?: React.ReactElement
selection?: SelectionArray
focusArray?: FocusArray
editUrl?: string
}

Expand Down Expand Up @@ -512,7 +513,7 @@ export class Grapher
this.props.table?.availableEntities ?? []
)

focusArray = new FocusArray()
focusArray = this.manager?.focusArray ?? new FocusArray()

/**
* todo: factor this out and make more RAII.
Expand Down
1 change: 1 addition & 0 deletions packages/@ourworldindata/grapher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export {
MapProjectionGeos,
} from "./mapCharts/MapProjections"
export { SelectionArray } from "./selection/SelectionArray"
export { FocusArray } from "./focus/FocusArray"
export {
setSelectedEntityNamesParam,
migrateSelectedEntityNamesParam,
Expand Down
Loading