Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
119 changes: 67 additions & 52 deletions frontend/src/components/custom-tools/list-of-tools/ListOfTools.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ArrowDownOutlined, PlusOutlined } from "@ant-design/icons";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { Space } from "antd";
import PropTypes from "prop-types";

import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
import { useAlertStore } from "../../../store/alert-store";
Expand All @@ -15,6 +16,38 @@ import { SharePermission } from "../../widgets/share-permission/SharePermission"
import usePostHogEvents from "../../../hooks/usePostHogEvents.js";
import { ImportTool } from "../import-tool/ImportTool";

const DefaultCustomButtons = ({
setOpenImportTool,
isImportLoading,
handleNewProjectBtnClick,
}) => {
return (
<Space gap={16}>
<CustomButton
type="default"
icon={<ArrowDownOutlined />}
onClick={() => setOpenImportTool(true)}
loading={isImportLoading}
>
Import Project
</CustomButton>
<CustomButton
type="primary"
icon={<PlusOutlined />}
onClick={handleNewProjectBtnClick}
>
New Project
</CustomButton>
</Space>
);
};

DefaultCustomButtons.propTypes = {
setOpenImportTool: PropTypes.func.isRequired,
isImportLoading: PropTypes.bool.isRequired,
handleNewProjectBtnClick: PropTypes.func.isRequired,
};

function ListOfTools() {
const [isListLoading, setIsListLoading] = useState(false);
const [openAddTool, setOpenAddTool] = useState(false);
Expand All @@ -23,13 +56,12 @@ function ListOfTools() {
const [editItem, setEditItem] = useState(null);
const { sessionDetails } = useSessionStore();
const { setPostHogCustomEvent } = usePostHogEvents();

const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();

const [listOfTools, setListOfTools] = useState([]);
const [filteredListOfTools, setFilteredListOfTools] = useState([]);
const handleException = useExceptionHandler();
const [isEdit, setIsEdit] = useState(false);
const [promptDetails, setPromptDetails] = useState(null);
const [openSharePermissionModal, setOpenSharePermissionModal] =
Expand Down Expand Up @@ -145,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 @@ -242,28 +270,6 @@ function ListOfTools() {
});
};

const CustomButtons = () => {
return (
<Space gap={16}>
<CustomButton
type="default"
icon={<ArrowDownOutlined />}
onClick={() => setOpenImportTool(true)}
loading={isImportLoading}
>
Import Project
</CustomButton>
<CustomButton
type="primary"
icon={<PlusOutlined />}
onClick={handleNewProjectBtnClick}
>
New Project
</CustomButton>
</Space>
);
};

const handleShare = (_event, promptProject, isEdit) => {
const requestOptions = {
method: "GET",
Expand Down Expand Up @@ -328,16 +334,42 @@ function ListOfTools() {
axiosPrivate(requestOptions)
.then((response) => {
setOpenSharePermissionModal(false);
setAlertDetails({
type: "success",
content: "Sharing settings updated successfully",
});
})
.catch((err) => {
setAlertDetails(handleException(err, "Failed to load"));
});
};

const defaultContent = (
<div className="list-of-tools-body">
<ViewTools
isLoading={isListLoading}
isEmpty={!listOfTools?.length}
listOfTools={filteredListOfTools}
setOpenAddTool={setOpenAddTool}
handleEdit={handleEdit}
handleDelete={handleDelete}
titleProp="tool_name"
descriptionProp="description"
iconProp="icon"
idProp="tool_id"
type="Prompt Project"
handleShare={handleShare}
/>
</div>
);

const CustomButtonsComponent = useCallback(
() => (
<DefaultCustomButtons
setOpenImportTool={setOpenImportTool}
isImportLoading={isImportLoading}
handleNewProjectBtnClick={handleNewProjectBtnClick}
/>
),
[isImportLoading]
);

return (
<>
<ToolNavBar
Expand All @@ -346,27 +378,10 @@ function ListOfTools() {
onSearch={onSearch}
searchList={listOfTools}
setSearchList={setFilteredListOfTools}
CustomButtons={CustomButtons}
CustomButtons={CustomButtonsComponent}
/>
<div className="list-of-tools-layout">
<div className="list-of-tools-island">
<div className="list-of-tools-body">
<ViewTools
isLoading={isListLoading}
isEmpty={!listOfTools?.length}
listOfTools={filteredListOfTools}
setOpenAddTool={setOpenAddTool}
handleEdit={handleEdit}
handleDelete={handleDelete}
titleProp="tool_name"
descriptionProp="description"
iconProp="icon"
idProp="tool_id"
type="Prompt Project"
handleShare={handleShare}
/>
</div>
</div>
<div className="list-of-tools-island">{defaultContent}</div>
</div>
{openAddTool && (
<AddCustomToolFormModal
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
Loading