fix: use __temp_key__ for when you've just added components and theres no IDs

This commit is contained in:
Josh 2022-12-06 10:26:00 +00:00
parent b041dcb8c4
commit 04a6cd4861
3 changed files with 8 additions and 5 deletions

View File

@ -17,10 +17,12 @@ function useSelect(name) {
const dynamicDisplayedComponents = useMemo(
() =>
get(modifiedData, [name], []).map((data) => ({
componentUid: data.__component,
id: data.id,
})),
get(modifiedData, [name], []).map((data) => {
return {
componentUid: data.__component,
id: data.id ?? data.__temp_key__,
};
}),
[modifiedData, name]
);

View File

@ -88,6 +88,7 @@ const reducer = (state, action) =>
? {
...state.componentsDataStructure[componentLayoutData.uid],
__component: componentLayoutData.uid,
__temp_key__: getMaxTempKey(currentValue) + 1,
}
: {
...state.componentsDataStructure[componentLayoutData.uid],

View File

@ -5,7 +5,7 @@ const getMaxTempKey = (arr) => {
return Math.max.apply(
Math,
arr.map((o) => o.__temp_key__)
arr.map((o) => o.__temp_key__ ?? o.id)
);
};