Skip to content

Commit

Permalink
Merge branch 'master' of github.com:owid/owid-grapher
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed May 22, 2024
2 parents a2c7023 + ab9ef41 commit 2a99b12
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.

This file was deleted.

32 changes: 0 additions & 32 deletions packages/@ourworldindata/grapher/src/bodyPortal/BodyPortal.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ interface SortConfig {
order: SortOrder
}

type SearchableEntity = { name: string; local?: boolean } & Record<
ColumnSlug,
CoreValueType | undefined
>
type SearchableEntity = {
name: string
local?: boolean
isWorld?: boolean
} & Record<ColumnSlug, CoreValueType | undefined>

interface PartitionedEntities {
selected: SearchableEntity[]
Expand Down Expand Up @@ -447,7 +448,10 @@ export class EntitySelector extends React.Component<{

@computed private get availableEntities(): SearchableEntity[] {
return this.availableEntityNames.map((entityName) => {
const searchableEntity: SearchableEntity = { name: entityName }
const searchableEntity: SearchableEntity = {
name: entityName,
isWorld: entityName === "World",
}

if (this.localEntityNames) {
searchableEntity.local =
Expand All @@ -468,15 +472,17 @@ export class EntitySelector extends React.Component<{

private sortEntities(
entities: SearchableEntity[],
options: { sortLocalsToTop: boolean } = { sortLocalsToTop: true }
options: { sortLocalsAndWorldToTop: boolean } = {
sortLocalsAndWorldToTop: true,
}
): SearchableEntity[] {
const { sortConfig } = this

const shouldBeSortedByName =
sortConfig.slug === this.table.entityNameSlug

// sort by name, ignoring local entities
if (shouldBeSortedByName && !options.sortLocalsToTop) {
if (shouldBeSortedByName && !options.sortLocalsAndWorldToTop) {
return orderBy(
entities,
(entity: SearchableEntity) => entity.name,
Expand All @@ -485,9 +491,14 @@ export class EntitySelector extends React.Component<{
}

// sort by name, with local entities at the top
if (shouldBeSortedByName && options.sortLocalsToTop) {
const [localEntities, otherEntities] = partition(
if (shouldBeSortedByName && options.sortLocalsAndWorldToTop) {
const [[worldEntity], entitiesWithoutWorld] = partition(
entities,
(entity) => entity.isWorld
)

const [localEntities, otherEntities] = partition(
entitiesWithoutWorld,
(entity: SearchableEntity) => entity.local
)

Expand All @@ -503,7 +514,11 @@ export class EntitySelector extends React.Component<{
sortConfig.order
)

return [...sortedLocalEntities, ...sortedOtherEntities]
return excludeUndefined([
...sortedLocalEntities,
worldEntity,
...sortedOtherEntities,
])
}

// sort by number column, with missing values at the end
Expand Down Expand Up @@ -563,7 +578,9 @@ export class EntitySelector extends React.Component<{
)

return {
selected: this.sortEntities(selected, { sortLocalsToTop: false }),
selected: this.sortEntities(selected, {
sortLocalsAndWorldToTop: false,
}),
unselected: this.sortEntities(unselected),
}
}
Expand Down
10 changes: 10 additions & 0 deletions site/DataPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
pick,
GrapherInterface,
ImageMetadata,
Url,
} from "@ourworldindata/utils"
import { MarkdownTextWrap } from "@ourworldindata/components"
import React from "react"
Expand Down Expand Up @@ -57,6 +58,7 @@ export const DataPageV2 = (props: {
const canonicalUrl = grapher?.slug
? urljoin(baseGrapherUrl, grapher.slug as string)
: ""
const dataApiOrigin = Url.fromURL(DATA_API_URL).origin
let pageDesc: string
if (grapher?.subtitle?.length) {
// convert subtitle from markdown to plaintext
Expand Down Expand Up @@ -123,6 +125,7 @@ export const DataPageV2 = (props: {
figure[data-grapher-src] { display: none !important; }
`}</style>
</noscript>
<link rel="preconnect" href={dataApiOrigin} />
{variableIds.flatMap((variableId) =>
[
getVariableDataRoute(DATA_API_URL, variableId),
Expand All @@ -137,6 +140,13 @@ export const DataPageV2 = (props: {
/>
))
)}
<link
rel="preload"
href="/fonts/PlayfairDisplayLatin-SemiBold.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
</Head>
<body className="DataPage">
<SiteHeader baseUrl={baseUrl} />
Expand Down

0 comments on commit 2a99b12

Please sign in to comment.