Skip to content

Commit

Permalink
SCKAN-300 feat: Refresh statement on via/destination type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Nov 11, 2024
1 parent 1d269b9 commit e7260da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 0 additions & 2 deletions backend/composer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ def update(self, request, *args, **kwargs):
origin_ids = request.data.pop("origins", None)
graph_rendering_state_data = request.data.pop("graph_rendering_state", None)

# Call the UpdateModelMixin's update
response = super().update(request, *args, **kwargs)

if response.status_code == status.HTTP_200_OK:
Expand All @@ -418,7 +417,6 @@ def update(self, request, *args, **kwargs):
def partial_update(self, request, *args, **kwargs):
graph_rendering_state_data = request.data.pop("graph_rendering_state", None)

# Call the UpdateModelMixin's partial_update
response = super().partial_update(request, *args, **kwargs)

if response.status_code == status.HTTP_200_OK:
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/components/Forms/StatementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,13 @@ const StatementForm = (props: any) => {
onUpdate: async (selectedOption: string, formId: string) => {
const viaIndex = getConnectionId(formId, statement.vias);
const typeOption = selectedOption as TypeB60Enum;

if (viaIndex) {
try {
await api.composerViaPartialUpdate(viaIndex, {
type: typeOption,
});
refreshStatement()
return ChangeRequestStatus.SAVED;
} catch (error) {
return checkOwnership(
Expand All @@ -266,6 +267,7 @@ const StatementForm = (props: any) => {
await api.composerViaPartialUpdate(viaIndex, {
type: typeOption,
});
refreshStatement()
return ChangeRequestStatus.SAVED;
},
() => {
Expand Down Expand Up @@ -306,7 +308,7 @@ const StatementForm = (props: any) => {
);
},
onUpdate: async (selectedOptions: Option[], formId: any) => {
return await updateEntity({
return await updateEntity({
statementId: statement.id,
selected: selectedOptions,
entityId: getConnectionId(formId, statement.vias),
Expand Down Expand Up @@ -451,10 +453,10 @@ const StatementForm = (props: any) => {
const viaIndex = getConnectionId(formId, statement?.destinations);
const typeOption = selectedOption as TypeC11Enum;
if (viaIndex) {
api
.composerDestinationPartialUpdate(viaIndex, {
type: typeOption,
})
await api.composerDestinationPartialUpdate(viaIndex, {
type: typeOption,
})
refreshStatement()
}
},
},
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/services/CustomDropdownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ export async function updateEntity({
// Ownership error occurred, trigger ownership check
return checkOwnership(
statementId,
() => updateFunction(entityId as number, patchObject), // Re-attempt the update if ownership is reassigned
async () => {
await updateFunction(entityId as number, patchObject); // Re-attempt the update if ownership is reassigned
refreshStatement();
},
() => {
return ChangeRequestStatus.CANCELLED;
}, // Optional: handle post-assignment logic
(owner) => getOwnershipAlertMessage(owner)
);

}
} else {
alert(`No update function found for entity type: ${entityType}`);
Expand Down

0 comments on commit e7260da

Please sign in to comment.