Skip to content

Commit

Permalink
refactor(react-18): fix wrong replacement for forwardRef and class co…
Browse files Browse the repository at this point in the history
…mponents
  • Loading branch information
kabaros committed Sep 14, 2024
1 parent 5437911 commit d6875ea
Show file tree
Hide file tree
Showing 33 changed files with 162 additions and 87 deletions.
2 changes: 1 addition & 1 deletion components/button/src/dropdown-button/dropdown-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DropdownButton extends Component {
tabIndex,
type,
initialFocus,
dataTest,
dataTest = 'dhis2-uicore-dropdownbutton',
} = this.props
const open =
typeof this.props.open === 'boolean'
Expand Down
2 changes: 1 addition & 1 deletion components/button/src/split-button/split-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SplitButton extends Component {
disabled,
type,
tabIndex,
dataTest,
dataTest = 'dhis2-uicore-splitbutton',
initialFocus,
} = this.props

Expand Down
2 changes: 2 additions & 0 deletions components/calendar/src/calendar-input/calendar-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const CalendarInput = ({
width,
cellSize,
clearable,
dataTest = 'dhis2-uiwidgets-calendar-inputfield',
...rest
} = {}) => {
const ref = useRef()
Expand Down Expand Up @@ -72,6 +73,7 @@ export const CalendarInput = ({
<InputField
label={i18n.t('Pick a date')}
{...rest}
dataTest={dataTest}
type="text"
onFocus={onFocus}
value={date}
Expand Down
7 changes: 4 additions & 3 deletions components/calendar/src/stories/calendar-story-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { constants } from '@dhis2/multi-calendar-dates'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import { Calendar } from '../calendar/calendar.js'

const { calendars, numberingSystems } = constants
export const CalendarStoryWrapper = (props) => {
const {
calendar,
calendar = 'gregory',
locale,
timeZone,
dir,
component: Component,
component: Component = Calendar,
date,
weekDayFormat,
weekDayFormat = 'narrow',
} = props
const [selectedCalendar, setSelectedCalendar] = useState(calendar)
const [selectedNumberingSystem, setSelectedNumberingSystem] = useState()
Expand Down
10 changes: 9 additions & 1 deletion components/center/src/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import PropTypes from 'prop-types'
import React, { forwardRef } from 'react'

export const Center = forwardRef(
({ className, dataTest, children, position }, ref) => (
(
{
className,
dataTest = 'dhis2-uicore-centeredcontent',
children,
position = 'middle',
},
ref
) => (
<div
className={cx('center', className, position)}
data-test={dataTest}
Expand Down
6 changes: 1 addition & 5 deletions components/checkbox/src/checkbox-field/checkbox-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import { Checkbox } from '../checkbox/index.js'

const AddRequired = ({
label,
required,
dataTest = 'dhis2-uiwidgets-checkboxfield',
}) => (
const AddRequired = ({ label, required, dataTest }) => (
<React.Fragment>
{label}
{required && <Required dataTest={`${dataTest}-required`} />}
Expand Down
6 changes: 3 additions & 3 deletions components/checkbox/src/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Checkbox extends Component {

render() {
const {
checked,
indeterminate,
checked = false,
indeterminate = false,
className,
disabled,
error,
Expand All @@ -72,7 +72,7 @@ class Checkbox extends Component {
value,
warning,
dense,
dataTest,
dataTest = 'dhis2-uicore-checkbox',
} = this.props

const classes = cx({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { sharedPropTypes } from '@dhis2/ui-constants'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { FileInputField } from '../file-input-field/index.js'
import i18n from '../locales/index.js'
import { FileListItemWithRemove } from './file-list-item-with-remove.js'

// TODO: i18n
Expand Down Expand Up @@ -61,12 +62,12 @@ class FileInputFieldWithList extends Component {
render() {
const {
accept,
buttonLabel,
buttonLabel = () => i18n.t('Upload a file'),
className,
dataTest,
dataTest = 'dhis2-uiwidgets-fileinputfieldwithlist',
disabled,
error,
files,
files = [],
helpText,
initialFocus,
label,
Expand All @@ -76,8 +77,8 @@ class FileInputFieldWithList extends Component {
onBlur,
onFocus,
onKeyDown,
placeholder,
removeText,
placeholder = () => i18n.t('No file uploaded yet'),
removeText = () => i18n.t('Remove'),
required,
small,
tabIndex,
Expand Down
4 changes: 2 additions & 2 deletions components/file-input/src/file-input/file-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class FileInput extends Component {

render() {
const {
accept,
accept = '*',
buttonLabel,
className,
dataTest,
dataTest = 'dhis2-uicore-fileinput',
disabled,
error,
initialFocus,
Expand Down
2 changes: 1 addition & 1 deletion components/input/src/input-field/input-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class InputField extends React.Component {
validationText,
inputWidth,
autoComplete,
dataTest,
dataTest = 'dhis2-uiwidgets-inputfield',
} = this.props

return (
Expand Down
4 changes: 2 additions & 2 deletions components/input/src/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class Input extends Component {
const {
role,
className,
type,
type = 'text',
dense,
disabled,
readOnly,
Expand All @@ -148,7 +148,7 @@ export class Input extends Component {
min,
step,
autoComplete,
dataTest,
dataTest = 'dhis2-uicore-input',
} = this.props

return (
Expand Down
11 changes: 5 additions & 6 deletions components/logo/src/logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const blue = '#0080d4'
const white = '#ffffff'
const dark = '#212225'

export const LogoIcon = ({
className,
dataTest = 'dhis2-uicore-logowhite',
}) => <LogoIconSvg iconColor={blue} className={className} dataTest={dataTest} />
export const LogoIcon = ({ className, dataTest = 'dhis2-uicore-logoicon' }) => (
<LogoIconSvg iconColor={blue} className={className} dataTest={dataTest} />
)

LogoIcon.propTypes = {
className: PropTypes.string,
Expand All @@ -28,7 +27,7 @@ LogoIcon.propTypes = {

export const LogoIconWhite = ({
className,
dataTest = 'dhis2-uicore-logowhite',
dataTest = 'dhis2-uicore-logoiconwhite',
}) => (
<LogoIconSvg iconColor={white} className={className} dataTest={dataTest} />
)
Expand All @@ -38,7 +37,7 @@ LogoIconWhite.propTypes = {
dataTest: PropTypes.string,
}

export const Logo = ({ className, dataTest = 'dhis2-uicore-logowhite' }) => (
export const Logo = ({ className, dataTest = 'dhis2-uicore-logo' }) => (
<LogoSvg
iconColor={blue}
textColor={dark}
Expand Down
8 changes: 6 additions & 2 deletions components/popover/src/popover.e2e.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class PopperInBoxWithCenteredReferenceElement extends Component {
ref = createRef()

render() {
const { paddingTop, popoverHeight, popoverWidth, ...popoverProps } =
this.props
const {
paddingTop = 220,
popoverHeight = 200,
popoverWidth = 336,
...popoverProps
} = this.props
return (
<div style={{ ...boxStyle, paddingTop, height: paddingTop + 100 }}>
<div
Expand Down
2 changes: 1 addition & 1 deletion components/radio/src/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Radio extends Component {
value,
warning,
dense,
dataTest,
dataTest = 'dhis2-uicore-radio',
} = this.props

const classes = cx({
Expand Down
15 changes: 8 additions & 7 deletions components/select/src/multi-select-field/multi-select-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Box } from '@dhis2-ui/box'
import { Field } from '@dhis2-ui/field'
import PropTypes from 'prop-types'
import React from 'react'
import i18n from '../locales/index.js'
import { MultiSelect } from '../multi-select/index.js'

// TODO: translate
Expand All @@ -29,7 +30,7 @@ class MultiSelectField extends React.Component {
disabled,
warning,
loading,
selected,
selected = [],
tabIndex,
helpText,
validationText,
Expand All @@ -38,17 +39,17 @@ class MultiSelectField extends React.Component {
inputWidth,
children,
clearable,
clearText,
clearText = () => i18n.t('Clear'),
filterable,
filterPlaceholder,
filterPlaceholder = () => i18n.t('Type to filter options'),
placeholder,
prefix,
empty,
loadingText,
noMatchText,
empty = () => i18n.t('No data found'),
loadingText = () => i18n.t('Loading options'),
noMatchText = () => i18n.t('No options found'),
initialFocus,
dense,
dataTest,
dataTest = 'dhis2-uiwidgets-multiselectfield',
} = this.props

return (
Expand Down
15 changes: 8 additions & 7 deletions components/select/src/single-select-field/single-select-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Box } from '@dhis2-ui/box'
import { Field } from '@dhis2-ui/field'
import PropTypes from 'prop-types'
import React from 'react'
import i18n from '../locales/index.js'
import { SingleSelect } from '../single-select/index.js'

// TODO: translate
Expand All @@ -28,7 +29,7 @@ class SingleSelectField extends React.Component {
warning,
disabled,
loading,
selected,
selected = '',
tabIndex,
helpText,
validationText,
Expand All @@ -37,17 +38,17 @@ class SingleSelectField extends React.Component {
inputWidth,
children,
clearable,
clearText,
clearText = () => i18n.t('Clear'),
filterable,
filterPlaceholder,
filterPlaceholder = () => i18n.t('Type to filter options'),
placeholder,
prefix,
empty,
loadingText,
noMatchText,
empty = () => i18n.t('No data found'),
loadingText = () => i18n.t('Loading options'),
noMatchText = () => i18n.t('No options found'),
initialFocus,
dense,
dataTest,
dataTest = 'dhis2-uiwidgets-singleselectfield',
} = this.props

return (
Expand Down
6 changes: 1 addition & 5 deletions components/switch/src/switch-field/switch-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import { Switch } from '../switch/index.js'

const AddRequired = ({
label,
required,
dataTest = 'dhis2-uiwidgets-switchfield',
}) => (
const AddRequired = ({ label, required, dataTest }) => (
<React.Fragment>
{label}
{required && <Required dataTest={`${dataTest}-required`} />}
Expand Down
6 changes: 3 additions & 3 deletions components/switch/src/switch/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Switch extends Component {
render() {
const {
'aria-label': ariaLabel,
checked,
checked = false,
className,
disabled,
error,
Expand All @@ -59,8 +59,8 @@ class Switch extends Component {
value,
warning,
dense,
dataTest,
role,
dataTest = 'dhis2-uicore-switch',
role = 'switch',
} = this.props

const classes = cx({
Expand Down
10 changes: 9 additions & 1 deletion components/tab/src/tab/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import React, { useState, useEffect, useRef } from 'react'

export const Tab = React.forwardRef(
(
{ icon, onClick, selected, disabled, children, className, dataTest },
{
icon,
onClick,
selected,
disabled,
children,
className,
dataTest = 'dhis2-uicore-tab',
},
ref
) => {
let tabRef = useRef(null)
Expand Down
9 changes: 5 additions & 4 deletions components/table/src/data-table/data-table-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ export const DataTableCell = forwardRef(
(
{
active,
align,
align = 'left',
backgroundColor,
bordered,
children,
className,
colSpan,
dataTest,
dataTest = 'dhis2-uicore-datatablecell',
error,
fixed,
large,
left,

left = 'auto',
muted,
rowSpan,
role,
scope,
staticStyle,
tag,
valid,
width,
width = 'auto',
onClick,
...props
},
Expand Down
Loading

0 comments on commit d6875ea

Please sign in to comment.