mirror of
https://github.com/strapi/strapi.git
synced 2025-08-02 13:58:18 +00:00
console.log removed, mainValue length limited to 50 chars, componentFieldName (string) parameter reorged to componentFieldPath (array)
This commit is contained in:
parent
469ff7e100
commit
7afa200622
@ -14,7 +14,6 @@ import { Loader } from '@strapi/design-system/Loader';
|
|||||||
import Trash from '@strapi/icons/Trash';
|
import Trash from '@strapi/icons/Trash';
|
||||||
import ArrowDown from '@strapi/icons/ArrowDown';
|
import ArrowDown from '@strapi/icons/ArrowDown';
|
||||||
import ArrowUp from '@strapi/icons/ArrowUp';
|
import ArrowUp from '@strapi/icons/ArrowUp';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
||||||
import { useContentTypeLayout } from '../../../../hooks';
|
import { useContentTypeLayout } from '../../../../hooks';
|
||||||
import { getTrad } from '../../../../utils';
|
import { getTrad } from '../../../../utils';
|
||||||
import FieldComponent from '../../../FieldComponent';
|
import FieldComponent from '../../../FieldComponent';
|
||||||
@ -60,21 +59,12 @@ const Component = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { getComponentLayout } = useContentTypeLayout();
|
const { getComponentLayout } = useContentTypeLayout();
|
||||||
const { modifiedData } = useCMEditViewDataManager();
|
|
||||||
const componentLayoutData = useMemo(() => {
|
const componentLayoutData = useMemo(() => {
|
||||||
const layout = getComponentLayout(componentUid);
|
const layout = getComponentLayout(componentUid);
|
||||||
|
|
||||||
console.log('DZone/Component componentLayoutData', {
|
|
||||||
componentUid,
|
|
||||||
layout,
|
|
||||||
name,
|
|
||||||
index,
|
|
||||||
modifiedData,
|
|
||||||
});
|
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}, [componentUid, getComponentLayout, index, name, modifiedData]);
|
}, [componentUid, getComponentLayout]);
|
||||||
const mainValue = useMainValue(componentLayoutData, `${name}.${index}`);
|
const mainValue = useMainValue(componentLayoutData, [name, index]);
|
||||||
const { icon, friendlyName } = useMemo(() => {
|
const { icon, friendlyName } = useMemo(() => {
|
||||||
const {
|
const {
|
||||||
info: { icon, displayName },
|
info: { icon, displayName },
|
||||||
|
@ -2,13 +2,15 @@ import { useMemo } from 'react';
|
|||||||
import { get, toString } from 'lodash';
|
import { get, toString } from 'lodash';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
function useMainValue(schema, componentFieldName) {
|
function useMainValue(schema, componentFieldPath) {
|
||||||
const { modifiedData } = useCMEditViewDataManager();
|
const { modifiedData } = useCMEditViewDataManager();
|
||||||
|
|
||||||
const mainField = useMemo(() => get(schema, ['settings', 'mainField'], 'id'), [schema]);
|
const mainField = useMemo(() => get(schema, ['settings', 'mainField'], 'id'), [schema]);
|
||||||
const displayedValue = toString(
|
let displayedValue = toString(get(modifiedData, [...componentFieldPath, mainField], ''));
|
||||||
get(modifiedData, [...componentFieldName.split('.'), mainField], '')
|
|
||||||
);
|
if (displayedValue.length > 50) {
|
||||||
|
displayedValue = `${displayedValue.substring(0, 50)}...`;
|
||||||
|
}
|
||||||
|
|
||||||
return displayedValue;
|
return displayedValue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user