Skip to content

Commit de5df9c

Browse files
authored
Fix: avoid enabling disabled fields on provisioning error (#30)
1 parent caa5b4d commit de5df9c

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/app/screens/product-action-screen/product-action-screen.component.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,37 @@ describe('ProductActionScreenComponent', () => {
997997
expect(paramNames).toContain('visible_param');
998998
expect(paramNames).toContain('another_visible_param');
999999
});
1000+
1001+
it('should re-enable only non-disabled params when HTTP POST fails', () => {
1002+
const actionParams: ProductActionParameter[] = [
1003+
{ name: 'project_key', type: 'string', required: true, disabled: true } as ProductActionParameter,
1004+
{ name: 'param_1', type: 'string', required: true, disabled: false } as ProductActionParameter,
1005+
{ name: 'param_2', type: 'string', required: false } as ProductActionParameter,
1006+
];
1007+
component.action = {
1008+
id: 'fakeAction',
1009+
url: '/api/action',
1010+
parameters: actionParams,
1011+
triggerMessage: '',
1012+
requestable: true,
1013+
restrictionMessage: '',
1014+
label: 'Fake Action'
1015+
} as ProductAction;
1016+
component.product = { id: 'fakeId', title: 'fakeProduct' } as AppProduct;
1017+
component.actionParams = actionParams;
1018+
component.formGroup = component['fb'].group({
1019+
project_key: [{ value: 'project 1', disabled: true }],
1020+
param_1: ['value1'],
1021+
param_2: ['value2']
1022+
});
1023+
1024+
component.onActionClick();
1025+
1026+
const req: TestRequest = httpTesting.expectOne('/api/action');
1027+
req.flush('error', { status: 500, statusText: 'Internal Server Error' });
1028+
1029+
expect(component.formGroup.get('project_key')?.disabled).toBeTrue();
1030+
expect(component.formGroup.get('param_1')?.enabled).toBeTrue();
1031+
expect(component.formGroup.get('param_2')?.enabled).toBeTrue();
1032+
});
10001033
});

src/app/screens/product-action-screen/product-action-screen.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ export class ProductActionScreenComponent implements OnInit, OnDestroy {
403403
subject: 'only_toast',
404404
title: `${errorMessage}`
405405
} as AppShellNotification, 8000);
406-
this.formGroup.enable();
406+
this.actionParams.filter(param => !param.disabled).forEach(param => {
407+
this.formGroup.get(param.name)?.enable();
408+
});
407409
},
408410
complete: () => { }
409411
});

0 commit comments

Comments
 (0)