feat: implement ActionBuilder and PolicyEngine API services and scaffold the AddPolicyEngine component.
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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 && defaultVal !== '') {
|
||||
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 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user