Skip to content

Commit

Permalink
Remove calls to useResourceDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Nov 2, 2020
1 parent ee0edf2 commit 99f79a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecordType extends Omit<Record, 'id'> = Record> {
basePath?: string;
Expand Down Expand Up @@ -102,6 +102,8 @@ export const useCreateController = <
useCheckMinimumRequiredProps('Create', ['basePath', 'resource'], props);
const {
basePath,
hasEdit,
hasShow,
record = {},
successMessage,
onSuccess,
Expand All @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions packages/ra-core/src/controller/details/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
SetTransformData,
useSaveModifiers,
} from '../saveModifiers';
import { useResourceContext, useResourceDefinition } from '../../core';
import { useResourceContext } from '../../core';

export interface EditProps {
basePath?: string;
Expand Down Expand Up @@ -95,6 +95,9 @@ export const useEditController = <RecordType extends Record = Record>(
const {
basePath,
hasCreate,
hasEdit,
hasList,
hasShow,
id,
successMessage,
undoable = true,
Expand All @@ -103,10 +106,6 @@ export const useEditController = <RecordType extends Record = Record>(
transform,
} = props;
const { resource } = useResourceContext(props);
const { hasEdit, hasList, hasShow } = useResourceDefinition(
resource,
props
);
const translate = useTranslate();
const notify = useNotify();
const redirect = useRedirect();
Expand Down
8 changes: 2 additions & 6 deletions packages/ra-core/src/controller/details/useShowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,12 +58,8 @@ export const useShowController = <RecordType extends Record = Record>(
props: ShowProps
): ShowControllerProps<RecordType> => {
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();
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,13 +112,13 @@ const useListController = <RecordType extends Record = Record>(
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(
Expand Down

0 comments on commit 99f79a0

Please sign in to comment.