From 8a13dbe77bc1955ffa01c033025a64454e9ca84a Mon Sep 17 00:00:00 2001 From: Kmaschta Date: Tue, 10 Dec 2019 18:00:11 +0100 Subject: [PATCH] Better prop sanitation for reference inputs --- .../src/input/ReferenceArrayInput.js | 23 ++----------------- .../src/input/ReferenceInput.tsx | 21 ++--------------- .../src/input/sanitizeRestProps.ts | 2 +- 3 files changed, 5 insertions(+), 41 deletions(-) diff --git a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js index e5c1219d246..9ddeb2c8069 100644 --- a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js +++ b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js @@ -6,6 +6,7 @@ import { useTranslate, } from 'ra-core'; +import sanitizeInputProps from './sanitizeRestProps'; import LinearProgress from '../layout/LinearProgress'; import Labeled from '../input/Labeled'; import ReferenceError from './ReferenceError'; @@ -160,33 +161,13 @@ ReferenceArrayInput.defaultProps = { }; const sanitizeRestProps = ({ - alwaysOn, - basePath, - component, crudGetMany, crudGetMatching, - defaultValue, filterToQuery, - formClassName, - initializeForm, - input, - isRequired, - label, - locale, - meta, - optionText, - optionValue, perPage, - record, referenceSource, - resource, - allowEmpty, - source, - textAlign, - translate, - translateChoice, ...rest -}) => rest; +}) => sanitizeInputProps(rest); export const ReferenceArrayInputView = ({ allowEmpty, diff --git a/packages/ra-ui-materialui/src/input/ReferenceInput.tsx b/packages/ra-ui-materialui/src/input/ReferenceInput.tsx index 2b56b460b45..4da477eb06a 100644 --- a/packages/ra-ui-materialui/src/input/ReferenceInput.tsx +++ b/packages/ra-ui-materialui/src/input/ReferenceInput.tsx @@ -14,6 +14,7 @@ import { Sort, } from 'ra-core'; +import sanitizeInputProps from './sanitizeRestProps'; import LinearProgress from '../layout/LinearProgress'; import Labeled from './Labeled'; import ReferenceError from './ReferenceError'; @@ -165,41 +166,23 @@ ReferenceInput.defaultProps = { }; const sanitizeRestProps = ({ - allowEmpty, - basePath, choices, className, - component, crudGetMatching, crudGetOne, - defaultValue, filter, filterToQuery, - formClassName, - initializeForm, - input, - isRequired, - label, - locale, - meta, onChange, - optionValue, - optionText, perPage, - record, reference, referenceSource, - resource, setFilter, setPagination, setSort, sort, - source, - textAlign, - translateChoice, validation, ...rest -}: any) => rest; +}: any) => sanitizeInputProps(rest); interface ReferenceInputViewProps { allowEmpty?: boolean; diff --git a/packages/ra-ui-materialui/src/input/sanitizeRestProps.ts b/packages/ra-ui-materialui/src/input/sanitizeRestProps.ts index 82773361bcb..bec152ff279 100644 --- a/packages/ra-ui-materialui/src/input/sanitizeRestProps.ts +++ b/packages/ra-ui-materialui/src/input/sanitizeRestProps.ts @@ -1,4 +1,5 @@ export default ({ + allowEmpty, alwaysOn, basePath, component, @@ -16,7 +17,6 @@ export default ({ optionValue, record, resource, - allowEmpty, source, textAlign, translate,