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);
|
||||
};
|
||||
@ -377,7 +377,7 @@ function EntityForm(props: Props): JSX.Element
|
||||
widgetData.viewAllLink = null;
|
||||
widgetMetaData.showExportButton = false;
|
||||
|
||||
return <RecordGridWidget
|
||||
return Object.keys(childListWidgetData).length > 0 && (<RecordGridWidget
|
||||
key={`${formValues["tableName"]}-${modalDataChangedCounter}`}
|
||||
widgetMetaData={widgetMetaData}
|
||||
data={widgetData}
|
||||
@ -387,7 +387,7 @@ function EntityForm(props: Props): JSX.Element
|
||||
addNewRecordCallback={() => openAddChildRecord(widgetMetaData.name, widgetData)}
|
||||
editRecordCallback={(rowIndex) => openEditChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
||||
deleteRecordCallback={(rowIndex) => deleteChildRecord(widgetMetaData.name, widgetData, rowIndex)}
|
||||
/>;
|
||||
/>);
|
||||
}
|
||||
|
||||
if (widgetMetaData.type == "filterAndColumnsSetup")
|
||||
@ -480,6 +480,8 @@ function EntityForm(props: Props): JSX.Element
|
||||
//////////////////
|
||||
// initial load //
|
||||
//////////////////
|
||||
useEffect(() =>
|
||||
{
|
||||
if (!asyncLoadInited)
|
||||
{
|
||||
setAsyncLoadInited(true);
|
||||
@ -762,6 +764,7 @@ function EntityForm(props: Props): JSX.Element
|
||||
forceUpdate();
|
||||
})();
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@ -881,11 +884,22 @@ function EntityForm(props: Props): JSX.Element
|
||||
let haveAssociationsToPost = false;
|
||||
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");
|
||||
if (!manageAssociationName)
|
||||
{
|
||||
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] = [];
|
||||
haveAssociationsToPost = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (haveAssociationsToPost)
|
||||
{
|
||||
valuesToPost["associations"] = JSON.stringify(associationsToPost);
|
||||
|
Reference in New Issue
Block a user