From 99f79a00ee8376fd5413f9d5787165570033812c Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Mon, 2 Nov 2020 16:04:01 +0100 Subject: [PATCH] Remove calls to useResourceDefinition --- .../src/controller/details/useCreateController.ts | 5 +++-- .../ra-core/src/controller/details/useEditController.ts | 9 ++++----- .../ra-core/src/controller/details/useShowController.ts | 8 ++------ packages/ra-core/src/controller/useListController.ts | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/ra-core/src/controller/details/useCreateController.ts b/packages/ra-core/src/controller/details/useCreateController.ts index a1746548a28..3824a5f3300 100644 --- a/packages/ra-core/src/controller/details/useCreateController.ts +++ b/packages/ra-core/src/controller/details/useCreateController.ts @@ -25,7 +25,7 @@ import { useTranslate } from '../../i18n'; import useVersion from '../useVersion'; import { CRUD_CREATE } from '../../actions'; import { Record } from '../../types'; -import { useResourceContext, useResourceDefinition } from '../../core'; +import { useResourceContext } from '../../core'; export interface CreateProps = Record> { basePath?: string; @@ -102,6 +102,8 @@ export const useCreateController = < useCheckMinimumRequiredProps('Create', ['basePath', 'resource'], props); const { basePath, + hasEdit, + hasShow, record = {}, successMessage, onSuccess, @@ -110,7 +112,6 @@ export const useCreateController = < } = props; const { resource } = useResourceContext(props); - const { hasEdit, hasShow } = useResourceDefinition(resource, props); const location = useLocation(); const translate = useTranslate(); const notify = useNotify(); diff --git a/packages/ra-core/src/controller/details/useEditController.ts b/packages/ra-core/src/controller/details/useEditController.ts index 4219f76b1ee..7e7ebea98b6 100644 --- a/packages/ra-core/src/controller/details/useEditController.ts +++ b/packages/ra-core/src/controller/details/useEditController.ts @@ -22,7 +22,7 @@ import { SetTransformData, useSaveModifiers, } from '../saveModifiers'; -import { useResourceContext, useResourceDefinition } from '../../core'; +import { useResourceContext } from '../../core'; export interface EditProps { basePath?: string; @@ -95,6 +95,9 @@ export const useEditController = ( const { basePath, hasCreate, + hasEdit, + hasList, + hasShow, id, successMessage, undoable = true, @@ -103,10 +106,6 @@ export const useEditController = ( transform, } = props; const { resource } = useResourceContext(props); - const { hasEdit, hasList, hasShow } = useResourceDefinition( - resource, - props - ); const translate = useTranslate(); const notify = useNotify(); const redirect = useRedirect(); diff --git a/packages/ra-core/src/controller/details/useShowController.ts b/packages/ra-core/src/controller/details/useShowController.ts index bd0d6d28dd7..a4dd8a33ce2 100644 --- a/packages/ra-core/src/controller/details/useShowController.ts +++ b/packages/ra-core/src/controller/details/useShowController.ts @@ -7,7 +7,7 @@ import { useGetOne } from '../../dataProvider'; import { useTranslate } from '../../i18n'; import { useNotify, useRedirect, useRefresh } from '../../sideEffect'; import { CRUD_GET_ONE } from '../../actions'; -import { useResourceContext, useResourceDefinition } from '../../core'; +import { useResourceContext } from '../../core'; export interface ShowProps { basePath?: string; @@ -58,12 +58,8 @@ export const useShowController = ( props: ShowProps ): ShowControllerProps => { useCheckMinimumRequiredProps('Show', ['basePath', 'resource'], props); - const { basePath, id } = props; + const { basePath, hasCreate, hasEdit, hasList, hasShow, id } = props; const { resource } = useResourceContext(props); - const { hasCreate, hasEdit, hasList, hasShow } = useResourceDefinition( - resource, - props - ); const translate = useTranslate(); const notify = useNotify(); const redirect = useRedirect(); diff --git a/packages/ra-core/src/controller/useListController.ts b/packages/ra-core/src/controller/useListController.ts index 848bb24fc4d..0fc933b2117 100644 --- a/packages/ra-core/src/controller/useListController.ts +++ b/packages/ra-core/src/controller/useListController.ts @@ -23,7 +23,7 @@ import { Record, Exporter, } from '../types'; -import { useResourceContext, useResourceDefinition } from '../core'; +import { useResourceContext } from '../core'; export interface ListProps { // the props you can change @@ -112,13 +112,13 @@ const useListController = ( basePath, exporter = defaultExporter, filterDefaultValues, + hasCreate, sort = defaultSort, perPage = 10, filter, debounce = 500, } = props; const { resource } = useResourceContext(props); - const { hasCreate } = useResourceDefinition(resource, props); if (filter && isValidElement(filter)) { throw new Error(