mirror of
https://github.com/strapi/strapi.git
synced 2025-08-13 03:07:32 +00:00
fix(content-manager): initial data indexing
This commit is contained in:
parent
143ddc8466
commit
168fe777d5
@ -6,7 +6,6 @@ import get from 'lodash/get';
|
|||||||
import pick from 'lodash/pick';
|
import pick from 'lodash/pick';
|
||||||
import take from 'lodash/take';
|
import take from 'lodash/take';
|
||||||
import isNil from 'lodash/isNil';
|
import isNil from 'lodash/isNil';
|
||||||
import findIndex from 'lodash/findIndex';
|
|
||||||
|
|
||||||
import { useCMEditViewDataManager, NotAllowedInput } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager, NotAllowedInput } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
@ -54,16 +53,16 @@ export const RelationInputDataManager = ({
|
|||||||
const initialDataPath = [];
|
const initialDataPath = [];
|
||||||
const nameSplit = name.split('.');
|
const nameSplit = name.split('.');
|
||||||
nameSplit.reduce((acc, currentValue, index) => {
|
nameSplit.reduce((acc, currentValue, index) => {
|
||||||
const pathSoFar = take(nameSplit, index);
|
const initialDataParent = get(initialData, initialDataPath);
|
||||||
|
const modifiedDataTempKey = get(modifiedData, [
|
||||||
|
...take(nameSplit, index),
|
||||||
|
currentValue,
|
||||||
|
'__temp_key__',
|
||||||
|
]);
|
||||||
|
|
||||||
const initialDataParent = get(initialData, pathSoFar);
|
if (!isNil(modifiedDataTempKey) && Array.isArray(initialDataParent)) {
|
||||||
const modifiedDataValue = get(modifiedData, [...pathSoFar, currentValue]);
|
const initialDataIndex = initialDataParent.findIndex(
|
||||||
const tempKey = get(modifiedDataValue, '__temp_key__');
|
(entry) => entry.__temp_key__ === modifiedDataTempKey
|
||||||
|
|
||||||
if (!isNil(tempKey) && Array.isArray(initialDataParent)) {
|
|
||||||
const initialDataIndex = findIndex(
|
|
||||||
initialDataParent,
|
|
||||||
(entry) => entry.__temp_key__ === tempKey
|
|
||||||
);
|
);
|
||||||
acc.push(`${initialDataIndex}`);
|
acc.push(`${initialDataIndex}`);
|
||||||
|
|
||||||
|
@ -688,10 +688,6 @@ describe('RelationInputDataManager', () => {
|
|||||||
test('correctly computes modified and initial data paths for nested content and passes this to useRelation', async () => {
|
test('correctly computes modified and initial data paths for nested content and passes this to useRelation', async () => {
|
||||||
const initialData = {
|
const initialData = {
|
||||||
dz: [
|
dz: [
|
||||||
{
|
|
||||||
__component: 'default.blank',
|
|
||||||
__temp_key__: 6,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
__component: 'default.withToManyComponentRelation',
|
__component: 'default.withToManyComponentRelation',
|
||||||
__temp_key__: 7,
|
__temp_key__: 7,
|
||||||
@ -708,6 +704,10 @@ describe('RelationInputDataManager', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
__component: 'default.blank',
|
||||||
|
__temp_key__: 6,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -753,7 +753,7 @@ describe('RelationInputDataManager', () => {
|
|||||||
expect(useRelation).toBeCalledWith(
|
expect(useRelation).toBeCalledWith(
|
||||||
expect.any(String),
|
expect.any(String),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
initialDataPath: ['initialData', 'dz', '1', 'toManyRelation', '1', 'publishers'],
|
initialDataPath: ['initialData', 'dz', '0', 'toManyRelation', '1', 'publishers'],
|
||||||
modifiedDataPath: ['modifiedData', 'dz', '1', 'toManyRelation', '0', 'publishers'],
|
modifiedDataPath: ['modifiedData', 'dz', '1', 'toManyRelation', '0', 'publishers'],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user