mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 13:20:43 +00:00
CE-938: fixed bug on deletion of associated child records
This commit is contained in:
@ -205,7 +205,7 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
const deleteChildRecord = (name: string, widgetData: any, rowIndex: number) =>
|
function deleteChildRecord(name: string, widgetData: any, rowIndex: number)
|
||||||
{
|
{
|
||||||
updateChildRecordList(name, "delete", rowIndex);
|
updateChildRecordList(name, "delete", rowIndex);
|
||||||
};
|
};
|
||||||
@ -377,7 +377,7 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
widgetData.viewAllLink = null;
|
widgetData.viewAllLink = null;
|
||||||
widgetMetaData.showExportButton = false;
|
widgetMetaData.showExportButton = false;
|
||||||
|
|
||||||
return <RecordGridWidget
|
return Object.keys(childListWidgetData).length > 0 && (<RecordGridWidget
|
||||||
key={`${formValues["tableName"]}-${modalDataChangedCounter}`}
|
key={`${formValues["tableName"]}-${modalDataChangedCounter}`}
|
||||||
widgetMetaData={widgetMetaData}
|
widgetMetaData={widgetMetaData}
|
||||||
data={widgetData}
|
data={widgetData}
|
||||||
@ -387,7 +387,7 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
addNewRecordCallback={() => openAddChildRecord(widgetMetaData.name, widgetData)}
|
addNewRecordCallback={() => openAddChildRecord(widgetMetaData.name, widgetData)}
|
||||||
editRecordCallback={(rowIndex) => openEditChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
editRecordCallback={(rowIndex) => openEditChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
||||||
deleteRecordCallback={(rowIndex) => deleteChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
deleteRecordCallback={(rowIndex) => deleteChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
||||||
/>;
|
/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgetMetaData.type == "filterAndColumnsSetup")
|
if (widgetMetaData.type == "filterAndColumnsSetup")
|
||||||
@ -480,6 +480,8 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
//////////////////
|
//////////////////
|
||||||
// initial load //
|
// initial load //
|
||||||
//////////////////
|
//////////////////
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
if (!asyncLoadInited)
|
if (!asyncLoadInited)
|
||||||
{
|
{
|
||||||
setAsyncLoadInited(true);
|
setAsyncLoadInited(true);
|
||||||
@ -762,6 +764,7 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
forceUpdate();
|
forceUpdate();
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
@ -881,11 +884,22 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
let haveAssociationsToPost = false;
|
let haveAssociationsToPost = false;
|
||||||
for (let name of Object.keys(childListWidgetData))
|
for (let name of Object.keys(childListWidgetData))
|
||||||
{
|
{
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// if cannot find association name, continue loop, since cannot tell backend which association this is for //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
const manageAssociationName = metaData.widgets.get(name)?.defaultValues?.get("manageAssociationName");
|
const manageAssociationName = metaData.widgets.get(name)?.defaultValues?.get("manageAssociationName");
|
||||||
if (!manageAssociationName)
|
if (!manageAssociationName)
|
||||||
{
|
{
|
||||||
console.log(`Cannot send association data to backend - missing a manageAssociationName defaultValue in widget meta data for widget name ${name}`);
|
console.log(`Cannot send association data to backend - missing a manageAssociationName defaultValue in widget meta data for widget name ${name}`);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// if the records array exists, add to associations to post - note: even if empty list, the backend will expect this //
|
||||||
|
// association name to be present if it is to act on it (for the case when all associations have been deleted) //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if (childListWidgetData[name].queryOutput.records)
|
||||||
|
{
|
||||||
associationsToPost[manageAssociationName] = [];
|
associationsToPost[manageAssociationName] = [];
|
||||||
haveAssociationsToPost = true;
|
haveAssociationsToPost = true;
|
||||||
for (let i = 0; i < childListWidgetData[name].queryOutput?.records?.length; i++)
|
for (let i = 0; i < childListWidgetData[name].queryOutput?.records?.length; i++)
|
||||||
@ -893,6 +907,7 @@ function EntityForm(props: Props): JSX.Element
|
|||||||
associationsToPost[manageAssociationName].push(childListWidgetData[name].queryOutput.records[i].values);
|
associationsToPost[manageAssociationName].push(childListWidgetData[name].queryOutput.records[i].values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (haveAssociationsToPost)
|
if (haveAssociationsToPost)
|
||||||
{
|
{
|
||||||
valuesToPost["associations"] = JSON.stringify(associationsToPost);
|
valuesToPost["associations"] = JSON.stringify(associationsToPost);
|
||||||
|
Reference in New Issue
Block a user