Skip to content

Commit

Permalink
Convert some .js[x] -> .ts[x]
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jan 31, 2018
1 parent 0b292da commit f2238e9
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 52 deletions.
@@ -1,12 +1,13 @@
import React from 'react'
import { Component } from 'react'
import * as PropTypes from 'prop-types'
import {FromProjectVersionType} from '../../utils/prop-types-util'
import React, { ClassAttributes, ReactElement, StatelessComponent } from 'react'
import { Component } from 'react'
import {Icon, LockIcon} from '../../components'
import {FromProjectVersionType} from '../../utils/prop-types-util'
import {
SortableContainer,
SortableElement,
SortableHandle
SortableHandle,
WrappedComponent
} from 'react-sortable-hoc'
import {
Button,
Expand All @@ -26,16 +27,19 @@ export const DragHandle = SortableHandle(() =>
<Icon name='menu' className='n1' parentClassName='drag-handle'
title='click to drag' />)

export class Item extends Component {
static propTypes = {
interface ItemProps {
dispatch: (action: any) => void
removeVersion: (...args: any[]) => any,
value: any,
}

export class Item extends Component<ItemProps, {}> {
private static propTypes = {
value: FromProjectVersionType.isRequired,
removeVersion: PropTypes.func.isRequired
}
removeVersion = () => {
const { value: { version, projectSlug } } = this.props
this.props.removeVersion(projectSlug, version)
}
render () {

public render () {
const { value: { version, projectSlug } } = this.props
return <ListGroupItem className='v' >
<DragHandle />
Expand All @@ -49,15 +53,38 @@ export class Item extends Component {
</Button>
</ListGroupItem>
}

private removeVersion = () => {
const { value: { version, projectSlug } } = this.props
this.props.removeVersion(projectSlug, version)
}
}

const SortableItem = SortableElement(Item as any) as any

type EntityStatus = 'READONLY' | 'ACTIVE' | 'OBSOLETE'

interface VersionDto {
id: string
status: EntityStatus
}

interface FromProjectVersion {
projectSlug: string,
version: VersionDto
}

interface ItemsProps {
items: FromProjectVersion[]
removeVersion: (...args: any[]) => any
}
const SortableItem = SortableElement(Item)

class Items extends Component {
static propTypes = {
class Items extends Component<ItemsProps, {}> {
private static propTypes = {
items: PropTypes.arrayOf(FromProjectVersionType).isRequired,
removeVersion: PropTypes.func.isRequired
}
render () {
public render () {
const { items, removeVersion } = this.props
const sortableItems = items.map((value, index) => (
<SortableItem
Expand All @@ -81,18 +108,22 @@ class Items extends Component {
}
}

const SortableList = SortableContainer(Items)
const SortableList = SortableContainer(Items as any) as any

/**
* Draggable version priority list
*/
class DraggableVersionPanels extends Component {
static propTypes = {
class DraggableVersionPanels extends Component<{
selectedVersions: FromProjectVersion[];
onDraggableMoveEnd: (...args: any[]) => any;
removeVersion: (...args: any[]) => any;
}, {}> {
private static propTypes = {
selectedVersions: PropTypes.arrayOf(FromProjectVersionType).isRequired,
onDraggableMoveEnd: PropTypes.func.isRequired,
removeVersion: PropTypes.func.isRequired
}
render () {
public render () {
if (this.props.selectedVersions.length === 0) {
return (
<span className="no-v text-muted">
Expand Down
@@ -1,3 +1,4 @@
// @ts-check
import React from 'react'
import {storiesOf} from '@storybook/react'
import {Icon} from '../'
Expand Down
@@ -1,12 +1,19 @@
import React from 'react'
import * as PropTypes from 'prop-types'
import { isUndefined } from 'lodash'
import * as PropTypes from 'prop-types'
import React from 'react'

const Icon = ({
interface IconProps {
className?: string,
name: string,
parentClassName?: string,
title?: string,
}

const Icon: React.StatelessComponent<IconProps> = ({
name,
parentClassName,
className,
...props
...props,
}) => {
const svgIcon = `<use xlink:href="#Icon-${name}" />`
const parentCSS = isUndefined(parentClassName) ? '' : parentClassName
Expand All @@ -19,13 +26,13 @@ const Icon = ({
}

Icon.propTypes = {
className: PropTypes.string,
/**
* The name of the icon.
* See list.js in the same folder for possible icons.
*/
name: PropTypes.string.isRequired,
className: PropTypes.string,
parentClassName: PropTypes.string
parentClassName: PropTypes.string,
}

export default Icon
@@ -1,10 +1,8 @@
// @ts-check
import React from 'react'
import * as PropTypes from 'prop-types'
import React from 'react'
import Loading from 'react-loading'

/** @type { React.StatelessComponent<{className}> } */
const Loader = ({ className = 'loader' }) => {
const Loader: React.SFC<LoaderProps> = ({ className = 'loader' }) => {
return (
<span className={className}>
<span>
Expand All @@ -14,6 +12,10 @@ const Loader = ({ className = 'loader' }) => {
)
}

interface LoaderProps {
className: string
}

Loader.propTypes = {
className: PropTypes.string
}
Expand Down
@@ -1,17 +1,15 @@
import React from 'react'
import {Tooltip, OverlayTrigger} from 'react-bootstrap'
import {OverlayTrigger, Tooltip} from 'react-bootstrap'
import {Icon} from '../../components'
import {entityStatusPropType} from '../../utils/prop-types-util'
import {isEntityStatusReadOnly} from '../../utils/EnumValueUtils'
import {entityStatusPropType} from '../../utils/prop-types-util'

const DO_NOT_RENDER = null

/**
* Version Lock Icon with tooltip
*
* @type { React.StatelessComponent<{status}> }
*/
const LockIcon = ({status}) => {
const LockIcon: React.SFC<LockIconProps> = ({status}) => {
const tooltipReadOnly = <Tooltip id='tooltipreadonly'>Read only</Tooltip>
return isEntityStatusReadOnly(status)
? (
Expand All @@ -21,6 +19,11 @@ const LockIcon = ({status}) => {
)
: DO_NOT_RENDER
}

interface LockIconProps {
status: any // TODO should be one of entityStatuses
}

LockIcon.propTypes = {
status: entityStatusPropType
}
Expand Down
@@ -1,10 +1,9 @@
// @ts-check
import React from 'react'
import * as PropTypes from 'prop-types'
import React from 'react'

const ModalFooter: React.StatelessComponent<{children: any, props?: any}> = ({
children,
...props
...props,
}) => {
return (
<div className='modal-footer'
Expand All @@ -18,8 +17,8 @@ const ModalFooter: React.StatelessComponent<{children: any, props?: any}> = ({
ModalFooter.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node]
)
PropTypes.node,
])
}

export default ModalFooter
@@ -1,11 +1,8 @@
// @ts-check
import * as PropTypes from 'prop-types'
import React from 'react'
import { isEmpty, isUndefined } from 'lodash'

/** @type
* { React.StatelessComponent<{itemTitle, itemName, wordCount, props?}> } */
const CategoryItemMatrix = ({
const CategoryItemMatrix: React.SFC<{itemTitle, itemName, wordCount, props?}> = ({
itemTitle,
itemName,
wordCount,
Expand Down
@@ -1,6 +1,6 @@
// @ts-check
import * as PropTypes from 'prop-types'
import React, {StatelessComponent} from 'react'
import React from 'react'
import { ContentStates } from '../../constants/Options'
import dateUtil from '../../utils/DateHelper'
import { Button } from 'react-bootstrap'
Expand All @@ -15,7 +15,7 @@ const cssClass = {
needswork: 'warning'
}

/** @type { StatelessComponent<{key?, dateLabel?, date?, wordCount?, selectedDay?, selectedContentState?, handleSelectedDayChanged?, props?}> } */
/** @type { React.StatelessComponent<{key?, dateLabel?, date?, wordCount?, selectedDay?, selectedContentState?, handleSelectedDayChanged?, props?}> } */
const DayMatrix = ({
dateLabel,
date,
Expand Down
@@ -1,6 +1,6 @@
import React from 'react'
import * as PropTypes from 'prop-types'
import Icon from '../../components'
import React from 'react'
import { Icon } from '../../components'
import cx from 'classnames'

const statusNames = {
Expand All @@ -10,16 +10,20 @@ const statusNames = {
approved: 'Approved'
}

interface TransUnitStatusProps {
phrase: any
}

/**
* Status indicator showing the state of the translations
* and some other metadata about a phrase.
*/
class TransUnitStatus extends React.Component {
static propTypes = {
class TransUnitStatus extends React.Component<TransUnitStatusProps, any> {
private static propTypes = {
phrase: PropTypes.object.isRequired
}

render () {
public render () {
const phrase = this.props.phrase
const className = cx('TransUnit-status', {
// loading if there is an in-progress save object
Expand All @@ -29,7 +33,7 @@ class TransUnitStatus extends React.Component {
const comments = phrase.comments
? (
<li className="TransUnit-metaDataItem TransUnit-metaDataComments">
<button tabIndex="-1"
<button tabIndex={-1}
className="TransUnit-metaDataButton"
title={phrase.comments + ' comments'}>
<Icon name="comment" title="Comments" />
Expand All @@ -43,7 +47,7 @@ class TransUnitStatus extends React.Component {
const errors = phrase.errors
? (
<li className="TransUnit-metaDataItem TransUnit-metaDataErrors">
<button tabIndex="-1"
<button tabIndex={-1}
className="TransUnit-metaDataButton"
title="1 Error">
<span className="u-textDanger">
Expand Down

0 comments on commit f2238e9

Please sign in to comment.