Merge pull request 'azeem' (#60) from azeem into development

Reviewed-on: https://gitea.maskantech.in/gitea_admin/aeroresolve_frontend/pulls/60
This commit is contained in:
Syed Waseem khadri Rafai
2026-09-01 04:58:27 +00:00
4 changed files with 30 additions and 7 deletions
@@ -68,7 +68,8 @@ export function deleteActionType(id: string): Promise<void> {
// ─── Field Definition Endpoints ──────────────────────────────────────────────
export function getFieldDefinitions(actionTypeId: string): Promise<FieldDefinition[]> {
return ApiClient.get<any, FieldDefinition[]>(`/master-data/action-types/${actionTypeId}/fields`);
return ApiClient.get<any, FieldDefinition[]>(`/master-data/action-types/${actionTypeId}/fields`)
.then(res => Array.isArray(res) ? res.sort((a, b) => (a.displayOrder ?? 0) - (b.displayOrder ?? 0)) : []);
}
export function createFieldDefinition(actionTypeId: string, payload: FieldDefinitionFormData): Promise<FieldDefinition> {
@@ -95,7 +95,7 @@ export default function ActionBuilderPage() {
placeholder: '',
helpText: '',
width: 'full',
section: 'General Information',
section: '',
displayOrder: 1,
isActive: true,
validationJson: { min: undefined, max: undefined, regex: '' },
@@ -387,7 +387,7 @@ export default function ActionBuilderPage() {
placeholder: '',
helpText: '',
width: 'full',
section: 'General Information',
section: '',
displayOrder: fields.length + 1,
isActive: true,
validationJson: { min: undefined, max: undefined, regex: '' },
@@ -409,7 +409,7 @@ export default function ActionBuilderPage() {
placeholder: f.placeholder || '',
helpText: f.helpText || '',
width: f.width || 'full',
section: f.section || 'General Information',
section: f.section || '',
displayOrder: f.displayOrder || 1,
isActive: f.isActive !== false,
validationJson: f.validationJson || { min: undefined, max: undefined, regex: '' },
+2 -2
View File
@@ -210,7 +210,7 @@ export function getOperatorOptions(): Promise<OptionItem[]> {
export function getActionTypeFields(actionTypeId: string): Promise<ActionTypeField[]> {
if (!actionTypeId) return Promise.resolve([]);
return ApiClient.get<any, ActionTypeField[]>(`/master-data/action-types/${actionTypeId}/fields`)
.then((res) => (Array.isArray(res) ? res.filter((f) => f.isActive !== false) : []))
.then((res) => (Array.isArray(res) ? res.filter((f) => f.isActive !== false).sort((a, b) => (a.displayOrder ?? 0) - (b.displayOrder ?? 0)) : []))
.catch(() => []);
}
@@ -321,7 +321,7 @@ export function getConditionGroupsForCategory(categoryCodeOrId: string): Promise
export function getConditionFieldsForGroup(groupIdOrCode: string): Promise<any[]> {
if (!groupIdOrCode) return Promise.resolve([]);
return ApiClient.get<any, any[]>(`/master-data/condition-groups/${groupIdOrCode}/fields`)
.then((res) => (Array.isArray(res) ? res.filter((f) => f.isActive !== false) : []))
.then((res) => (Array.isArray(res) ? res.filter((f) => f.isActive !== false).sort((a, b) => (a.displayOrder ?? 0) - (b.displayOrder ?? 0)) : []))
.catch(() => []);
}
@@ -396,6 +396,17 @@ export default function AddPolicyEngine() {
const fields = await getActionTypeFields(selectedTypeId);
setActionTypeFieldsMap((prev) => ({ ...prev, [selectedTypeId]: fields }));
// Pre-populate default values for the new action
const initialFieldValues: Record<string, any> = {};
fields.forEach((f) => {
const defaultVal = f.defaultValue ?? (f as any).default_value ?? (f as any).defaultValueJson ?? (f as any).default_value_json;
if (defaultVal !== undefined && defaultVal !== null) {
initialFieldValues[f.fieldCode] = defaultVal;
}
});
handleUpdateAction(ruleId, actionId, { fieldValues: initialFieldValues });
// Pre-fetch lookup options for fields requiring lookupSource
const sourcesToFetch = new Set<string>();
fields.forEach((f) => {
@@ -413,6 +424,17 @@ export default function AddPolicyEngine() {
} finally {
setLoadingActionFields((prev) => ({ ...prev, [selectedTypeId]: false }));
}
} else {
// Fields already loaded in map, just pre-populate default values
const fields = actionTypeFieldsMap[selectedTypeId] || [];
const initialFieldValues: Record<string, any> = {};
fields.forEach((f) => {
const defaultVal = f.defaultValue ?? (f as any).default_value ?? (f as any).defaultValueJson ?? (f as any).default_value_json;
if (defaultVal !== undefined && defaultVal !== null && defaultVal !== '') {
initialFieldValues[f.fieldCode] = defaultVal;
}
});
handleUpdateAction(ruleId, actionId, { fieldValues: initialFieldValues });
}
};
@@ -1422,7 +1444,7 @@ export default function AddPolicyEngine() {
(field as any).default_value_json;
const effectiveVal =
rawVal !== undefined && rawVal !== null && rawVal !== ''
rawVal !== undefined && rawVal !== null
? rawVal
: defaultVal;