Skip to content

Commit

Permalink
Run npx react-codemod update-react-imports
Browse files Browse the repository at this point in the history
Since React 17 we no longer need to import React for JSX transforms.
Running this codemod:

* Removes all unused React imports as a result of upgrading to the new
  JSX transform.
* Changes all default React imports (i.e. import React from "react") to
  destructured named imports (ex. import { useState } from "react") which
  is the preferred style going into the future.

These cannot be separated, even though we now only needed to remove the
unused imports.
  • Loading branch information
rakyi committed Dec 26, 2024
1 parent a808921 commit 05dee10
Show file tree
Hide file tree
Showing 372 changed files with 392 additions and 558 deletions.
2 changes: 1 addition & 1 deletion adminShared/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { drop, escapeRegExp, sortBy } from "@ourworldindata/utils"
import React from "react"
import * as React from "react"

export interface SearchWord {
regex: RegExp
Expand Down
1 change: 0 additions & 1 deletion adminSiteClient/Admin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react"
import ReactDOM from "react-dom"
import * as lodash from "lodash"
import { observable, computed, action } from "mobx"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminApp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { Admin } from "./Admin.js"
import { ChartEditorPage } from "./ChartEditorPage.js"
import { action } from "mobx"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminAppContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { Admin } from "./Admin.js"

export interface AdminAppContextType {
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observable, action, computed } from "mobx"
import { observer } from "mobx-react"

Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/AdminSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link } from "./Link.js"
import React from "react"
import * as React from "react"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome/index.js"
import {
faChartBar,
Expand Down
6 changes: 3 additions & 3 deletions adminSiteClient/BulkDownloadPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { AdminLayout } from "./AdminLayout.js"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"

@observer
export class BulkDownloadPage extends React.Component {
export class BulkDownloadPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand All @@ -20,7 +20,7 @@ export class BulkDownloadPage extends React.Component {
}
}

export class DownloadChartsSection extends React.Component {
export class DownloadChartsSection extends Component {
render() {
return (
<section>
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/BulkGrapherConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import {
chartBulkUpdateAllowedColumnNamesAndTypes,
WHITELISTED_SQL_COLUMN_NAMES,
Expand Down Expand Up @@ -130,7 +130,7 @@ const config: GrapherConfigGridEditorConfig = {
finalVariableLayerModificationFn: () => ({}),
}

export class BulkGrapherConfigEditorPage extends React.Component {
export class BulkGrapherConfigEditorPage extends Component {
render() {
return (
<AdminLayout title="Bulk chart editor">
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartEditorView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import {
observable,
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ChartIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"

Expand All @@ -15,7 +15,7 @@ import {
import { sortNumeric, SortOrder } from "@ourworldindata/utils"

@observer
export class ChartIndexPage extends React.Component {
export class ChartIndexPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import { runInAction, observable } from "mobx"
import { bind } from "decko"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/ChartRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observer } from "mobx-react"
import { action, runInAction } from "mobx"
import * as lodash from "lodash"
Expand Down
3 changes: 2 additions & 1 deletion adminSiteClient/ChartViewIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext, useEffect, useMemo, useState } from "react"
import { useContext, useEffect, useMemo, useState } from "react"
import * as React from "react"
import { Button, Flex, Input, Space, Table } from "antd"

import { AdminLayout } from "./AdminLayout.js"
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/ColorSchemeDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { computed, action } from "mobx"
import Select from "react-select"
import { GrapherChartOrMapType } from "@ourworldindata/types"
Expand Down Expand Up @@ -27,7 +27,7 @@ interface ColorSchemeDropdownProps {
}

@observer
export class ColorSchemeDropdown extends React.Component<ColorSchemeDropdownProps> {
export class ColorSchemeDropdown extends Component<ColorSchemeDropdownProps> {
static defaultProps = {
additionalOptions: [],
gradientColorCount: 6,
Expand Down
8 changes: 4 additions & 4 deletions adminSiteClient/Colorpicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component, Fragment } from "react"
import { action } from "mobx"
import { observer } from "mobx-react"
import { SketchPicker } from "react-color"
Expand All @@ -16,7 +16,7 @@ interface ColorpickerProps {
}

@observer
export class Colorpicker extends React.Component<ColorpickerProps> {
export class Colorpicker extends Component<ColorpickerProps> {
@action.bound onColor(color: string) {
if (color === "") {
this.props.onColor(undefined)
Expand All @@ -39,7 +39,7 @@ export class Colorpicker extends React.Component<ColorpickerProps> {
}

return (
<React.Fragment>
<Fragment>
<SketchPicker
disableAlpha
presetColors={availableColors.map((color) => ({
Expand All @@ -49,7 +49,7 @@ export class Colorpicker extends React.Component<ColorpickerProps> {
color={this.props.color}
onChange={(color) => this.onColor(color.hex)}
/>
</React.Fragment>
</Fragment>
)
}
}
8 changes: 4 additions & 4 deletions adminSiteClient/DatasetEditPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, runInAction, action } from "mobx"
import * as lodash from "lodash"
Expand Down Expand Up @@ -79,7 +79,7 @@ class DatasetEditable {
}

@observer
class DatasetTagEditor extends React.Component<{
class DatasetTagEditor extends Component<{
newDataset: DatasetEditable
availableTags: { id: number; name: string; parentName: string }[]
}> {
Expand All @@ -104,7 +104,7 @@ class DatasetTagEditor extends React.Component<{
}

@observer
class DatasetEditor extends React.Component<{ dataset: DatasetPageData }> {
class DatasetEditor extends Component<{ dataset: DatasetPageData }> {
static contextType = AdminAppContext
context!: AdminAppContextType
@observable newDataset!: DatasetEditable
Expand Down Expand Up @@ -405,7 +405,7 @@ class DatasetEditor extends React.Component<{ dataset: DatasetPageData }> {
}

@observer
export class DatasetEditPage extends React.Component<{ datasetId: number }> {
export class DatasetEditPage extends Component<{ datasetId: number }> {
static contextType = AdminAppContext
context!: AdminAppContextType
@observable dataset?: DatasetPageData
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/DatasetList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observable, action } from "mobx"
import { observer } from "mobx-react"
import * as lodash from "lodash"
Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/DatasetsIndexPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { observable, computed, action, runInAction } from "mobx"
import * as lodash from "lodash"
Expand All @@ -15,7 +15,7 @@ import {
} from "../adminShared/search.js"

@observer
export class DatasetsIndexPage extends React.Component {
export class DatasetsIndexPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand Down
4 changes: 2 additions & 2 deletions adminSiteClient/DeployStatusPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component } from "react"
import { observer } from "mobx-react"
import { action, observable, runInAction } from "mobx"

Expand All @@ -16,7 +16,7 @@ const statusLabel: Record<DeployStatus, string> = {
}

@observer
export class DeployStatusPage extends React.Component {
export class DeployStatusPage extends Component {
static contextType = AdminAppContext
context!: AdminAppContextType

Expand Down
8 changes: 4 additions & 4 deletions adminSiteClient/DimensionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component, Fragment } from "react"
import { observable, computed, action } from "mobx"
import { observer } from "mobx-react"
import { ChartDimension } from "@ourworldindata/grapher"
Expand Down Expand Up @@ -27,7 +27,7 @@ import { AbstractChartEditor } from "./AbstractChartEditor.js"
@observer
export class DimensionCard<
Editor extends AbstractChartEditor,
> extends React.Component<{
> extends Component<{
dimension: ChartDimension
editor: Editor
isDndEnabled?: boolean
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DimensionCard<
private get tableDisplaySettings() {
const { tableDisplay = {} } = this.props.dimension.display
return (
<React.Fragment>
<Fragment>
<hr className="ui divider" />
Table:
<Toggle
Expand All @@ -96,7 +96,7 @@ export class DimensionCard<
}}
/>
<hr className="ui divider" />
</React.Fragment>
</Fragment>
)
}

Expand Down
6 changes: 3 additions & 3 deletions adminSiteClient/EditTags.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { createRef, Component } from "react"
import { action } from "mobx"
import { observer } from "mobx-react"
import { DbChartTagJoin } from "@ourworldindata/utils"
Expand All @@ -9,15 +9,15 @@ import {
} from "react-tag-autocomplete"

@observer
export class EditTags extends React.Component<{
export class EditTags extends Component<{
tags: DbChartTagJoin[]
suggestions: DbChartTagJoin[]
onDelete: (index: number) => void
onAdd: (tag: DbChartTagJoin) => void
onSave: () => void
}> {
dismissable: boolean = true
reactTagsApi = React.createRef<ReactTagsAPI>()
reactTagsApi = createRef<ReactTagsAPI>()

@action.bound onClickSomewhere() {
if (this.dismissable) this.props.onSave()
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/EditableTags.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import * as lodash from "lodash"
import { observable, action } from "mobx"
import { observer } from "mobx-react"
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/EditorBasicTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import {
observable,
action,
Expand Down
20 changes: 10 additions & 10 deletions adminSiteClient/EditorColorScaleSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import { Component, Fragment } from "react"
import { action, computed, runInAction } from "mobx"
import { observer } from "mobx-react"
import Select from "react-select"
Expand Down Expand Up @@ -41,7 +41,7 @@ interface EditorColorScaleSectionFeatures {
}

@observer
export class EditorColorScaleSection extends React.Component<{
export class EditorColorScaleSection extends Component<{
scale: ColorScale
chartType: GrapherChartOrMapType
features: EditorColorScaleSectionFeatures
Expand All @@ -50,7 +50,7 @@ export class EditorColorScaleSection extends React.Component<{
}> {
render() {
return (
<React.Fragment>
<Fragment>
<ColorsSection
scale={this.props.scale}
onChange={this.props.onChange}
Expand All @@ -62,13 +62,13 @@ export class EditorColorScaleSection extends React.Component<{
features={this.props.features}
onChange={this.props.onChange}
/>
</React.Fragment>
</Fragment>
)
}
}

@observer
class ColorLegendSection extends React.Component<{
class ColorLegendSection extends Component<{
scale: ColorScale
features: EditorColorScaleSectionFeatures
onChange?: () => void
Expand Down Expand Up @@ -130,7 +130,7 @@ class ColorLegendSection extends React.Component<{
}

@observer
class ColorsSection extends React.Component<{
class ColorsSection extends Component<{
scale: ColorScale
chartType: GrapherChartOrMapType
showLineChartColors: boolean
Expand Down Expand Up @@ -275,7 +275,7 @@ class ColorsSection extends React.Component<{
}

@observer
class ColorSchemeEditor extends React.Component<{
class ColorSchemeEditor extends Component<{
scale: ColorScale
showLineChartColors: boolean
onChange?: () => void
Expand Down Expand Up @@ -319,7 +319,7 @@ class ColorSchemeEditor extends React.Component<{
}

@observer
class BinLabelView extends React.Component<{
class BinLabelView extends Component<{
scale: ColorScale
bin: ColorScaleBin
index: number
Expand Down Expand Up @@ -385,7 +385,7 @@ function populateManualBinValuesIfAutomatic(scale: ColorScale) {
}

@observer
class NumericBinView extends React.Component<{
class NumericBinView extends Component<{
scale: ColorScale
bin: NumericBin
index: number
Expand Down Expand Up @@ -492,7 +492,7 @@ class NumericBinView extends React.Component<{
}

@observer
class CategoricalBinView extends React.Component<{
class CategoricalBinView extends Component<{
scale: ColorScale
bin: CategoricalBin
showLineChartColors: boolean
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/EditorCustomizeTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import { observable, computed, action } from "mobx"
import { observer } from "mobx-react"
import {
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/EditorDataTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import * as React from "react"
import {
differenceOfSets,
moveArrayItemToIndex,
Expand Down
Loading

0 comments on commit 05dee10

Please sign in to comment.