Merge pull request 'development' (#62) from development into test

Reviewed-on: https://gitea.maskantech.in/gitea_admin/aeroresolve_frontend/pulls/62
This commit is contained in:
Syed Waseem khadri Rafai
2026-09-01 05:33:39 +00:00
4 changed files with 42 additions and 19 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 });
}
};
@@ -800,8 +822,8 @@ export default function AddPolicyEngine() {
// ─── Handlers ──────────────────────────────────────────────────────────────
// Returns the lowest priority (1-10) not already used by an existing rule.
const findFreePriority = () => {
const taken = rules.map(r => r.priority);
const findFreePriority = (currentRules: Rule[]) => {
const taken = currentRules.map(r => r.priority);
for (let p = 1; p <= 10; p++) {
if (!taken.includes(p)) return p;
}
@@ -809,21 +831,21 @@ export default function AddPolicyEngine() {
};
const handleAddRule = () => {
setRules([...rules, {
setRules(prevRules => [...prevRules, {
id: crypto.randomUUID(),
category: '',
priority: findFreePriority(),
priority: findFreePriority(prevRules),
conditions: [{ id: crypto.randomUUID(), condition: '', operator: '', value: '', logic: 'AND' }],
actions: [{ id: crypto.randomUUID(), actionCategoryId: '', actionTypeId: '', logic: 'AND', fieldValues: {} }]
}]);
};
const handleDeleteRule = (ruleId: string) => {
setRules(rules.filter(r => r.id !== ruleId));
setRules(prevRules => prevRules.filter(r => r.id !== ruleId));
};
const handleUpdateRule = (ruleId: string, updates: Partial<Rule>) => {
setRules(rules.map(r => r.id === ruleId ? { ...r, ...updates } : r));
setRules(prevRules => prevRules.map(r => r.id === ruleId ? { ...r, ...updates } : r));
};
// Priorities used by every OTHER rule — a rule may never land on one of these.
@@ -849,7 +871,7 @@ export default function AddPolicyEngine() {
};
const handleAddCondition = (ruleId: string) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return {
...r,
@@ -861,7 +883,7 @@ export default function AddPolicyEngine() {
};
const handleUpdateCondition = (ruleId: string, conditionId: string, updates: Partial<Condition>) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return {
...r,
@@ -873,7 +895,7 @@ export default function AddPolicyEngine() {
};
const handleDeleteCondition = (ruleId: string, conditionId: string) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return { ...r, conditions: r.conditions.filter(c => c.id !== conditionId) };
}
@@ -882,7 +904,7 @@ export default function AddPolicyEngine() {
};
const handleAddAction = (ruleId: string) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return {
...r,
@@ -894,7 +916,7 @@ export default function AddPolicyEngine() {
};
const handleUpdateAction = (ruleId: string, actionId: string, updates: Partial<Action>) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return {
...r,
@@ -906,7 +928,7 @@ export default function AddPolicyEngine() {
};
const handleDeleteAction = (ruleId: string, actionId: string) => {
setRules(rules.map(r => {
setRules(prevRules => prevRules.map(r => {
if (r.id === ruleId) {
return { ...r, actions: r.actions.filter(a => a.id !== actionId) };
}
@@ -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;