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

Grapher redesign: Add feedback for empty search result in entity selector #2675

Merged
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
4 changes: 4 additions & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2764,6 +2764,10 @@ export class Grapher
)
}

@computed get entitiesAreCountryLike(): boolean {
return !!this.entityType.match(/\bcountry\b/i)
}

@computed get startSelectingWhenLineClicked(): boolean {
return this.showAddEntityButton
}
Expand Down
11 changes: 4 additions & 7 deletions packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface DataTableManager {
startTime?: Time
dataTableSlugs?: ColumnSlug[]
showSelectionOnlyInDataTable?: boolean
entitiesAreCountryLike?: boolean
isSmall?: boolean
isMedium?: boolean
isNarrow?: boolean
Expand Down Expand Up @@ -164,10 +165,6 @@ export class DataTable extends React.Component<{
return this.manager.entityType ?? "Country/area"
}

@computed private get entitiesAreCountryLike(): boolean {
return !!this.entityType.match(/\bcountry\b/i)
}

@computed private get sortValueMapper(): (
row: DataTableRow
) => number | string {
Expand Down Expand Up @@ -893,18 +890,18 @@ export class DataTable extends React.Component<{
}

@computed private get displayEntityRows(): DataTableRow[] {
if (!this.entitiesAreCountryLike) return this.displayRows
if (!this.manager.entitiesAreCountryLike) return this.displayRows
return this.displayRows.filter((row) => isCountryName(row.entityName))
}

@computed private get displayAggregateRows(): DataTableRow[] {
if (!this.entitiesAreCountryLike) return []
if (!this.manager.entitiesAreCountryLike) return []
return this.displayRows.filter((row) => !isCountryName(row.entityName))
}

@computed private get showTitleRows(): boolean {
return (
this.entitiesAreCountryLike &&
!!this.manager.entitiesAreCountryLike &&
this.displayEntityRows.length > 0 &&
this.displayAggregateRows.length > 0
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
}
}

.searchResults .empty {
font-size: 0.8125em;
}

&.EntitySelectorSingle {
ul {
margin-top: 8px;
Expand Down Expand Up @@ -109,6 +113,10 @@
font-weight: 900;
}
}

.searchResults .empty {
margin-top: 1.5em;
}
}

&.EntitySelectorMulti {
Expand Down
37 changes: 24 additions & 13 deletions packages/@ourworldindata/grapher/src/modal/EntitySelectorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DEFAULT_BOUNDS,
isTouchDevice,
sortBy,
isCountryName,
} from "@ourworldindata/utils"
import { Checkbox } from "../controls/Checkbox"
import { FuzzySearch } from "../controls/FuzzySearch"
Expand All @@ -24,6 +25,7 @@ export interface EntitySelectorModalManager {
tabBounds?: Bounds
entityType?: string
entityTypePlural?: string
entitiesAreCountryLike?: boolean
}

interface SearchableEntity {
Expand Down Expand Up @@ -228,19 +230,28 @@ export class EntitySelectorModal extends React.Component<{

<div className="entities">
<div className="searchResults">
<ul>
{searchResults.map((result) => (
<EntitySearchResult
key={result.name}
result={result}
isMulti={this.isMulti}
isChecked={selectionArray.selectedSet.has(
result.name
)}
onSelect={this.onSelect}
/>
))}
</ul>
{searchResults.length > 0 ? (
<ul>
{searchResults.map((result) => (
<EntitySearchResult
key={result.name}
result={result}
isMulti={this.isMulti}
isChecked={selectionArray.selectedSet.has(
result.name
)}
onSelect={this.onSelect}
/>
))}
</ul>
) : (
<div className="empty">
{this.manager.entitiesAreCountryLike &&
isCountryName(this.searchInput)
? "There is no data for the country, region or group you are looking for."
: "Nothing turned up. You may want to try using different keywords or checking for typos."}
</div>
)}
</div>
{this.renderSelectedData()}
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/@ourworldindata/utils/src/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ const countriesBySlug: Record<string, Country> = Object.fromEntries(

const currentAndHistoricalCountryNames = regions
.filter(({ regionType }) => regionType === "country")
.map(({ name }) => name)
.map(({ name }) => name.toLowerCase())

export const isCountryName = (name: string): boolean =>
currentAndHistoricalCountryNames.includes(name)
currentAndHistoricalCountryNames.includes(name.toLowerCase())

export const getCountryBySlug = (slug: string): Country | undefined =>
countriesBySlug[slug]
Loading