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

enhance(admin): persist entities when changing the chart type #2702

Merged
merged 2 commits into from
Oct 20, 2023
Merged
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
27 changes: 18 additions & 9 deletions adminSiteClient/EditorBasicTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,32 @@ class DimensionSlotView extends React.Component<{
const { availableEntityNames, availableEntityNameSet } = selection

if (grapher.isScatter || grapher.isSlopeChart || grapher.isMarimekko) {
// chart types that display all entities by default shouldn't select any by default
selection.clearSelection()
} else if (
grapher.yColumnsFromDimensions.length > 1 &&
!grapher.isStackedArea &&
!grapher.isStackedBar
) {
const entity = availableEntityNameSet.has(WorldEntityName)
? WorldEntityName
: sample(availableEntityNames)
if (entity) selection.setSelectedEntities([entity])
// non-stacked charts with multiple y-dimensions should select a single entity by default.
// if possible, the currently selected entity is persisted, otherwise "World" is preferred
if (selection.numSelectedEntities !== 1) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also pick the first entity if multiple entities are currently selected

const entity = availableEntityNameSet.has(WorldEntityName)
? WorldEntityName
: sample(availableEntityNames)
if (entity) selection.setSelectedEntities([entity])
}
grapher.addCountryMode = EntitySelectionMode.SingleEntity
} else {
selection.setSelectedEntities(
availableEntityNames.length > 10
? sampleSize(availableEntityNames, 4)
: availableEntityNames
)
// stacked charts or charts with a single y-dimension should select multiple entities by default.
// if possible, the currently selected entities are persisted, otherwise a random sample is selected
if (selection.numSelectedEntities <= 1) {
selection.setSelectedEntities(
availableEntityNames.length > 10
? sampleSize(availableEntityNames, 4)
: availableEntityNames
)
}
grapher.addCountryMode = EntitySelectionMode.MultipleEntities
}
}
Expand Down
Loading