Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ function CustomDataSettings() {
const [jsonError, setJsonError] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [hasChanges, setHasChanges] = useState(false);
const [isSaved, setIsSaved] = useState(false);
const { sessionDetails } = useSessionStore();
const { details, isPublicSource, updateCustomTool } = useCustomToolStore();
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();

// Initialize editor with current custom_data
// Initialize editor with current custom_data (only on tab switch)
useEffect(() => {
const customData = details?.custom_data;
if (customData && Object.keys(customData).length > 0) {
Expand All @@ -70,7 +71,8 @@ function CustomDataSettings() {
setJsonValue("{\n \n}");
}
setHasChanges(false);
}, [details?.custom_data]);
setIsSaved(false);
}, [details?.tool_id]);

// Extract variables from active prompts
const extractedVariables = useMemo(() => {
Expand Down Expand Up @@ -113,6 +115,9 @@ function CustomDataSettings() {
const handleEditorChange = (value) => {
setJsonValue(value || "");
setHasChanges(true);
if (isSaved) {
setIsSaved(false);
}

// Validate JSON
try {
Expand Down Expand Up @@ -158,11 +163,8 @@ function CustomDataSettings() {
setIsLoading(true);
axiosPrivate(requestOptions)
.then((res) => {
setAlertDetails({
type: "success",
content: "Custom data saved successfully",
});
setHasChanges(false);
setIsSaved(true);
// Update the store with the new details
const updatedDetails = res?.data;
if (updatedDetails) {
Expand Down Expand Up @@ -292,7 +294,7 @@ function CustomDataSettings() {
loading={isLoading}
disabled={isPublicSource || !!jsonError || !hasChanges}
>
Save
{isSaved ? "Saved" : "Save"}
</CustomButton>
</Space>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ function CustomSynonyms() {
const [rows, setRows] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [currentPage, setCurrentPage] = useState(1);
const [hasChanges, setHasChanges] = useState(false);
const [isSaved, setIsSaved] = useState(false);
const { sessionDetails } = useSessionStore();
const { details, isPublicSource } = useCustomToolStore();
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();

// Reset state on tool switch
useEffect(() => {
setHasChanges(false);
setIsSaved(false);
}, [details?.tool_id]);

useEffect(() => {
const promptGrammar = details?.prompt_grammer;
if (!promptGrammar || Object.keys(promptGrammar).length === 0) {
Expand Down Expand Up @@ -121,6 +129,8 @@ function CustomSynonyms() {
const updatedSynonyms = [...synonyms];
updatedSynonyms[index][propertyName] = value;
setSynonyms(updatedSynonyms);
setHasChanges(true);
setIsSaved(false);
};

const handleAddRow = () => {
Expand All @@ -137,6 +147,8 @@ function CustomSynonyms() {
const updatedSynonyms = [...synonyms];
updatedSynonyms.push(data);
setSynonyms(updatedSynonyms);
setHasChanges(true);
setIsSaved(false);

const newPage = updatedSynonyms?.length / PAGE_SIZE;
if (newPage + 1 > currentPage) {
Expand All @@ -163,15 +175,10 @@ function CustomSynonyms() {
promptGrammar[item.word] = item.synonyms || [];
});

let successMsg = "";
let failureMsg = "";
if (actionType === actionTypes.save) {
successMsg = "Saved synonyms successfully";
failureMsg = "Failed to save synonyms";
} else {
successMsg = "Deleted synonyms successfully";
failureMsg = "Failed to delete synonyms";
}
const failureMsg =
actionType === actionTypes.save
? "Failed to save synonyms"
: "Failed to delete synonyms";

const body = {
prompt_grammer: promptGrammar,
Expand All @@ -193,10 +200,10 @@ function CustomSynonyms() {
if (actionType === actionTypes.delete) {
setSynonyms(listOfSynonyms);
}
setAlertDetails({
type: "success",
content: successMsg,
});
setHasChanges(false);
if (actionType === actionTypes.save) {
setIsSaved(true);
}
})
.catch((err) => {
setAlertDetails(handleException(err, failureMsg));
Expand Down Expand Up @@ -245,9 +252,9 @@ function CustomSynonyms() {
type="primary"
onClick={() => updateSynonyms(synonyms, actionTypes.save)}
loading={isLoading}
disabled={isPublicSource}
disabled={isPublicSource || !hasChanges}
>
Save
{isSaved ? "Saved" : "Save"}
</CustomButton>
</Space>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ function DocumentParser({
);
modifiedDetails["prompts"] = modifiedPrompts;
updateCustomTool({ details: modifiedDetails });
setAlertDetails({
type: "success",
content: "Deleted successfully",
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to delete"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ function ListOfTools() {
(filterToll) => filterToll?.tool_id !== tool.tool_id
);
setListOfTools(tools);
setAlertDetails({
type: "success",
content: `${tool?.tool_name} - Deleted successfully`,
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to Delete"));
Expand Down Expand Up @@ -338,10 +334,6 @@ function ListOfTools() {
axiosPrivate(requestOptions)
.then((response) => {
setOpenSharePermissionModal(false);
setAlertDetails({
type: "success",
content: "Sharing settings updated successfully",
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to load"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ function ManageLlmProfiles() {
defaultLlmProfile: data?.default_profile,
};
updateCustomTool(updatedState);
setAlertDetails({
type: "success",
content: "Default LLM Profile updated successfully",
});
})
.catch((err) => {
handleException(err, "Failed to set default LLM Profile");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function PreAndPostAmbleModal({ type, handleUpdateTool }) {
const [title, setTitle] = useState("");
const [text, setText] = useState("");
const [expandModalVisible, setExpandModalVisible] = useState(false);
const [hasChanges, setHasChanges] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [isSaved, setIsSaved] = useState(false);
const textAreaRef = useRef(null);
const { details, updateCustomTool, isPublicSource } = useCustomToolStore();
const { setAlertDetails } = useAlertStore();
Expand All @@ -34,18 +37,28 @@ function PreAndPostAmbleModal({ type, handleUpdateTool }) {
setTitle("Postamble Settings");
setText(details?.postamble || "");
}
setHasChanges(false);
}, [type, details]);

// Reset isSaved on tool switch (separate from text initialization)
useEffect(() => {
setIsSaved(false);
}, [details?.tool_id]);

const setDefaultPrompt = () => {
if (type === fieldNames.preamble) {
setText(DefaultPrompts.preamble);
} else if (type === fieldNames.postamble) {
setText(DefaultPrompts.postamble);
}
setHasChanges(true);
setIsSaved(false);
};

const handleTextChange = (e) => {
setText(e.target.value);
setHasChanges(true);
setIsSaved(false);
};

const toggleExpandModal = () => {
Expand All @@ -61,6 +74,7 @@ function PreAndPostAmbleModal({ type, handleUpdateTool }) {
if (type === fieldNames.postamble) {
body["postamble"] = text;
}
setIsLoading(true);
handleUpdateTool(body)
.then((res) => {
const data = res?.data;
Expand All @@ -70,13 +84,14 @@ function PreAndPostAmbleModal({ type, handleUpdateTool }) {
};
const updatedDetails = { ...details, ...updatedData };
updateCustomTool({ details: updatedDetails });
setAlertDetails({
type: "success",
content: "Saved successfully",
});
setHasChanges(false);
setIsSaved(true);
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to update."));
})
.finally(() => {
setIsLoading(false);
});
};

Expand Down Expand Up @@ -149,9 +164,10 @@ function PreAndPostAmbleModal({ type, handleUpdateTool }) {
<CustomButton
type="primary"
onClick={handleSave}
disabled={isPublicSource}
loading={isLoading}
disabled={isPublicSource || !hasChanges}
>
Save
{isSaved ? "Saved" : "Save"}
</CustomButton>
</Space>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ function ApiDeployment() {
record.is_active = !record?.is_active;
apiDeploymentsApiService
.updateApiDeployment(record)
.then((res) => {
setAlertDetails({
type: "success",
content: "Status updated successfully",
});
})
.then(() => {})
.catch((err) => {
setAlertDetails(handleException(err));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,6 @@ function ConfigureDs({
if (data) {
addNewItem(data, !!editItemId);
}
setAlertDetails({
type: "success",
content: `Successfully ${
method === "POST" ? "added" : "updated"
} connector`,
});
if (!isConnector && method === "POST") {
updateSession(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ const FileHistoryModal = ({ open, setOpen, workflowId, workflowName }) => {
const handleDeleteSingle = async (fileHistoryId) => {
try {
await workflowApiService.deleteFileHistory(workflowId, fileHistoryId);
setAlertDetails({
type: "success",
message: "File history deleted successfully",
});
// Refresh data
fetchFileHistories(pagination.current, pagination.pageSize);
setSelectedRowKeys([]);
Expand All @@ -262,18 +258,11 @@ const FileHistoryModal = ({ open, setOpen, workflowId, workflowName }) => {

setLoading(true);
try {
const response = await workflowApiService.bulkDeleteFileHistoriesByIds(
await workflowApiService.bulkDeleteFileHistoriesByIds(
workflowId,
selectedRowKeys
);

setAlertDetails({
type: "success",
message:
response?.data?.message ||
`${selectedRowKeys.length} file histories deleted successfully`,
});

// Refresh data
fetchFileHistories(pagination.current, pagination.pageSize);
setSelectedRowKeys([]);
Expand Down Expand Up @@ -358,17 +347,7 @@ const FileHistoryModal = ({ open, setOpen, workflowId, workflowName }) => {
filters.file_path = appliedFilters.filePath;
}

const response = await workflowApiService.bulkClearFileHistories(
workflowId,
filters
);

setAlertDetails({
type: "success",
message:
response?.data?.message ||
`${response?.data?.deleted_count} file histories cleared`,
});
await workflowApiService.bulkClearFileHistories(workflowId, filters);

// Refresh data
fetchFileHistories(1, pagination.pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ function Pipelines({ type }) {
const data = res?.data?.pipeline;
fieldsToUpdate.last_run_status = data?.last_run_status;
fieldsToUpdate.last_run_time = data?.last_run_time;
setAlertDetails({
type: "success",
content: "Pipeline Sync Initiated",
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to sync."));
Expand Down Expand Up @@ -232,12 +228,6 @@ function Pipelines({ type }) {
axiosPrivate(requestOptions)
.then(() => {
getPipelineList();
setAlertDetails({
type: "success",
content: value
? "Pipeline Enabled Successfully"
: "Pipeline Disabled Successfully",
});
})
.catch((err) => {
setAlertDetails(handleException(err));
Expand Down Expand Up @@ -284,10 +274,7 @@ function Pipelines({ type }) {

const clearFileMarkers = async () => {
const workflowId = selectedPorD?.workflow_id;
const success = await clearFileHistory(
workflowId,
"Pipeline File History Cleared Successfully"
);
const success = await clearFileHistory(workflowId);
if (success && openDeleteModal) {
setOpenDeleteModal(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ function DefaultTriad() {
};
axiosPrivate(requestOptions)
.then((res) => {
setAlertDetails({
type: "success",
content: "Default triad setting saved successfully",
});
fetchData();
setIsSubmitEnabled(false);
})
Expand Down
Loading