Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/* eslint-disable import/no-cycle */
import React, { memo } from "react";
import PropTypes from "prop-types";
import { get, size } from "lodash";
import { FormattedMessage } from "react-intl";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import isEqual from "react-fast-compare";
import pluginId from "../../pluginId";
import useEditView from "../../hooks/useEditView";
import ComponentInitializer from "../ComponentInitializer";
import NonRepeatableComponent from "../NonRepeatableComponent";
import NotAllowedInput from "../NotAllowedInput";
import RepeatableComponent from "../RepeatableComponent";
import connect from "./utils/connect";
import select from "./utils/select";
import ComponentIcon from "./ComponentIcon";
import Label from "./Label";
import Reset from "./ResetComponent";
import Wrapper from "./Wrapper";
import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { size } from 'lodash';
import { FormattedMessage } from 'react-intl';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import isEqual from 'react-fast-compare';
import { NotAllowedInput } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
import ComponentInitializer from '../ComponentInitializer';
import NonRepeatableComponent from '../NonRepeatableComponent';
import RepeatableComponent from '../RepeatableComponent';
import connect from './utils/connect';
import select from './utils/select';
import ComponentIcon from './ComponentIcon';
import Label from './Label';
import Reset from './ResetComponent';
import Wrapper from './Wrapper';

const FieldComponent = ({
componentFriendlyName,
Expand All @@ -39,22 +38,13 @@ const FieldComponent = ({
dataForCurrentVersion,
isVersionCurrent,
}) => {
const { allLayoutData } = useEditView();

const componentValueLength = size(componentValue);
const isInitialized = componentValue || isFromDynamicZone;
const isInitialized = componentValue !== null || isFromDynamicZone;
const showResetComponent =
!isRepeatable &&
isInitialized &&
!isFromDynamicZone &&
hasChildrenAllowedFields;
const currentComponentSchema = get(
allLayoutData,
["components", componentUid],
{},
);

const displayedFields = get(currentComponentSchema, ["layouts", "edit"], []);

if (!hasChildrenAllowedFields && isCreatingEntry) {
return (
Expand Down Expand Up @@ -115,10 +105,8 @@ const FieldComponent = ({
{!isRepeatable && isInitialized && (
<NonRepeatableComponent
componentUid={componentUid}
fields={displayedFields}
isFromDynamicZone={isFromDynamicZone}
name={name}
schema={currentComponentSchema}
dataForCurrentVersion={dataForCurrentVersion}
isVersionCurrent={isVersionCurrent}
/>
Expand All @@ -128,14 +116,11 @@ const FieldComponent = ({
componentValue={componentValue}
componentValueLength={componentValueLength}
componentUid={componentUid}
fields={displayedFields}
isFromDynamicZone={isFromDynamicZone}
isNested={isNested}
isReadOnly={isReadOnly}
max={max}
min={min}
name={name}
schema={currentComponentSchema}
dataForCurrentVersion={dataForCurrentVersion}
isVersionCurrent={isVersionCurrent}
/>
Expand All @@ -149,7 +134,7 @@ FieldComponent.defaultProps = {
componentFriendlyName: null,
hasChildrenAllowedFields: false,
hasChildrenReadableFields: false,
icon: "smile",
icon: 'smile',
isFromDynamicZone: false,
isReadOnly: false,
isRepeatable: false,
Expand Down
Loading