diff --git a/app/admin/page.tsx b/app/admin/page.tsx
index 17ec803..d5823e7 100644
--- a/app/admin/page.tsx
+++ b/app/admin/page.tsx
@@ -1,7 +1,7 @@
"use client";
import { useState, useEffect } from "react";
import Link from "next/link";
-import { Table, Input, Button, Flex } from "antd";
+import { Table, Input, Button, Flex, Tooltip } from "antd";
import { ColumnsType, TablePaginationConfig } from "antd/es/table";
import { FilterValue } from "antd/es/table/interface";
import { HomeOutlined } from "@ant-design/icons";
@@ -14,8 +14,6 @@ enum ACTION_STATUS {
DELETE = "delete",
}
-const PAGE_SIZE = 15;
-
interface TableParams {
pagination?: TablePaginationConfig;
searchTerm?: string;
@@ -73,10 +71,20 @@ export default function Admin() {
setRules(newRules);
};
- const deleteRule = async (index: number) => {
- const { current, pageSize } = tableParams?.pagination || {};
- const deletionIndex = ((current || 1) - 1) * (pageSize || PAGE_SIZE) + index;
- const newRules = [...rules.slice(0, deletionIndex), ...rules.slice(deletionIndex + 1, rules.length)];
+ const resetDraft = async (rule: RuleInfo) => {
+ setIsLoading(true);
+ try {
+ await updateRuleData(rule._id, rule);
+ } catch (error) {
+ console.error(`Error reseting draft for rule ${rule._id}: ${error}`);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ const deleteRule = (index: number) => {
+ const newRules = [...rules];
+ newRules.splice(index, 1);
setRules(newRules);
};
@@ -149,20 +157,38 @@ export default function Admin() {
{
dataIndex: "delete",
width: "60px",
- render: (value: string, _: RuleInfo, index: number) => (
-
- ),
+ render: (value: string, _: RuleInfo, index: number) => {
+ return (
+ <>
+ {_.isPublished ? (
+
+
+
+ ) : (
+
+
+
+ )}
+ >
+ );
+ },
},
{
dataIndex: "view",
width: "60px",
- render: (_: string, { _id }: RuleInfo) => (
-
-
-
- ),
+ render: (_: string, { _id, isPublished }: RuleInfo) => {
+ const ruleLink = `/rule/${_id}`;
+ const draftLink = `${ruleLink}?version=draft`;
+ return (
+
+
+
+ );
+ },
},
];
diff --git a/app/components/RuleManager/RuleManager.tsx b/app/components/RuleManager/RuleManager.tsx
index cf21fdc..3f2fa36 100644
--- a/app/components/RuleManager/RuleManager.tsx
+++ b/app/components/RuleManager/RuleManager.tsx
@@ -103,6 +103,7 @@ export default function RuleManager({
if (runContext) {
console.info("Simulate:", runContext);
try {
+ message.destroy();
const data = await postDecision(ruleContent, runContext);
console.info("Simulation Results:", data, data?.result);
// Check if data.result is an array and throw error as object is required
@@ -114,7 +115,7 @@ export default function RuleManager({
// Set the results of the simulation
setResultsOfSimulation(data?.result);
} catch (e: any) {
- message.error("Error during simulation run: " + e);
+ message.error("Error during simulation run: " + e, 10);
console.error("Error during simulation run:", e);
}
} else {
diff --git a/app/utils/api.ts b/app/utils/api.ts
index 34b11f6..9ecb3bd 100644
--- a/app/utils/api.ts
+++ b/app/utils/api.ts
@@ -112,8 +112,14 @@ export const postDecision = async (ruleContent: DecisionGraphType, context: unkn
});
return data;
} catch (error) {
- console.error(`Error simulating decision: ${error}`);
- throw error;
+ if (axios.isAxiosError(error) && error.response) {
+ const errorMessage = error.response.data.message;
+ console.error(errorMessage);
+ throw new Error(errorMessage);
+ } else {
+ console.error(`Error simulating decision: ${error}`);
+ throw error;
+ }
}
};