Skip to content

Commit

Permalink
🐛 clear focus when clearing query params (#4366)
Browse files Browse the repository at this point in the history
clear focus
  • Loading branch information
sophiamersmann authored Jan 2, 2025
1 parent 3eda0e1 commit 162e43f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,11 @@ export class Grapher
this.selection.setSelectedEntities(this.selectedEntityNames)
}

@action.bound private applyOriginalFocusAsAuthored(): void {
if (this.focusedSeriesNames?.length)
this.focusArray.clearAllAndAdd(...this.focusedSeriesNames)
}

@computed get hasData(): boolean {
return this.dimensions.length > 0 || this.newSlugs.length > 0
}
Expand Down Expand Up @@ -2641,10 +2646,14 @@ export class Grapher
},
{
combo: "a",
fn: (): void | SelectionArray =>
this.selection.hasSelection
? this.selection.clearSelection()
: this.selection.selectAll(),
fn: (): void => {
if (this.selection.hasSelection) {
this.selection.clearSelection()
this.focusArray.clear()
} else {
this.selection.selectAll()
}
},
title: this.selection.hasSelection
? `Select None`
: `Select All`,
Expand Down Expand Up @@ -3354,6 +3363,11 @@ export class Grapher
this.applyOriginalSelectionAsAuthored()
}

@action.bound clearFocus(): void {
this.focusArray.clear()
this.applyOriginalFocusAsAuthored()
}

@action.bound clearQueryParams(): void {
const { authorsVersion } = this
this.tab = authorsVersion.tab
Expand All @@ -3370,6 +3384,7 @@ export class Grapher
authorsVersion.showSelectionOnlyInDataTable
this.showNoDataArea = authorsVersion.showNoDataArea
this.clearSelection()
this.clearFocus()
}

// Todo: come up with a more general pattern?
Expand All @@ -3388,6 +3403,7 @@ export class Grapher
this.sizeSlug = grapher.sizeSlug

this.selection.clearSelection()
this.focusArray.clear()
}

debounceMode = false
Expand Down

0 comments on commit 162e43f

Please sign in to comment.