diff --git a/src/lib/core/components/Form/Controller.tsx b/src/lib/core/components/Form/Controller.tsx index ce77ca4f..e33b1eaa 100644 --- a/src/lib/core/components/Form/Controller.tsx +++ b/src/lib/core/components/Form/Controller.tsx @@ -1,6 +1,5 @@ import _ from 'lodash'; -import {isCorrectSpec} from '../../helpers'; import {Spec} from '../../types'; import { @@ -63,9 +62,5 @@ export const Controller = ({ __mirror, ); - if (_.isString(name) && isCorrectSpec(spec) && !spec.viewSpec.hidden) { - return withSearch(render(renderProps)); - } - - return null; + return withSearch(render(renderProps)); }; diff --git a/src/lib/core/components/Form/hooks/__tests__/useSearch.test.tsx b/src/lib/core/components/Form/hooks/__tests__/useSearch.test.tsx index 8b6a9a18..f5ad23c1 100644 --- a/src/lib/core/components/Form/hooks/__tests__/useSearch.test.tsx +++ b/src/lib/core/components/Form/hooks/__tests__/useSearch.test.tsx @@ -64,9 +64,7 @@ describe('Form/hooks/useSearch', () => { 'name.surname': true, 'name.username': false, }); - expect(mirror.controller['name.surname']?.useSearch?.(null).props.className).toBe( - 'df-use-search', - ); + expect(mirror.controller['name.surname']?.useSearch?.(null)).toBe(null); rerender(
@@ -88,8 +86,6 @@ describe('Form/hooks/useSearch', () => { 'name.surname': true, 'name.username': false, }); - expect(mirror.controller['name.surname']?.useSearch?.(null).props.className).toBe( - 'df-use-search df-use-search_hidden', - ); + expect(mirror.controller['name.surname']?.useSearch?.(null)).toBe(null); }); }); diff --git a/src/lib/core/components/Form/hooks/useRender.tsx b/src/lib/core/components/Form/hooks/useRender.tsx index 14d52a8a..3e357154 100644 --- a/src/lib/core/components/Form/hooks/useRender.tsx +++ b/src/lib/core/components/Form/hooks/useRender.tsx @@ -28,24 +28,28 @@ export const useRender = ({ const render = React.useCallback( (props: FieldRenderProps) => { if (inputEntity && isCorrectSpec(spec) && _.isString(name)) { - if (inputEntity.independent) { - const InputComponent = inputEntity.Component; + if (!spec.viewSpec.hidden) { + if (inputEntity.independent) { + const InputComponent = inputEntity.Component; - return ; - } + return ( + + ); + } - const InputComponent = inputEntity.Component; - const input = ; + const InputComponent = inputEntity.Component; + const input = ; - if (Layout) { - return ( - - {input} - - ); - } + if (Layout) { + return ( + + {input} + + ); + } - return input; + return input; + } } return null; diff --git a/src/lib/core/components/Form/hooks/useSearch/useSearch.tsx b/src/lib/core/components/Form/hooks/useSearch/useSearch.tsx index d946e97d..6ce5b0b8 100644 --- a/src/lib/core/components/Form/hooks/useSearch/useSearch.tsx +++ b/src/lib/core/components/Form/hooks/useSearch/useSearch.tsx @@ -20,7 +20,8 @@ export const useSearch = (spec: Spec, value: FieldValue, name: string) => { const hidden = React.useMemo(() => isHiddenField(name), [isHiddenField, name]); const withSearch = React.useCallback( - (children: JSX.Element | null) =>
{children}
, + (children: JSX.Element | null) => + children ?
{children}
: null, [hidden], ); diff --git a/src/lib/core/components/View/ViewController.tsx b/src/lib/core/components/View/ViewController.tsx index 45fb2439..f0c3fef1 100644 --- a/src/lib/core/components/View/ViewController.tsx +++ b/src/lib/core/components/View/ViewController.tsx @@ -19,9 +19,5 @@ export const ViewController = ({ const {viewEntity, Layout} = useComponents(spec, config); const render = useRender({name, value, spec, viewEntity, Layout, Link}); - if (!spec.viewSpec.hidden) { - return {render}; - } - - return null; + return {render}; }; diff --git a/src/lib/core/components/View/hooks/useRender.tsx b/src/lib/core/components/View/hooks/useRender.tsx index 6f804142..e7ce32f0 100644 --- a/src/lib/core/components/View/hooks/useRender.tsx +++ b/src/lib/core/components/View/hooks/useRender.tsx @@ -26,45 +26,47 @@ export const useRender = ({ }: UseRenderParams) => { const render = React.useMemo(() => { if (viewEntity && isCorrectSpec(spec) && _.isString(name)) { - const currentValue = name ? _.get(value, name) : value; - const linkValue = - isValidElementType(Link) && spec?.viewSpec?.link ? ( - - ) : undefined; + if (!spec.viewSpec.hidden) { + const currentValue = name ? _.get(value, name) : value; + const linkValue = + isValidElementType(Link) && spec?.viewSpec?.link ? ( + + ) : undefined; - if (viewEntity.independent) { - const InputComponent = viewEntity.Component; + if (viewEntity.independent) { + const InputComponent = viewEntity.Component; + + return ( + + ); + } - return ( + const InputComponent = viewEntity.Component; + const input = ( ); - } - const InputComponent = viewEntity.Component; - const input = ( - - ); + if (Layout) { + return ( + + {input} + + ); + } - if (Layout) { - return ( - - {input} - - ); + return input; } - - return input; } return null;