Skip to content

Commit

Permalink
chore: use assignment operators when possible (??=, ||=, +=, `-…
Browse files Browse the repository at this point in the history
…=`) (#4227)
  • Loading branch information
marcelgerber authored Nov 27, 2024
1 parent 5324762 commit 0758f9f
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 30 deletions.
4 changes: 2 additions & 2 deletions adminSiteClient/GrapherConfigGridEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ export class GrapherConfigGridEditor extends React.Component<GrapherConfigGridEd
(this.numTotalRows ?? 0) > PAGEING_SIZE &&
this.desiredPagingOffset >= PAGEING_SIZE
)
this.desiredPagingOffset = this.desiredPagingOffset - PAGEING_SIZE
this.desiredPagingOffset -= PAGEING_SIZE
}

@action.bound
Expand All @@ -1350,7 +1350,7 @@ export class GrapherConfigGridEditor extends React.Component<GrapherConfigGridEd
(this.numTotalRows ?? 0) > PAGEING_SIZE &&
this.desiredPagingOffset + PAGEING_SIZE < (this.numTotalRows ?? 0)
) {
this.desiredPagingOffset = this.desiredPagingOffset + PAGEING_SIZE
this.desiredPagingOffset += PAGEING_SIZE
}
}

Expand Down
2 changes: 1 addition & 1 deletion adminSiteServer/chartConfigHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const saveNewChartConfigInDbAndR2 = async (
patchConfig: GrapherInterface,
fullConfig: GrapherInterface
) => {
chartConfigId = chartConfigId ?? (uuidv7() as Base64String)
chartConfigId ??= uuidv7() as Base64String

await knex<DbInsertChartConfig>(ChartConfigsTableName).insert({
id: chartConfigId,
Expand Down
4 changes: 2 additions & 2 deletions adminSiteServer/testPageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ async function propsFromQueryParams(
if (params.type) {
if (params.type === GRAPHER_MAP_TYPE) {
query = query.andWhereRaw(`cc.full->>"$.hasMapTab" = "true"`)
tab = tab || GRAPHER_TAB_OPTIONS.map
tab ||= GRAPHER_TAB_OPTIONS.map
} else {
query = query.andWhereRaw(`cc.chartType = :type`, {
type: params.type,
})
tab = tab || GRAPHER_TAB_OPTIONS.chart
tab ||= GRAPHER_TAB_OPTIONS.chart
}
}

Expand Down
5 changes: 2 additions & 3 deletions db/migration/1661264304751-MigrateSelectedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export class MigrateSelectedData1661264304751 implements MigrationInterface {
if (item.entityId && item.color) {
// migrate entity color
if (!legacyConfig.selectedEntityColors) {
newConfig.selectedEntityColors =
newConfig.selectedEntityColors ?? {}
newConfig.selectedEntityColors ??= {}
const entityName = entityNameById[item.entityId]
if (entityName) {
newConfig.selectedEntityColors[entityName] ??=
Expand All @@ -79,7 +78,7 @@ export class MigrateSelectedData1661264304751 implements MigrationInterface {
// migrate dimension color
const dimension = newConfig.dimensions?.[item.index]
if (dimension?.variableId) {
dimension.display = dimension.display ?? {}
dimension.display ??= {}
dimension.display.color ??= item.color
}
}
Expand Down
2 changes: 1 addition & 1 deletion db/model/Gdoc/htmlToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export function adjustHeadingLevels(
const correction = isEntry
? minHeadingLevel - 1
: Math.max(0, minHeadingLevel - 2)
block.level = block.level - correction
block.level -= correction
} else if ("children" in block) {
adjustHeadingLevels(
block.children as OwidEnrichedGdocBlock[],
Expand Down
7 changes: 4 additions & 3 deletions packages/@ourworldindata/core-table/src/CoreTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,9 +1398,10 @@ export class CoreTable<
sourceTable: CoreTable,
by?: ColumnSlug[]
): COL_DEF_TYPE[] {
by =
by ??
intersection(sourceTable.columnSlugs, destinationTable.columnSlugs)
by ??= intersection(
sourceTable.columnSlugs,
destinationTable.columnSlugs
)
const columnSlugsToAdd = difference(
sourceTable.columnSlugs,
destinationTable.columnSlugs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const toAlignedTextTable = (
// Drop columns if they exceed the max line width
let runningWidth = 0
const finalHeaderSlugs = headerSlugs.filter((slug, index) => {
runningWidth = runningWidth + colWidths[index]
runningWidth += colWidths[index]
if (runningWidth <= maxCharactersPerLine) return true
return false
})
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/explorer/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export class Explorer
const mergedDef = { ...def, ...manuallyProvidedDef }

// update display properties
mergedDef.display = mergedDef.display ?? {}
mergedDef.display ??= {}
if (manuallyProvidedDef.name)
mergedDef.display.name = manuallyProvidedDef.name
if (manuallyProvidedDef.unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const VerticalScrollContainer = React.forwardRef(
...rest
} = props

scrollingShadows = scrollingShadows ?? true
scrollingShadows ??= true

const scrollContainerRef = useCombinedRefs<HTMLDivElement>(ref)
const [scrollTop, scrollBottom] = useScrollBounds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Areas extends React.Component<AreasProps> {
if (index > 0) {
prevPoints = placedSeriesArr[index - 1].placedPoints
} else {
prevPoints = prevPoints = [
prevPoints = [
[
placedPoints[0][0], // placed x coord of first (= leftmost) point in chart
verticalAxis.range[0],
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/types/src/domainTypes/Various.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class JsonError extends Error {
status: number
constructor(message: string, status?: number) {
super(message)
this.status = status || 400
this.status = status ?? 400
}
}

Expand Down
6 changes: 3 additions & 3 deletions site/gdocs/components/HomepageIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function FeaturedWorkTile({
}
}

title = title || linkedDocument?.title
authors = authors || linkedDocument?.authors
description = description || linkedDocument?.excerpt
title ||= linkedDocument?.title
authors ||= linkedDocument?.authors
description ||= linkedDocument?.excerpt

return (
<a
Expand Down
19 changes: 9 additions & 10 deletions site/gdocs/components/ProminentLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,19 @@ export const ProminentLink = (props: {
let thumbnail: string | undefined = props.thumbnail
if (linkType === "gdoc") {
href = `/${linkedDocument?.slug}`
title = title ?? linkedDocument?.title
description = description ?? linkedDocument?.excerpt
thumbnail = thumbnail ?? linkedDocument?.["featured-image"]
title ??= linkedDocument?.title
description ??= linkedDocument?.excerpt
thumbnail ??= linkedDocument?.["featured-image"]
} else if (linkType === "grapher") {
href = `${linkedChart?.resolvedUrl}`
title = title ?? linkedChart?.title
thumbnail = thumbnail ?? linkedChart?.thumbnail
description =
description ?? "See the data in our interactive visualization"
title ??= linkedChart?.title
thumbnail ??= linkedChart?.thumbnail
description ??= "See the data in our interactive visualization"
} else if (linkType === "explorer") {
href = `${linkedChart?.resolvedUrl}`
title = title ?? `${linkedChart?.title} Data Explorer`
thumbnail = thumbnail ?? linkedChart?.thumbnail
description = description ?? linkedChart?.subtitle
title ??= `${linkedChart?.title} Data Explorer`
thumbnail ??= linkedChart?.thumbnail
description ??= linkedChart?.subtitle
}

const anchorTagProps =
Expand Down

0 comments on commit 0758f9f

Please sign in to comment.