mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 02:07:51 +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 take from 'lodash/take';
|
||||
import isNil from 'lodash/isNil';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
|
||||
import { useCMEditViewDataManager, NotAllowedInput } from '@strapi/helper-plugin';
|
||||
|
||||
@ -54,16 +53,16 @@ export const RelationInputDataManager = ({
|
||||
const initialDataPath = [];
|
||||
const nameSplit = name.split('.');
|
||||
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);
|
||||
const modifiedDataValue = get(modifiedData, [...pathSoFar, currentValue]);
|
||||
const tempKey = get(modifiedDataValue, '__temp_key__');
|
||||
|
||||
if (!isNil(tempKey) && Array.isArray(initialDataParent)) {
|
||||
const initialDataIndex = findIndex(
|
||||
initialDataParent,
|
||||
(entry) => entry.__temp_key__ === tempKey
|
||||
if (!isNil(modifiedDataTempKey) && Array.isArray(initialDataParent)) {
|
||||
const initialDataIndex = initialDataParent.findIndex(
|
||||
(entry) => entry.__temp_key__ === modifiedDataTempKey
|
||||
);
|
||||
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 () => {
|
||||
const initialData = {
|
||||
dz: [
|
||||
{
|
||||
__component: 'default.blank',
|
||||
__temp_key__: 6,
|
||||
},
|
||||
{
|
||||
__component: 'default.withToManyComponentRelation',
|
||||
__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.any(String),
|
||||
expect.objectContaining({
|
||||
initialDataPath: ['initialData', 'dz', '1', 'toManyRelation', '1', 'publishers'],
|
||||
initialDataPath: ['initialData', 'dz', '0', 'toManyRelation', '1', 'publishers'],
|
||||
modifiedDataPath: ['modifiedData', 'dz', '1', 'toManyRelation', '0', 'publishers'],
|
||||
})
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user