diff --git a/examples/demo/package.json b/examples/demo/package.json index 7f4ba46590b..e216c13bae9 100644 --- a/examples/demo/package.json +++ b/examples/demo/package.json @@ -7,20 +7,20 @@ "@material-ui/icons": "^4.9.1", "@types/inflection": "^1.5.28", "@types/recharts": "^1.8.10", - "data-generator-retail": "^3.0.0", + "data-generator-retail": "^3.9.0-beta.1", "fakerest": "~2.1.0", "fetch-mock": "~6.3.0", "json-graphql-server": "~2.1.3", "proxy-polyfill": "^0.3.0", - "ra-data-fakerest": "^3.0.0", - "ra-data-graphql-simple": "^3.0.0", - "ra-data-simple-rest": "^3.0.0", - "ra-i18n-polyglot": "^3.0.0", - "ra-input-rich-text": "^3.0.0", - "ra-language-english": "^3.0.0", - "ra-language-french": "^3.0.0", + "ra-data-fakerest": "^3.9.0-beta.1", + "ra-data-graphql-simple": "^3.9.0-beta.1", + "ra-data-simple-rest": "^3.9.0-beta.1", + "ra-i18n-polyglot": "^3.9.0-beta.1", + "ra-input-rich-text": "^3.9.0-beta.1", + "ra-language-english": "^3.9.0-beta.1", + "ra-language-french": "^3.9.0-beta.1", "react": "^16.9.0", - "react-admin": "^3.0.0", + "react-admin": "^3.9.0-beta.1", "react-app-polyfill": "^1.0.4", "react-dom": "^16.9.0", "react-redux": "^7.1.0", @@ -54,4 +54,4 @@ "source-map-explorer": "^2.0.0", "typescript": "^4.0.2" } -} \ No newline at end of file +} diff --git a/examples/simple/package.json b/examples/simple/package.json index 6bbc6929d35..f8ec4344d40 100644 --- a/examples/simple/package.json +++ b/examples/simple/package.json @@ -37,13 +37,13 @@ "@babel/polyfill": "^7.10.4", "@material-ui/core": "^4.10.0", "@material-ui/icons": "^4.9.1", - "ra-data-fakerest": "^3.0.0", - "ra-i18n-polyglot": "^3.0.0", - "ra-input-rich-text": "^3.0.0", - "ra-language-english": "^3.0.0", - "ra-language-french": "^3.0.0", + "ra-data-fakerest": "^3.9.0-beta.1", + "ra-i18n-polyglot": "^3.9.0-beta.1", + "ra-input-rich-text": "^3.9.0-beta.1", + "ra-language-english": "^3.9.0-beta.1", + "ra-language-french": "^3.9.0-beta.1", "react": "^16.9.0", - "react-admin": "^3.0.0", + "react-admin": "^3.9.0-beta.1", "react-dom": "^16.9.0" } } diff --git a/examples/tutorial/package.json b/examples/tutorial/package.json index 308f30abdd4..5b527112d77 100644 --- a/examples/tutorial/package.json +++ b/examples/tutorial/package.json @@ -4,9 +4,9 @@ "private": true, "dependencies": { "@material-ui/core": "^4.10.0", - "ra-data-json-server": "^3.0.0", + "ra-data-json-server": "^3.9.0-beta.1", "react": "^16.9.0", - "react-admin": "^3.0.0", + "react-admin": "^3.9.0-beta.1", "react-dom": "^16.9.0", "react-scripts": "^3.0.0" }, @@ -21,4 +21,4 @@ "not ie <= 11", "not op_mini all" ] -} \ No newline at end of file +} diff --git a/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts b/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts index 09379a9b2cb..dd0ffdc1236 100644 --- a/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts +++ b/packages/ra-core/src/controller/input/useReferenceArrayInputController.ts @@ -216,7 +216,7 @@ interface ReferenceArrayInputProps { } interface Option { - basePath: string; + basePath?: string; filter?: any; filterToQuery?: (filter: any) => any; input: FieldInputProps; @@ -224,7 +224,7 @@ interface Option { perPage?: number; record?: Record; reference: string; - resource: string; + resource?: string; sort?: SortPayload; source: string; } diff --git a/packages/ra-core/src/controller/useShowController.ts b/packages/ra-core/src/controller/useShowController.ts index 93312ca7b0b..aaaf359d7fa 100644 --- a/packages/ra-core/src/controller/useShowController.ts +++ b/packages/ra-core/src/controller/useShowController.ts @@ -15,7 +15,7 @@ export interface ShowProps { hasShow?: boolean; hasList?: boolean; id: Identifier; - resource: string; + resource?: string; [key: string]: any; } diff --git a/packages/ra-core/src/dataProvider/index.ts b/packages/ra-core/src/dataProvider/index.ts index 82d61c50684..e55780331d3 100644 --- a/packages/ra-core/src/dataProvider/index.ts +++ b/packages/ra-core/src/dataProvider/index.ts @@ -7,11 +7,11 @@ import Query from './Query'; import cacheDataProviderProxy from './cacheDataProviderProxy'; import undoableEventEmitter from './undoableEventEmitter'; import useDataProvider from './useDataProvider'; -import useMutation from './useMutation'; -import useQuery from './useQuery'; -import useQueryWithStore from './useQueryWithStore'; +import useMutation, { UseMutationValue } from './useMutation'; +import useQuery, { UseQueryValue } from './useQuery'; +import useQueryWithStore, { QueryOptions } from './useQueryWithStore'; import withDataProvider from './withDataProvider'; -import useGetOne from './useGetOne'; +import useGetOne, { UseGetOneHookValue } from './useGetOne'; import useGetList from './useGetList'; import useGetMany from './useGetMany'; import useGetManyReference from './useGetManyReference'; @@ -24,6 +24,13 @@ import useDeleteMany from './useDeleteMany'; import useRefreshWhenVisible from './useRefreshWhenVisible'; import useIsAutomaticRefreshEnabled from './useIsAutomaticRefreshEnabled'; +export type { + QueryOptions, + UseMutationValue, + UseQueryValue, + UseGetOneHookValue, +}; + export { cacheDataProviderProxy, convertLegacyDataProvider, diff --git a/packages/ra-core/src/types.ts b/packages/ra-core/src/types.ts index 16e7dc520bb..465046995ff 100644 --- a/packages/ra-core/src/types.ts +++ b/packages/ra-core/src/types.ts @@ -387,12 +387,14 @@ export type LoginComponent = ComponentType; export type DashboardComponent = ComponentType; export interface LayoutProps { + appBar?: ComponentType; dashboard?: DashboardComponent; logout?: ReactNode; menu?: ComponentType<{ logout?: ReactNode; hasDashboard?: boolean; }>; + sideBar?: ComponentType; theme?: ThemeOptions; title?: TitleComponent; } diff --git a/packages/ra-data-fakerest/package.json b/packages/ra-data-fakerest/package.json index 6c7632990ab..7bec2b4a65d 100644 --- a/packages/ra-data-fakerest/package.json +++ b/packages/ra-data-fakerest/package.json @@ -44,6 +44,6 @@ "rimraf": "^2.6.3" }, "peerDependencies": { - "ra-core": "^3.0.0" + "ra-core": "^3.9.0-beta.1" } } diff --git a/packages/ra-data-graphql-simple/package.json b/packages/ra-data-graphql-simple/package.json index 883d26d5d43..0f9e1650ad8 100644 --- a/packages/ra-data-graphql-simple/package.json +++ b/packages/ra-data-graphql-simple/package.json @@ -40,7 +40,7 @@ }, "peerDependencies": { "graphql": "^14.1.1", - "ra-core": "^3.0.0" + "ra-core": "^3.9.0-beta.1" }, "devDependencies": { "cross-env": "^5.2.0", diff --git a/packages/ra-data-graphql/package.json b/packages/ra-data-graphql/package.json index a0cb5128ff3..bfc83bea35b 100644 --- a/packages/ra-data-graphql/package.json +++ b/packages/ra-data-graphql/package.json @@ -40,7 +40,7 @@ }, "peerDependencies": { "graphql": "^14.1.1", - "ra-core": "^3.0.0" + "ra-core": "^3.9.0-beta.1" }, "devDependencies": { "cross-env": "^5.2.0", diff --git a/packages/ra-data-simple-rest/package.json b/packages/ra-data-simple-rest/package.json index aaa387686db..1fe87910123 100644 --- a/packages/ra-data-simple-rest/package.json +++ b/packages/ra-data-simple-rest/package.json @@ -32,6 +32,6 @@ "rimraf": "^2.6.3" }, "peerDependencies": { - "ra-core": "^3.0.0" + "ra-core": "^3.9.0-beta.1" } } diff --git a/packages/ra-input-rich-text/package.json b/packages/ra-input-rich-text/package.json index 75010a3f86a..3ab1800dc4e 100644 --- a/packages/ra-input-rich-text/package.json +++ b/packages/ra-input-rich-text/package.json @@ -40,8 +40,8 @@ "watch": "tsc --outDir esm --module es2015 --watch" }, "peerDependencies": { - "ra-core": "^3.0.0", - "ra-ui-materialui": "^4.3.3", + "ra-core": "^3.9.0-beta.1", + "ra-ui-materialui": "^3.9.0-beta.1", "react": "^16.9.0", "react-dom": "^16.9.0" }, diff --git a/packages/ra-ui-materialui/package.json b/packages/ra-ui-materialui/package.json index c99d44973b4..6aa5f4a44a6 100644 --- a/packages/ra-ui-materialui/package.json +++ b/packages/ra-ui-materialui/package.json @@ -56,7 +56,7 @@ "@material-ui/styles": "^4.3.3", "final-form": "^4.18.5", "final-form-arrays": "^3.0.1", - "ra-core": "^3.0.0", + "ra-core": "^3.9.0-beta.1", "react": "^16.9.0", "react-dom": "^16.9.0", "react-final-form": "^6.3.3", diff --git a/packages/ra-ui-materialui/src/button/Button.tsx b/packages/ra-ui-materialui/src/button/Button.tsx index 966afe6a80e..2a61a2ab2d3 100644 --- a/packages/ra-ui-materialui/src/button/Button.tsx +++ b/packages/ra-ui-materialui/src/button/Button.tsx @@ -13,6 +13,7 @@ import { ButtonProps as MuiButtonProps } from '@material-ui/core/Button'; import { Theme } from '@material-ui/core'; import classnames from 'classnames'; import { Record, RedirectionSideEffect, useTranslate } from 'ra-core'; +import { LocationDescriptor } from 'history'; /** * A generic Button with side icon. Only the icon is displayed on small screens. @@ -133,7 +134,7 @@ interface Props { className?: string; color?: MuiPropTypes.Color; component?: ReactNode; - to?: string | { pathname: string; search: string }; + to?: string | LocationDescriptor; disabled?: boolean; label?: string; size?: 'small' | 'medium' | 'large'; diff --git a/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx b/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx index 751e62821f7..835f088f112 100644 --- a/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx +++ b/packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx @@ -132,7 +132,7 @@ interface Props { undoable?: boolean; } -type DeleteWithConfirmButtonProps = Props & ButtonProps; +export type DeleteWithConfirmButtonProps = Props & ButtonProps; DeleteWithConfirmButton.propTypes = { basePath: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/button/index.ts b/packages/ra-ui-materialui/src/button/index.ts index 7dc42820d83..d48224d852b 100644 --- a/packages/ra-ui-materialui/src/button/index.ts +++ b/packages/ra-ui-materialui/src/button/index.ts @@ -2,12 +2,16 @@ import BulkDeleteButton from './BulkDeleteButton'; import BulkDeleteWithConfirmButton from './BulkDeleteWithConfirmButton'; import BulkDeleteWithUndoButton from './BulkDeleteWithUndoButton'; import BulkExportButton from './BulkExportButton'; -import Button from './Button'; +import Button, { ButtonProps } from './Button'; import CloneButton from './CloneButton'; import CreateButton from './CreateButton'; -import DeleteButton from './DeleteButton'; -import DeleteWithConfirmButton from './DeleteWithConfirmButton'; -import DeleteWithUndoButton from './DeleteWithUndoButton'; +import DeleteButton, { DeleteButtonProps } from './DeleteButton'; +import DeleteWithConfirmButton, { + DeleteWithConfirmButtonProps, +} from './DeleteWithConfirmButton'; +import DeleteWithUndoButton, { + DeleteWithUndoButtonProps, +} from './DeleteWithUndoButton'; import EditButton from './EditButton'; import ExportButton from './ExportButton'; import ListButton from './ListButton'; @@ -17,6 +21,13 @@ import SortButton from './SortButton'; import RefreshButton from './RefreshButton'; import RefreshIconButton from './RefreshIconButton'; +export type { + ButtonProps, + DeleteButtonProps, + DeleteWithConfirmButtonProps, + DeleteWithUndoButtonProps, +}; + export { BulkDeleteButton, BulkDeleteWithConfirmButton, diff --git a/packages/ra-ui-materialui/src/detail/Show.js b/packages/ra-ui-materialui/src/detail/Show.tsx similarity index 93% rename from packages/ra-ui-materialui/src/detail/Show.js rename to packages/ra-ui-materialui/src/detail/Show.tsx index 2729ea426fb..e5e7cf0cb46 100644 --- a/packages/ra-ui-materialui/src/detail/Show.js +++ b/packages/ra-ui-materialui/src/detail/Show.tsx @@ -4,10 +4,11 @@ import PropTypes from 'prop-types'; import Card from '@material-ui/core/Card'; import { makeStyles } from '@material-ui/core/styles'; import classnames from 'classnames'; -import { useShowController } from 'ra-core'; +import { ShowControllerProps, useShowController } from 'ra-core'; import DefaultActions from './ShowActions'; import TitleForRecord from '../layout/TitleForRecord'; +import { ShowProps } from '../types'; /** * Page component for the Show view @@ -52,7 +53,9 @@ import TitleForRecord from '../layout/TitleForRecord'; * ); * export default App; */ -const Show = props => ; +const Show = (props: ShowProps) => ( + +); Show.propTypes = { actions: PropTypes.element, @@ -69,7 +72,11 @@ Show.propTypes = { title: PropTypes.node, }; -export const ShowView = props => { +interface ShowViewProps + extends ShowProps, + Omit {} + +export const ShowView = (props: ShowViewProps) => { const { actions, aside, @@ -207,6 +214,6 @@ const sanitizeRestProps = ({ permissions, translate, ...rest -}) => rest; +}: any) => rest; export default Show; diff --git a/packages/ra-ui-materialui/src/detail/ShowActions.js b/packages/ra-ui-materialui/src/detail/ShowActions.tsx similarity index 82% rename from packages/ra-ui-materialui/src/detail/ShowActions.js rename to packages/ra-ui-materialui/src/detail/ShowActions.tsx index 960f19f69c2..291ed17ae4c 100644 --- a/packages/ra-ui-materialui/src/detail/ShowActions.js +++ b/packages/ra-ui-materialui/src/detail/ShowActions.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import PropTypes from 'prop-types'; +import { Record } from 'ra-core'; import { EditButton } from '../button'; import TopToolbar from '../layout/TopToolbar'; @@ -12,7 +13,7 @@ const sanitizeRestProps = ({ hasList, resource, ...rest -}) => rest; +}: any) => rest; /** * Action Toolbar for the Show view @@ -39,12 +40,27 @@ const sanitizeRestProps = ({ * * ); */ -const ShowActions = ({ basePath, className, data, hasEdit, ...rest }) => ( +const ShowActions = ({ + basePath, + className, + data, + hasEdit, + ...rest +}: ShowActionsProps) => ( {hasEdit && } ); +export interface ShowActionsProps { + basePath?: string; + className?: string; + data?: Record; + hasEdit?: boolean; + hasList?: boolean; + resource?: string; +} + ShowActions.propTypes = { basePath: PropTypes.string, className: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/detail/SimpleShowLayout.js b/packages/ra-ui-materialui/src/detail/SimpleShowLayout.tsx similarity index 88% rename from packages/ra-ui-materialui/src/detail/SimpleShowLayout.js rename to packages/ra-ui-materialui/src/detail/SimpleShowLayout.tsx index 8c73d9ef6a0..5b48b7c78a6 100644 --- a/packages/ra-ui-materialui/src/detail/SimpleShowLayout.js +++ b/packages/ra-ui-materialui/src/detail/SimpleShowLayout.tsx @@ -1,7 +1,8 @@ import * as React from 'react'; -import { Children, isValidElement, cloneElement } from 'react'; +import { Children, isValidElement, cloneElement, ReactNode } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; +import { Record } from 'ra-core'; import CardContentInner from '../layout/CardContentInner'; import Labeled from '../input/Labeled'; @@ -16,7 +17,7 @@ const sanitizeRestProps = ({ initialValues, translate, ...rest -}) => rest; +}: any) => rest; /** * Simple Layout for a Show view, showing fields in one column. @@ -58,14 +59,14 @@ const SimpleShowLayout = ({ resource, version, ...rest -}) => ( +}: SimpleShowLayoutProps) => ( {Children.map(children, field => - field && isValidElement(field) ? ( + field && isValidElement(field) ? (
); +export interface SimpleShowLayoutProps { + basePath?: string; + className?: string; + children: ReactNode; + record?: Record; + resource?: string; + version?: number; +} + SimpleShowLayout.propTypes = { basePath: PropTypes.string, className: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/detail/TabbedShowLayout.js b/packages/ra-ui-materialui/src/detail/TabbedShowLayout.tsx similarity index 87% rename from packages/ra-ui-materialui/src/detail/TabbedShowLayout.js rename to packages/ra-ui-materialui/src/detail/TabbedShowLayout.tsx index 0566c0fbd12..cfb87ce4ef2 100644 --- a/packages/ra-ui-materialui/src/detail/TabbedShowLayout.js +++ b/packages/ra-ui-materialui/src/detail/TabbedShowLayout.tsx @@ -1,13 +1,20 @@ import * as React from 'react'; -import { Children, cloneElement, isValidElement } from 'react'; +import { + Children, + cloneElement, + isValidElement, + ReactElement, + ReactNode, +} from 'react'; import PropTypes from 'prop-types'; import Divider from '@material-ui/core/Divider'; import { Route } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { useRouteMatch } from 'react-router-dom'; -import { escapePath } from 'ra-core'; +import { escapePath, Record } from 'ra-core'; import TabbedShowLayoutTabs, { getTabFullPath } from './TabbedShowLayoutTabs'; +import { ClassesOverride } from '../types'; const sanitizeRestProps = ({ children, @@ -21,7 +28,7 @@ const sanitizeRestProps = ({ translate, tabs, ...rest -}) => rest; +}: any) => rest; const useStyles = makeStyles( theme => ({ @@ -73,7 +80,7 @@ const useStyles = makeStyles( * ); * export default App; */ -const TabbedShowLayout = props => { +const TabbedShowLayout = (props: TabbedShowLayoutProps) => { const { basePath, children, @@ -119,6 +126,18 @@ const TabbedShowLayout = props => { ); }; +export interface TabbedShowLayoutProps { + basePath?: string; + className?: string; + classes?: ClassesOverride; + children: ReactNode; + record?: Record; + resource?: string; + tabs: ReactElement; + value?: any; + version?: number; +} + TabbedShowLayout.propTypes = { children: PropTypes.node, className: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.js b/packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.tsx similarity index 91% rename from packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.js rename to packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.tsx index 610427e3e98..4b2ef9c4a15 100644 --- a/packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.js +++ b/packages/ra-ui-materialui/src/detail/TabbedShowLayoutTabs.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Children, cloneElement, isValidElement } from 'react'; +import { Children, cloneElement, FC, isValidElement } from 'react'; import PropTypes from 'prop-types'; import Tabs from '@material-ui/core/Tabs'; import { useLocation, useRouteMatch } from 'react-router-dom'; @@ -9,7 +9,7 @@ export const getTabFullPath = (tab, index, baseUrl) => tab.props.path ? `/${tab.props.path}` : index > 0 ? `/${index}` : '' }`; -const TabbedShowLayoutTabs = ({ children, ...rest }) => { +const TabbedShowLayoutTabs: FC = ({ children, ...rest }) => { const location = useLocation(); const match = useRouteMatch(); diff --git a/packages/ra-ui-materialui/src/detail/index.js b/packages/ra-ui-materialui/src/detail/index.ts similarity index 100% rename from packages/ra-ui-materialui/src/detail/index.js rename to packages/ra-ui-materialui/src/detail/index.ts diff --git a/packages/ra-ui-materialui/src/form/SimpleForm.tsx b/packages/ra-ui-materialui/src/form/SimpleForm.tsx index 061d3f92a06..39b985ca4d2 100644 --- a/packages/ra-ui-materialui/src/form/SimpleForm.tsx +++ b/packages/ra-ui-materialui/src/form/SimpleForm.tsx @@ -1,5 +1,11 @@ import * as React from 'react'; -import { Children, FC, ReactElement, HtmlHTMLAttributes } from 'react'; +import { + Children, + FC, + ReactElement, + ReactNode, + HtmlHTMLAttributes, +} from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { @@ -83,6 +89,7 @@ export interface SimpleFormProps 'defaultValue' | 'onSubmit' | 'children' > { basePath?: string; + children: ReactNode; className?: string; initialValues?: any; margin?: 'none' | 'normal' | 'dense'; diff --git a/packages/ra-ui-materialui/src/form/TabbedForm.tsx b/packages/ra-ui-materialui/src/form/TabbedForm.tsx index 945e3dfcf62..1559ac73288 100644 --- a/packages/ra-ui-materialui/src/form/TabbedForm.tsx +++ b/packages/ra-ui-materialui/src/form/TabbedForm.tsx @@ -4,6 +4,7 @@ import { isValidElement, FC, ReactElement, + ReactNode, HtmlHTMLAttributes, } from 'react'; import PropTypes from 'prop-types'; @@ -124,6 +125,7 @@ export interface TabbedFormProps 'defaultValue' | 'onSubmit' | 'children' > { basePath?: string; + children: ReactNode; className?: string; initialValues?: any; margin?: 'none' | 'normal' | 'dense'; diff --git a/packages/ra-ui-materialui/src/form/index.tsx b/packages/ra-ui-materialui/src/form/index.tsx index 8fc6bc19c28..f47440d211c 100644 --- a/packages/ra-ui-materialui/src/form/index.tsx +++ b/packages/ra-ui-materialui/src/form/index.tsx @@ -1,13 +1,13 @@ import FormInput from './FormInput'; import FormTab from './FormTab'; -import SimpleForm from './SimpleForm'; +import SimpleForm, { SimpleFormProps } from './SimpleForm'; import SimpleFormIterator from './SimpleFormIterator'; -import TabbedForm from './TabbedForm'; +import TabbedForm, { TabbedFormProps } from './TabbedForm'; import TabbedFormTabs from './TabbedFormTabs'; import Toolbar, { ToolbarProps } from './Toolbar'; import getFormInitialValues from './getFormInitialValues'; -export type { ToolbarProps }; +export type { SimpleFormProps, TabbedFormProps, ToolbarProps }; export { FormInput, diff --git a/packages/ra-ui-materialui/src/input/Labeled.tsx b/packages/ra-ui-materialui/src/input/Labeled.tsx index 1d18c84aa74..d2b6c968a66 100644 --- a/packages/ra-ui-materialui/src/input/Labeled.tsx +++ b/packages/ra-ui-materialui/src/input/Labeled.tsx @@ -32,13 +32,13 @@ export interface LabeledProps { className?: string; classes?: object; fullWidth?: boolean; - id: string; - input: any; - isRequired: boolean; + id?: string; + input?: any; + isRequired?: boolean; label?: string | ReactElement; - meta: any; - resource: string; - source: string; + meta?: any; + resource?: string; + source?: string; [key: string]: any; } /** diff --git a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.tsx similarity index 83% rename from packages/ra-ui-materialui/src/input/ReferenceArrayInput.js rename to packages/ra-ui-materialui/src/input/ReferenceArrayInput.tsx index f6e2c9b691e..a138ea23966 100644 --- a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js +++ b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.tsx @@ -1,15 +1,33 @@ import * as React from 'react'; +import { FC, ReactElement } from 'react'; import PropTypes from 'prop-types'; import { + InputProps, useReferenceArrayInputController, useInput, useTranslate, + SortPayload, + PaginationPayload, + Translate, } from 'ra-core'; import sanitizeInputProps from './sanitizeRestProps'; import LinearProgress from '../layout/LinearProgress'; -import Labeled from '../input/Labeled'; +import Labeled from './Labeled'; import ReferenceError from './ReferenceError'; +import { FieldInputProps, FieldMetaState } from 'react-final-form'; + +export interface ReferenceArrayInputProps extends InputProps { + allowEmpty?: boolean; + basePath?: string; + children: ReactElement; + classes?: any; + className?: string; + label?: string; + reference: string; + resource?: string; + [key: string]: any; +} /** * An Input component for fields containing a list of references to another resource. @@ -89,7 +107,7 @@ import ReferenceError from './ReferenceError'; * * */ -const ReferenceArrayInput = ({ +const ReferenceArrayInput: FC = ({ children, id: idOverride, onBlur, @@ -171,7 +189,34 @@ const sanitizeRestProps = ({ perPage, referenceSource, ...rest -}) => sanitizeInputProps(rest); +}: any) => sanitizeInputProps(rest); + +export interface ReferenceArrayInputViewProps { + allowEmpty?: boolean; + basePath?: string; + children: ReactElement; + choices: any[]; + classes?: object; + className?: string; + error?: string; + helperText?: string | boolean; + id: string; + input: FieldInputProps; + isRequired: boolean; + label?: string; + loading: boolean; + meta: FieldMetaState; + onChange: any; + options?: any; + reference: string; + resource?: string; + setFilter: (v: string) => void; + setPagination: (pagination: PaginationPayload) => void; + setSort: (sort: SortPayload, order?: string) => void; + source: string; + translate: Translate; + warning?: string; +} export const ReferenceArrayInputView = ({ allowEmpty, @@ -195,7 +240,7 @@ export const ReferenceArrayInputView = ({ translate, warning, ...rest -}) => { +}: ReferenceArrayInputViewProps) => { const translatedLabel = translate( label || `resources.${resource}.fields.${source}`, { _: label } diff --git a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx index eec311a2d95..b59967c90d7 100644 --- a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx @@ -140,9 +140,7 @@ const useStyles = makeStyles( * { id: 'photography', name: 'myroot.tags.photography' }, * ]; */ -const SelectArrayInput: FunctionComponent< - ChoicesProps & InputProps & FormControlProps -> = props => { +const SelectArrayInput: FunctionComponent = props => { const { choices = [], classes: classesOverride, @@ -271,6 +269,17 @@ const SelectArrayInput: FunctionComponent< ); }; +interface SelectArrayInputProps + extends Omit, + Omit, 'source'>, + Omit< + FormControlProps, + 'defaultValue' | 'onBlur' | 'onChange' | 'onFocus' + > { + choices?: object[]; + source?: string; +} + SelectArrayInput.propTypes = { choices: PropTypes.arrayOf(PropTypes.object), classes: PropTypes.object, diff --git a/packages/ra-ui-materialui/src/layout/Sidebar.tsx b/packages/ra-ui-materialui/src/layout/Sidebar.tsx index 3f733f0284d..b896e5b0237 100644 --- a/packages/ra-ui-materialui/src/layout/Sidebar.tsx +++ b/packages/ra-ui-materialui/src/layout/Sidebar.tsx @@ -1,11 +1,12 @@ import * as React from 'react'; -import { Children, cloneElement } from 'react'; +import { Children, cloneElement, ReactElement } from 'react'; import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; -import { Drawer, useMediaQuery, Theme } from '@material-ui/core'; +import { Drawer, DrawerProps, useMediaQuery, Theme } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import lodashGet from 'lodash/get'; import { setSidebarVisibility, ReduxState, useLocale } from 'ra-core'; +import { ClassesOverride } from '../types'; export const DRAWER_WIDTH = 240; export const CLOSED_DRAWER_WIDTH = 55; @@ -57,7 +58,14 @@ const useStyles = makeStyles( { name: 'RaSidebar' } ); -const Sidebar = props => { +export interface SidebarProps extends DrawerProps { + children: ReactElement; + closedSize?: number; + classes: ClassesOverride; + size?: number; +} + +const Sidebar = (props: SidebarProps) => { const { children, closedSize, @@ -70,7 +78,9 @@ const Sidebar = props => { theme.breakpoints.down('xs') ); const isSmall = useMediaQuery(theme => theme.breakpoints.down('sm')); - const open = useSelector(state => state.admin.ui.sidebarOpen); + const open = useSelector( + state => state.admin.ui.sidebarOpen + ); useLocale(); // force redraw on locale change const handleClose = () => dispatch(setSidebarVisibility(false)); const toggleSidebar = () => dispatch(setSidebarVisibility(!open)); diff --git a/packages/ra-ui-materialui/src/layout/index.ts b/packages/ra-ui-materialui/src/layout/index.ts index 88333ab500e..9007bee43f8 100644 --- a/packages/ra-ui-materialui/src/layout/index.ts +++ b/packages/ra-ui-materialui/src/layout/index.ts @@ -10,8 +10,8 @@ import Layout from './Layout'; import Loading from './Loading'; import LinearProgress from './LinearProgress'; import LoadingIndicator from './LoadingIndicator'; -import Menu from './Menu'; -import MenuItemLink from './MenuItemLink'; +import Menu, { MenuProps } from './Menu'; +import MenuItemLink, { MenuItemLinkProps } from './MenuItemLink'; import NotFound from './NotFound'; import Notification from './Notification'; import Responsive from './Responsive'; @@ -21,6 +21,8 @@ import TitleForRecord from './TitleForRecord'; import TopToolbar from './TopToolbar'; import UserMenu from './UserMenu'; +export type { MenuProps, MenuItemLinkProps }; + export { AppBar, CardActions, diff --git a/packages/ra-ui-materialui/src/list/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList.tsx index 29376a36fe4..efa246565fd 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList.tsx @@ -171,7 +171,7 @@ SimpleList.propTypes = { export type FunctionToElement = ( record: Record, id: Identifier -) => ReactElement; +) => ReactElement | string; export interface SimpleListProps extends Omit { className?: string; diff --git a/packages/ra-ui-materialui/src/list/datagrid/ExpandRowButton.tsx b/packages/ra-ui-materialui/src/list/datagrid/ExpandRowButton.tsx index a39d13c3003..d819f84b3a3 100644 --- a/packages/ra-ui-materialui/src/list/datagrid/ExpandRowButton.tsx +++ b/packages/ra-ui-materialui/src/list/datagrid/ExpandRowButton.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { memo } from 'react'; -import IconButton from '@material-ui/core/IconButton'; +import { ElementType, memo } from 'react'; +import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import classNames from 'classnames'; import { useTranslate } from 'ra-core'; @@ -22,9 +22,9 @@ const ExpandRowButton = ({ className={classNames(classes.expandIcon, { [classes.expanded]: expanded, })} - component="div" tabIndex={-1} aria-hidden="true" + component="div" {...props} > @@ -32,11 +32,11 @@ const ExpandRowButton = ({ ); }; -export interface ExpandRowButtonProps { +export interface ExpandRowButtonProps extends IconButtonProps { classes?: any; + component?: ElementType; expanded: boolean; - expandContentId: string; - onClick?: (event: any) => void; + expandContentId?: string; } export default memo(ExpandRowButton); diff --git a/packages/ra-ui-materialui/src/types.ts b/packages/ra-ui-materialui/src/types.ts index 8ac1192508e..e75fd0143d2 100644 --- a/packages/ra-ui-materialui/src/types.ts +++ b/packages/ra-ui-materialui/src/types.ts @@ -48,6 +48,7 @@ export interface CreateProps extends ResourceComponentProps { classes?: any; className?: string; component?: ElementType; + record?: Partial; onSuccess?: (data: RaRecord) => void; onFailure?: (error: any) => void; transform?: (data: RaRecord) => RaRecord;