mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
Merge branch 'main' into enhancement/axios-refactoring
This commit is contained in:
commit
4a211a50d0
@ -40,7 +40,7 @@
|
||||
"dependencies": {
|
||||
"@strapi/generate-new": "4.5.0",
|
||||
"chalk": "4.1.1",
|
||||
"ci-info": "3.3.2",
|
||||
"ci-info": "3.5.0",
|
||||
"commander": "7.1.0",
|
||||
"execa": "5.1.1",
|
||||
"fs-extra": "10.0.0",
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
import { getDisplayedValue } from '../useMainValue';
|
||||
|
||||
describe('getDisplayedValue', () => {
|
||||
it('returns the mainField value', () => {
|
||||
const modifiedData = {
|
||||
DeepComplex: [
|
||||
{
|
||||
Title: 'File',
|
||||
},
|
||||
],
|
||||
};
|
||||
const componentFieldPath = ['DeepComplex', 0];
|
||||
const mainField = 'Title';
|
||||
|
||||
const normalizedContent = getDisplayedValue(modifiedData, componentFieldPath, mainField);
|
||||
|
||||
expect(normalizedContent).toEqual('File');
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { useMemo } from 'react';
|
||||
import get from 'lodash/get';
|
||||
import toString from 'lodash/toString';
|
||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||
|
||||
export function getDisplayedValue(modifiedData, componentFieldPath, mainField) {
|
||||
return toString(get(modifiedData, [...componentFieldPath, mainField], ''));
|
||||
}
|
||||
|
||||
function useMainValue(schema, componentFieldPath) {
|
||||
const { modifiedData } = useCMEditViewDataManager();
|
||||
|
||||
const mainField = useMemo(() => get(schema, ['settings', 'mainField'], 'id'), [schema]);
|
||||
|
||||
const displayedValue =
|
||||
mainField === 'id' ? '' : getDisplayedValue(modifiedData, componentFieldPath, mainField);
|
||||
|
||||
return displayedValue.trim().length < 1 ? '' : ` - ${displayedValue}`;
|
||||
}
|
||||
|
||||
export default useMainValue;
|
||||
@ -18,6 +18,7 @@ import { useContentTypeLayout } from '../../../../hooks';
|
||||
import { getTrad } from '../../../../utils';
|
||||
import FieldComponent from '../../../FieldComponent';
|
||||
import Rectangle from './Rectangle';
|
||||
import { connect, select } from './utils';
|
||||
|
||||
const ActionStack = styled(Stack)`
|
||||
svg {
|
||||
@ -55,6 +56,8 @@ const Component = ({
|
||||
removeComponentFromDynamicZone,
|
||||
showDownIcon,
|
||||
showUpIcon,
|
||||
// Passed with the select function
|
||||
mainValue,
|
||||
}) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { getComponentLayout } = useContentTypeLayout();
|
||||
@ -144,7 +147,7 @@ const Component = ({
|
||||
)}
|
||||
</ActionStack>
|
||||
}
|
||||
title={friendlyName}
|
||||
title={`${friendlyName}${mainValue}`}
|
||||
togglePosition="left"
|
||||
/>
|
||||
<AccordionContent>
|
||||
@ -186,6 +189,9 @@ Component.propTypes = {
|
||||
removeComponentFromDynamicZone: PropTypes.func.isRequired,
|
||||
showDownIcon: PropTypes.bool.isRequired,
|
||||
showUpIcon: PropTypes.bool.isRequired,
|
||||
mainValue: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default memo(Component, isEqual);
|
||||
const Memoized = memo(Component, isEqual);
|
||||
|
||||
export default connect(Memoized, select);
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
|
||||
function connect(WrappedComponent, select) {
|
||||
return (props) => {
|
||||
const selectors = select(props);
|
||||
|
||||
return <WrappedComponent {...props} {...selectors} />;
|
||||
};
|
||||
}
|
||||
|
||||
export default connect;
|
||||
@ -0,0 +1,2 @@
|
||||
export { default as connect } from './connect';
|
||||
export { default as select } from './select';
|
||||
@ -0,0 +1,19 @@
|
||||
import { useMemo } from 'react';
|
||||
import useMainValue from '../hooks/useMainValue';
|
||||
import { useContentTypeLayout } from '../../../../../hooks';
|
||||
|
||||
function useSelect({ componentUid, name, index }) {
|
||||
const { getComponentLayout } = useContentTypeLayout();
|
||||
const componentLayoutData = useMemo(() => {
|
||||
const layout = getComponentLayout(componentUid);
|
||||
|
||||
return layout;
|
||||
}, [componentUid, getComponentLayout]);
|
||||
const mainValue = useMainValue(componentLayoutData, [name, index]);
|
||||
|
||||
return {
|
||||
mainValue,
|
||||
};
|
||||
}
|
||||
|
||||
export default useSelect;
|
||||
@ -46,7 +46,7 @@
|
||||
"@casl/ability": "^5.4.3",
|
||||
"@fingerprintjs/fingerprintjs": "3.3.3",
|
||||
"@fortawesome/fontawesome-free": "^5.15.3",
|
||||
"@fortawesome/fontawesome-svg-core": "6.1.2",
|
||||
"@fortawesome/fontawesome-svg-core": "6.2.0",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.15.3",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.15.3",
|
||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^5.15.2",
|
||||
"@fortawesome/fontawesome-svg-core": "6.1.2",
|
||||
"@fortawesome/fontawesome-svg-core": "6.2.0",
|
||||
"@fortawesome/free-brands-svg-icons": "^5.15.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.15.3",
|
||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
"boxen": "5.1.2",
|
||||
"chalk": "4.1.2",
|
||||
"chokidar": "3.5.2",
|
||||
"ci-info": "3.3.2",
|
||||
"ci-info": "3.5.0",
|
||||
"cli-table3": "0.6.2",
|
||||
"commander": "8.2.0",
|
||||
"configstore": "5.0.1",
|
||||
|
||||
@ -18,8 +18,8 @@ const uploadAsset = (asset, folderId, cancelToken, onProgress) => {
|
||||
'fileInfo',
|
||||
JSON.stringify({
|
||||
name,
|
||||
caption: caption || name,
|
||||
alternativeText: alternativeText || name,
|
||||
caption,
|
||||
alternativeText,
|
||||
folder: folderId,
|
||||
})
|
||||
);
|
||||
|
||||
39
yarn.lock
39
yarn.lock
@ -2135,10 +2135,10 @@
|
||||
intl-messageformat "9.13.0"
|
||||
tslib "^2.1.0"
|
||||
|
||||
"@fortawesome/fontawesome-common-types@6.1.2":
|
||||
version "6.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.1.2.tgz#c1095b1bbabf19f37f9ff0719db38d92a410bcfe"
|
||||
integrity sha512-wBaAPGz1Awxg05e0PBRkDRuTsy4B3dpBm+zreTTyd9TH4uUM27cAL4xWyWR0rLJCrRwzVsQ4hF3FvM6rqydKPA==
|
||||
"@fortawesome/fontawesome-common-types@6.2.0":
|
||||
version "6.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.2.0.tgz#76467a94aa888aeb22aafa43eb6ff889df3a5a7f"
|
||||
integrity sha512-rBevIsj2nclStJ7AxTdfsa3ovHb1H+qApwrxcTVo+NNdeJiB9V75hsKfrkG5AwNcRUNxrPPiScGYCNmLMoh8pg==
|
||||
|
||||
"@fortawesome/fontawesome-common-types@^0.2.36":
|
||||
version "0.2.36"
|
||||
@ -2150,12 +2150,12 @@
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.4.tgz#ecda5712b61ac852c760d8b3c79c96adca5554e5"
|
||||
integrity sha512-eYm8vijH/hpzr/6/1CJ/V/Eb1xQFW2nnUKArb3z+yUWv7HTwj6M7SP957oMjfZjAHU6qpoNc2wQvIxBLWYa/Jg==
|
||||
|
||||
"@fortawesome/fontawesome-svg-core@6.1.2":
|
||||
version "6.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.1.2.tgz#11e2e8583a7dea75d734e4d0e53d91c63fae7511"
|
||||
integrity sha512-853G/Htp0BOdXnPoeCPTjFrVwyrJHpe8MhjB/DYE9XjwhnNDfuBCd3aKc2YUYbEfHEcBws4UAA0kA9dymZKGjA==
|
||||
"@fortawesome/fontawesome-svg-core@6.2.0":
|
||||
version "6.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.2.0.tgz#11856eaf4dd1d865c442ddea1eed8ee855186ba2"
|
||||
integrity sha512-Cf2mAAeMWFMzpLC7Y9H1I4o3wEU+XovVJhTiNG8ZNgSQj53yl7OCJaS80K4YjrABWZzbAHVaoHE1dVJ27AAYXw==
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "6.1.2"
|
||||
"@fortawesome/fontawesome-common-types" "6.2.0"
|
||||
|
||||
"@fortawesome/free-brands-svg-icons@^5.15.2", "@fortawesome/free-brands-svg-icons@^5.15.3":
|
||||
version "5.15.4"
|
||||
@ -9150,10 +9150,10 @@ chrome-trace-event@^1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz#1015eced4741e15d06664a957dbbf50d041e26ac"
|
||||
integrity sha512-p3KULyQg4S7NIHixdwbGX+nFHkoBiA4YQmyWtjb8XngSKV124nJmRysgAeujbUVb15vh+RvFUfCPqU7rXk+hZg==
|
||||
|
||||
ci-info@3.3.2, ci-info@^3.2.0:
|
||||
version "3.3.2"
|
||||
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.3.2.tgz#6d2967ffa407466481c6c90b6e16b3098f080128"
|
||||
integrity sha512-xmDt/QIAdeZ9+nfdPsaBCpMvHNLFiLdjj59qjqn+6iPe6YmHGQ35sBnQ8uslRBXFmXkiZQOJRjvQeoGppoTjjg==
|
||||
ci-info@3.5.0, ci-info@^3.2.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.5.0.tgz#bfac2a29263de4c829d806b1ab478e35091e171f"
|
||||
integrity sha512-yH4RezKOGlOhxkmhbeNuC4eYZKAUsEaGtBuBzDDP1eFUKiccDWzBABxBfOx31IDwDIXMTxWuwAxUGModvkbuVw==
|
||||
|
||||
ci-info@^2.0.0:
|
||||
version "2.0.0"
|
||||
@ -15852,9 +15852,9 @@ loader-runner@^4.2.0:
|
||||
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==
|
||||
|
||||
loader-utils@^1.2.3:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
|
||||
integrity sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.1.tgz#278ad7006660bccc4d2c0c1578e17c5c78d5c0e0"
|
||||
integrity sha512-1Qo97Y2oKaU+Ro2xnDMR26g1BwMT29jNbem1EvcujW2jqt+j5COXyscjM7bLQkM9HaxI7pkWeW7gnI072yMI9Q==
|
||||
dependencies:
|
||||
big.js "^5.2.2"
|
||||
emojis-list "^3.0.0"
|
||||
@ -16712,11 +16712,16 @@ minimist-options@4.1.0:
|
||||
is-plain-obj "^1.1.0"
|
||||
kind-of "^6.0.3"
|
||||
|
||||
minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
|
||||
minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
|
||||
version "1.2.6"
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
|
||||
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
|
||||
|
||||
minimist@^1.2.0:
|
||||
version "1.2.7"
|
||||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18"
|
||||
integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==
|
||||
|
||||
minipass-collect@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-1.0.2.tgz#22b813bf745dc6edba2576b940022ad6edc8c617"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user