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

Add "Show selection only" toggle for tables #2602

Closed
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
1 change: 1 addition & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export class Grapher
/** Hides the total value label that is normally displayed for stacked bar charts */
@observable.ref hideTotalValueLabel?: boolean = undefined
@observable.ref missingDataStrategy?: MissingDataStrategy = undefined
@observable.ref showSelectionOnlyInDataTable?: boolean = undefined

@observable.ref xAxis = new AxisConfig(undefined, this)
@observable.ref yAxis = new AxisConfig(undefined, this)
Expand Down
16 changes: 15 additions & 1 deletion packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface DataTableManager {
endTime?: Time
startTime?: Time
dataTableSlugs?: ColumnSlug[]
showSelectionOnlyInDataTable?: boolean
isSmall?: boolean
isMedium?: boolean
}
Expand All @@ -87,6 +88,19 @@ export class DataTable extends React.Component<{
manager?: DataTableManager
bounds?: Bounds
}> {
transformTable(table: OwidTable): OwidTable {
if (this.manager.showSelectionOnlyInDataTable) {
table = table.filterByEntityNames(
this.selectionArray.selectedEntityNames
)
}
return table
}

@computed get transformedTable(): OwidTable {
return this.transformTable(this.manager.table)
}

@observable private storedState: DataTableState = {
sort: DEFAULT_SORT_STATE,
}
Expand Down Expand Up @@ -124,7 +138,7 @@ export class DataTable extends React.Component<{
}

@computed get table(): OwidTable {
return this.inputTable
return this.transformedTable
}

@computed get inputTable(): OwidTable {
Expand Down