Add DataTitle types

This commit is contained in:
Maciej Ziarkowski 2019-10-15 15:44:22 +01:00
parent f498f4730b
commit 0a1b41cc07
2 changed files with 33 additions and 6 deletions

View File

@ -3,7 +3,13 @@ import PropTypes from 'prop-types';
import Tooltip from '../../components/tooltip'; import Tooltip from '../../components/tooltip';
const DataTitle: React.FunctionComponent<any> = (props) => {
interface DataTitleProps {
title: string;
tooltip: string;
}
const DataTitle: React.FunctionComponent<DataTitleProps> = (props) => {
return ( return (
<dt> <dt>
{ props.title } { props.title }
@ -17,7 +23,16 @@ DataTitle.propTypes = {
tooltip: PropTypes.string tooltip: PropTypes.string
} }
const DataTitleCopyable: React.FunctionComponent<any> = (props) => { // TODO: remove any
interface DataTitleCopyableProps {
title: string;
tooltip: string;
slug: string;
disabled?: boolean;
copy: any; // TODO: type should be CopyProps, but that clashes with propTypes in some obscure way
}
const DataTitleCopyable: React.FunctionComponent<DataTitleCopyableProps> = (props) => { // TODO: remove any
return ( return (
<div className="data-title"> <div className="data-title">
{ props.tooltip? <Tooltip text={ props.tooltip } /> : null } { props.tooltip? <Tooltip text={ props.tooltip } /> : null }
@ -48,7 +63,8 @@ DataTitleCopyable.propTypes = {
copy: PropTypes.shape({ copy: PropTypes.shape({
copying: PropTypes.bool, copying: PropTypes.bool,
copyingKey: PropTypes.func, copyingKey: PropTypes.func,
toggleCopyAttribute: PropTypes.func toggleCopyAttribute: PropTypes.func,
toggleCopying: PropTypes.func
}) })
} }

View File

@ -24,10 +24,17 @@ interface DataContainerProps {
interface DataContainerState { interface DataContainerState {
error: string; error: string;
copying: boolean; copying: boolean;
keys_to_copy: object; keys_to_copy: {[key: string]: boolean};
building: Building building: Building
} }
interface CopyProps {
copying: boolean;
toggleCopying: () => void;
toggleCopyAttribute: (key: string) => void;
copyingKey: (key: string) => boolean;
}
/** /**
* Shared functionality for view/edit forms * Shared functionality for view/edit forms
* *
@ -212,11 +219,11 @@ const withCopyEdit = (WrappedComponent) => {
values_to_copy[key] = this.state.building[key] values_to_copy[key] = this.state.building[key]
} }
const data_string = JSON.stringify(values_to_copy); const data_string = JSON.stringify(values_to_copy);
const copy = { const copy: CopyProps = {
copying: this.state.copying, copying: this.state.copying,
toggleCopying: this.toggleCopying, toggleCopying: this.toggleCopying,
toggleCopyAttribute: this.toggleCopyAttribute, toggleCopyAttribute: this.toggleCopyAttribute,
copyingKey: (key) => this.state.keys_to_copy[key] copyingKey: (key: string) => this.state.keys_to_copy[key]
} }
return ( return (
<section <section
@ -289,3 +296,7 @@ const withCopyEdit = (WrappedComponent) => {
} }
export default withCopyEdit; export default withCopyEdit;
export {
CopyProps
};