Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Migrate NullableBooleanInput to TypeScript #3523

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import React, { FunctionComponent } from 'react';
import PropTypes from 'prop-types';
import TextField from '@material-ui/core/TextField';
import TextField, { TextFieldProps } from '@material-ui/core/TextField';
import MenuItem from '@material-ui/core/MenuItem';
import { makeStyles } from '@material-ui/core/styles';
import classnames from 'classnames';
import { useInput, useTranslate, FieldTitle } from 'ra-core';
import { useInput, useTranslate, FieldTitle, InputProps } from 'ra-core';

import sanitizeRestProps from './sanitizeRestProps';
import InputHelperText from './InputHelperText';
Expand All @@ -13,19 +13,21 @@ const useStyles = makeStyles(theme => ({
input: { width: theme.spacing(16) },
}));

const getBooleanFromString = value => {
const getBooleanFromString = (value: string): boolean | null => {
if (value === 'true') return true;
if (value === 'false') return false;
return null;
};

const getStringFromBoolean = value => {
const getStringFromBoolean = (value?: boolean | null): string => {
if (value === true) return 'true';
if (value === false) return 'false';
return '';
};

const NullableBooleanInput = ({
const NullableBooleanInput: FunctionComponent<
InputProps<TextFieldProps> & Omit<TextFieldProps, 'label' | 'helperText'>
> = ({
className,
helperText,
label,
Expand All @@ -38,7 +40,7 @@ const NullableBooleanInput = ({
validate,
...rest
}) => {
const classes = useStyles();
const classes = useStyles({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curiosity, but why is the impact of the brackets as arguments of useStyles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a nutshell, it's a workaround for TypeScript

const translate = useTranslate();

const {
Expand Down