Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

FEAT: Implement Drag-and-Drop Reordering for Prompts, Refactor Prompt Cards, and Update Export Modal Messaging (#815)

Tahier Hussaine4811a4c1ec8
diff --git a/frontend/src/components/custom-tools/document-parser/DocumentParser.jsx b/frontend/src/components/custom-tools/document-parser/DocumentParser.jsx
index 18b603b50..0156dc806 100644
--- a/frontend/src/components/custom-tools/document-parser/DocumentParser.jsx
+++ b/frontend/src/components/custom-tools/document-parser/DocumentParser.jsx
@@ -1,7 +1,5 @@
import PropTypes from "prop-types";
import { useEffect, useRef, useState } from "react";
-import { DndProvider } from "react-dnd";
-import { HTML5Backend } from "react-dnd-html5-backend";
import "./DocumentParser.css";
import { promptType } from "../../../helpers/GetStaticData";
@@ -11,17 +9,14 @@ import { useCustomToolStore } from "../../../store/custom-tool-store";
import { useSessionStore } from "../../../store/session-store";
import { EmptyState } from "../../widgets/empty-state/EmptyState";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
-import { PromptDnd } from "../prompt-card/PrompDnd";
+import { PromptCardWrapper } from "../prompt-card/PromptCardWrapper";
import { usePromptOutputStore } from "../../../store/prompt-output-store";
let promptPatchApiSps;
-let promptReorderApiSps;
let SpsPromptsEmptyState;
try {
promptPatchApiSps =
require("../../../plugins/simple-prompt-studio/helper").promptPatchApiSps;
- promptReorderApiSps =
- require("../../../plugins/simple-prompt-studio/helper").promptReorderApiSps;
SpsPromptsEmptyState =
require("../../../plugins/simple-prompt-studio/SpsPromptsEmptyState").SpsPromptsEmptyState;
} catch {
@@ -46,7 +41,7 @@ function DocumentParser({
useEffect(() => {
const outputTypeData = getDropdownItems("output_type") || {};
- const dropdownList1 = Object.keys(outputTypeData).map((item) => {
+ const dropdownList1 = Object.keys(outputTypeData)?.map((item) => {
return { value: outputTypeData[item] };
});
setEnforceTypeList(dropdownList1);
@@ -54,7 +49,7 @@ function DocumentParser({
return () => {
// Set the prompts with updated changes when the component is unmounted
const modifiedDetails = { ...details };
- const modifiedPrompts = [...(modifiedDetails?.prompts || [])].map(
+ const modifiedPrompts = [...(modifiedDetails?.prompts || [])]?.map(
(item) => {
const itemPromptId = item?.prompt_id;
if (itemPromptId && updatedPromptsCopy[itemPromptId]) {
@@ -160,79 +155,6 @@ function DocumentParser({
});
};
- const moveItem = (startIndex, endIndex) => {
- if (startIndex === endIndex) {
- return;
- }
-
- // Clone details and prompts
- const updatedPrompts = [...(details?.prompts || [])];
-
- // Move the item within the updated prompts array
- const [movedStep] = updatedPrompts.splice(startIndex, 1);
- updatedPrompts.splice(endIndex, 0, movedStep);
-
- // Modify the prompts order and update
- const modifiedDetails = { ...details, prompts: updatedPrompts };
- updateCustomTool({ details: modifiedDetails });
-
- // Prepare the body for the POST request
- const body = {
- start_sequence_number: details.prompts[startIndex]?.sequence_number,
- end_sequence_number: details.prompts[endIndex]?.sequence_number,
- prompt_id: details.prompts[startIndex]?.prompt_id,
- };
-
- let url = promptUrl("reorder/");
- if (isSimplePromptStudio) {
- url = promptReorderApiSps;
- }
-
- const requestOptions = {
- method: "POST",
- url,
- headers: {
- "X-CSRFToken": sessionDetails?.csrfToken,
- "Content-Type": "application/json",
- },
- data: body,
- };
-
- axiosPrivate(requestOptions)
- .then((res) => {
- const data = res?.data || [];
-
- // Update sequence numbers based on the response
- handleMoveItemSuccess(updatedPrompts, data);
- })
- .catch((err) => {
- // Revert to the original prompts on error
- updateCustomTool({
- details: { ...details, prompts: details?.prompts },
- });
- setAlertDetails(handleException(err, "Failed to re-order the prompts"));
- });
- };
-
- const handleMoveItemSuccess = (updatedPrompts, updatedSequenceNums) => {
- const updatedPromptSequenceNum = updatedPrompts.map((promptItem) => {
- const newPromptSeqNum = updatedSequenceNums.find(
- (item) => item?.id === promptItem?.prompt_id
- );
- if (newPromptSeqNum) {
- return {
- ...promptItem,
- sequence_number: newPromptSeqNum.sequence_number,
- };
- }
- return promptItem;
- });
-
- updateCustomTool({
- details: { ...details, prompts: updatedPromptSequenceNum },
- });
- };
-
const getPromptOutputs = (promptId) => {
const keys = Object.keys(promptOutputs || {});
@@ -263,26 +185,22 @@ function DocumentParser({
return (
<div className="doc-parser-layout">
- <DndProvider backend={HTML5Backend}>
- {details?.prompts.map((item, index) => {
- return (
- <div key={item.prompt_id}>
- <div className="doc-parser-pad-top" />
- <PromptDnd
- item={item}
- index={index}
- handleChangePromptCard={handleChangePromptCard}
- handleDelete={handleDelete}
- moveItem={moveItem}
- outputs={getPromptOutputs(item?.prompt_id)}
- enforceTypeList={enforceTypeList}
- setUpdatedPromptsCopy={setUpdatedPromptsCopy}
- />
- <div ref={bottomRef} className="doc-parser-pad-bottom" />
- </div>
- );
- })}
- </DndProvider>
+ {details?.prompts?.map((item) => {
+ return (
+ <div key={item.prompt_id}>
+ <div className="doc-parser-pad-top" />
+ <PromptCardWrapper
+ item={item}
+ handleChangePromptCard={handleChangePromptCard}
+ handleDelete={handleDelete}
+ outputs={getPromptOutputs(item?.prompt_id)}
+ enforceTypeList={enforceTypeList}
+ setUpdatedPromptsCopy={setUpdatedPromptsCopy}
+ />
+ <div ref={bottomRef} className="doc-parser-pad-bottom" />
+ </div>
+ );
+ })}
</div>
);
}
diff --git a/frontend/src/components/custom-tools/export-tool/ExportTool.jsx b/frontend/src/components/custom-tools/export-tool/ExportTool.jsx
index 55d477a71..293ed6c15 100644
--- a/frontend/src/components/custom-tools/export-tool/ExportTool.jsx
+++ b/frontend/src/components/custom-tools/export-tool/ExportTool.jsx
@@ -94,7 +94,9 @@ function ExportTool({
const shareWithUsers = () => {
if (sharingOption === SHARE_ALL) {
- return <Typography.Text>Shared with everyone</Typography.Text>;
+ return (
+ <Typography.Text>Shared with everyone in current org</Typography.Text>
+ );
}
return (
<>
@@ -177,7 +179,9 @@ function ExportTool({
value={sharingOption}
className="export-per-radio"
>
- <Radio value={SHARE_ALL}>Share with everyone</Radio>
+ <Radio value={SHARE_ALL}>
+ Share with everyone in current org
+ </Radio>
<Radio value={SHARE_CUSTOM}>Custom share</Radio>
</Radio.Group>
)}
diff --git a/frontend/src/components/custom-tools/prompt-card/PrompDnd.jsx b/frontend/src/components/custom-tools/prompt-card/PromptCardWrapper.jsx
similarity index 72%
rename from frontend/src/components/custom-tools/prompt-card/PrompDnd.jsx
rename to frontend/src/components/custom-tools/prompt-card/PromptCardWrapper.jsx
index 3f1bd2d29..2fd4c65b4 100644
--- a/frontend/src/components/custom-tools/prompt-card/PrompDnd.jsx
+++ b/frontend/src/components/custom-tools/prompt-card/PromptCardWrapper.jsx
@@ -1,6 +1,5 @@
import PropTypes from "prop-types";
-import { useDrag, useDrop } from "react-dnd";
-import { memo, useRef } from "react";
+import { memo } from "react";
import { NotesCard } from "../notes-card/NotesCard";
import { PromptCard } from "./PromptCard";
@@ -9,42 +8,22 @@ import { useCustomToolStore } from "../../../store/custom-tool-store";
import usePromptRun from "../../../hooks/usePromptRun";
import { usePromptRunStatusStore } from "../../../store/prompt-run-status-store";
-const PromptDnd = memo(function PromptDnd({
+const PromptCardWrapper = memo(function PromptCardWrapper({
item,
- index,
handleChangePromptCard,
handleDelete,
- moveItem,
outputs,
enforceTypeList,
setUpdatedPromptsCopy,
}) {
- const ref = useRef(null);
const { isSimplePromptStudio } = useCustomToolStore();
const { handlePromptRunRequest } = usePromptRun();
const promptRunStatus = usePromptRunStatusStore(
(state) => state?.promptRunStatus?.[item?.prompt_id] || {}
);
- const [, drop] = useDrop({
- accept: "PROMPT_CARD",
- drop: (draggedItem) => {
- moveItem(/* Start Index*/ draggedItem?.index, /* Drop Index*/ index);
- },
- });
-
- const [, drag] = useDrag({
- type: "PROMPT_CARD",
- item: { index },
- collect: (monitor) => ({
- isDragging: monitor.isDragging(),
- }),
- });
-
- drag(drop(ref));
-
return (
- <div ref={ref}>
+ <div>
{(item.prompt_type === promptType.prompt || isSimplePromptStudio) && (
<PromptCard
promptDetails={item}
@@ -71,17 +50,15 @@ const PromptDnd = memo(function PromptDnd({
);
});
-PromptDnd.displayName = "PromptDnd";
+PromptCardWrapper.displayName = "PromptCardWrapper";
-PromptDnd.propTypes = {
+PromptCardWrapper.propTypes = {
item: PropTypes.object.isRequired,
- index: PropTypes.number.isRequired,
handleChangePromptCard: PropTypes.func.isRequired,
handleDelete: PropTypes.func.isRequired,
- moveItem: PropTypes.func.isRequired,
outputs: PropTypes.object.isRequired,
enforceTypeList: PropTypes.array.isRequired,
setUpdatedPromptsCopy: PropTypes.func.isRequired,
};
-export { PromptDnd };
+export { PromptCardWrapper };
diff --git a/frontend/src/components/custom-tools/prompts-reorder/DraggablePrompt.jsx b/frontend/src/components/custom-tools/prompts-reorder/DraggablePrompt.jsx
new file mode 100644
index 000000000..330af3700
--- /dev/null
+++ b/frontend/src/components/custom-tools/prompts-reorder/DraggablePrompt.jsx
@@ -0,0 +1,88 @@
+import { memo, useRef } from "react";
+import PropTypes from "prop-types";
+import { useDrag, useDrop } from "react-dnd";
+import "./PromptsReorder.css";
+import { Card, Typography } from "antd";
+
+const ItemTypes = {
+ PROMPT: "prompt",
+};
+
+function DraggablePrompt({ prompt, index, movePrompt, onDrop, cancelDrag }) {
+ const ref = useRef(null);
+
+ const [{ handlerId }, drop] = useDrop({
+ accept: ItemTypes.PROMPT,
+ hover: (item, monitor) => {
+ if (!ref.current) return;
+
+ const dragIndex = item.index;
+ const hoverIndex = index;
+
+ if (dragIndex === hoverIndex) return;
+
+ // Move the item visually during drag
+ movePrompt(dragIndex, hoverIndex);
+
+ // Update the index for dragged item
+ item.index = hoverIndex;
+ },
+ drop: () => {
+ // Return the drop result
+ return { index };
+ },
+ collect: (monitor) => ({
+ handlerId: monitor.getHandlerId(),
+ }),
+ });
+
+ const [{ isDragging }, drag] = useDrag({
+ type: ItemTypes.PROMPT,
+ item: { id: prompt.prompt_key, index, originalIndex: index },
+ end: (item, monitor) => {
+ if (!monitor.didDrop()) {
+ // Drag was canceled, revert back
+ cancelDrag();
+ return;
+ }
+ const dropResult = monitor.getDropResult();
+ if (dropResult) {
+ const { originalIndex } = item;
+ const toIndex = dropResult.index;
+ onDrop(originalIndex, toIndex);
+ }
+ },
+ collect: (monitor) => ({
+ isDragging: monitor.isDragging(),
+ }),
+ });
+
+ // Connect drag and drop refs
+ drag(drop(ref));
+
+ return (
+ <Card
+ ref={ref}
+ className={`draggable-prompt prompt-card-bg-col1 ${
+ isDragging ? "dragging" : ""
+ }`}
+ data-handler-id={handlerId}
+ >
+ <Typography.Text strong>{prompt?.prompt_key}</Typography.Text>
+ </Card>
+ );
+}
+
+DraggablePrompt.propTypes = {
+ prompt: PropTypes.shape({
+ prompt_id: PropTypes.string.isRequired,
+ prompt_key: PropTypes.string.isRequired,
+ sequence_number: PropTypes.number.isRequired,
+ }).isRequired,
+ index: PropTypes.number.isRequired,
+ movePrompt: PropTypes.func.isRequired,
+ onDrop: PropTypes.func.isRequired,
+ cancelDrag: PropTypes.func.isRequired,
+};
+
+export default memo(DraggablePrompt);
diff --git a/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.css b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.css
new file mode 100644
index 000000000..c4efa8ee7
--- /dev/null
+++ b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.css
@@ -0,0 +1,14 @@
+.prompts-container {
+ max-height: 80vh;
+ width: 100%;
+ overflow-y: auto;
+}
+
+.draggable-prompt {
+ cursor: grab;
+ transition: transform 0.2s ease-in-out;
+}
+
+.draggable-prompt.dragging {
+ opacity: 0.5;
+}
diff --git a/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.jsx b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.jsx
new file mode 100644
index 000000000..286f442b1
--- /dev/null
+++ b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorder.jsx
@@ -0,0 +1,171 @@
+import { useEffect, useState, useRef, useCallback, useMemo } from "react";
+import PropTypes from "prop-types";
+import { DndProvider } from "react-dnd";
+import { HTML5Backend } from "react-dnd-html5-backend";
+import { Space } from "antd";
+
+import { useCustomToolStore } from "../../../store/custom-tool-store";
+import DraggablePrompt from "./DraggablePrompt";
+import "./PromptsReorder.css";
+import { useSessionStore } from "../../../store/session-store";
+import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
+import { useAlertStore } from "../../../store/alert-store";
+import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
+
+function PromptsReorder({ isOpen, updateReorderedStatus }) {
+ const [listOfPrompts, setListOfPrompts] = useState([]);
+ const previousListOfPrompts = useRef([]);
+ const { details } = useCustomToolStore();
+ const { sessionDetails } = useSessionStore();
+ const axiosPrivate = useAxiosPrivate();
+ const { setAlertDetails } = useAlertStore();
+ const handleException = useExceptionHandler();
+
+ useEffect(() => {
+ if (!isOpen) {
+ setListOfPrompts([]);
+ return;
+ }
+
+ const prompts = details?.prompts || [];
+ setListOfPrompts(
+ prompts?.map((prompt) => ({
+ prompt_key: prompt.prompt_key,
+ prompt_id: prompt.prompt_id,
+ sequence_number: prompt.sequence_number,
+ }))
+ );
+ }, [isOpen, details]);
+
+ const movePrompt = useCallback(
+ (fromIndex, toIndex) => {
+ if (fromIndex === toIndex) return;
+
+ // Store the previous state if not already stored
+ if (!previousListOfPrompts.current?.length) {
+ previousListOfPrompts.current = listOfPrompts;
+ }
+
+ setListOfPrompts((prevPrompts) => {
+ const updatedPrompts = [...prevPrompts];
+ const [movedItem] = updatedPrompts.splice(fromIndex, 1);
+ updatedPrompts.splice(toIndex, 0, movedItem);
+ return updatedPrompts;
+ });
+ },
+ [listOfPrompts]
+ );
+
+ const handleDropSuccess = useCallback((data) => {
+ const responseData = data || [];
+ const sequenceMap = responseData.reduce((acc, item) => {
+ acc[item.id] = item.sequence_number;
+ return acc;
+ }, {});
+
+ setListOfPrompts((prevPrompts) => {
+ const updatedPrompts = prevPrompts?.map((prompt) => {
+ const newSequenceNumber = sequenceMap[prompt.prompt_id];
+ if (newSequenceNumber !== undefined) {
+ return { ...prompt, sequence_number: newSequenceNumber };
+ }
+ return prompt;
+ });
+
+ // Sort the prompts based on new sequence numbers
+ updatedPrompts.sort((a, b) => a.sequence_number - b.sequence_number);
+ return updatedPrompts;
+ });
+
+ previousListOfPrompts.current = [];
+ }, []);
+
+ const handleDropError = useCallback(
+ (err) => {
+ // Revert back the listOfPrompts state
+ setListOfPrompts(previousListOfPrompts.current);
+ previousListOfPrompts.current = [];
+ setAlertDetails(handleException(err, "Failed to reorder the prompts"));
+ },
+ [handleException, setAlertDetails]
+ );
+
+ const onDrop = useCallback(
+ async (fromIndex, toIndex) => {
+ if (fromIndex === toIndex) return;
+
+ updateReorderedStatus(true);
+
+ const body = {
+ start_sequence_number:
+ previousListOfPrompts.current[fromIndex]?.sequence_number,
+ end_sequence_number:
+ previousListOfPrompts.current[toIndex]?.sequence_number,
+ prompt_id: previousListOfPrompts.current[fromIndex]?.prompt_id,
+ };
+
+ const requestOptions = {
+ method: "POST",
+ url: `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/prompt/reorder/`,
+ headers: {
+ "X-CSRFToken": sessionDetails?.csrfToken,
+ "Content-Type": "application/json",
+ },
+ data: body,
+ };
+
+ try {
+ const res = await axiosPrivate(requestOptions);
+ handleDropSuccess(res?.data);
+ } catch (err) {
+ handleDropError(err);
+ }
+ },
+ [
+ axiosPrivate,
+ handleDropError,
+ handleDropSuccess,
+ previousListOfPrompts,
+ sessionDetails?.csrfToken,
+ sessionDetails?.orgId,
+ updateReorderedStatus,
+ ]
+ );
+
+ const cancelDrag = useCallback(() => {
+ if (previousListOfPrompts.current?.length) {
+ setListOfPrompts(previousListOfPrompts.current);
+ previousListOfPrompts.current = [];
+ }
+ }, []);
+
+ const renderedPrompts = useMemo(
+ () =>
+ listOfPrompts?.map((prompt, index) => (
+ <DraggablePrompt
+ key={prompt.prompt_key}
+ index={index}
+ prompt={prompt}
+ movePrompt={movePrompt}
+ onDrop={onDrop}
+ cancelDrag={cancelDrag}
+ />
+ )),
+ [listOfPrompts, movePrompt, onDrop, cancelDrag]
+ );
+
+ return (
+ <DndProvider backend={HTML5Backend}>
+ <Space direction="vertical" className="prompts-container">
+ {renderedPrompts}
+ </Space>
+ </DndProvider>
+ );
+}
+
+PromptsReorder.propTypes = {
+ isOpen: PropTypes.bool.isRequired,
+ updateReorderedStatus: PropTypes.func.isRequired,
+};
+
+export { PromptsReorder };
diff --git a/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderModal.jsx b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderModal.jsx
new file mode 100644
index 000000000..af0157151
--- /dev/null
+++ b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderModal.jsx
@@ -0,0 +1,30 @@
+import { Modal } from "antd";
+import PropTypes from "prop-types";
+
+import { PromptsReorder } from "./PromptsReorder";
+
+function PromptsReorderModal({ open, setOpen, updateReorderedStatus }) {
+ return (
+ <Modal
+ open={open}
+ onCancel={() => setOpen(false)}
+ title="Reorder Prompts"
+ footer={null}
+ maskClosable={false}
+ centered
+ >
+ <PromptsReorder
+ isOpen={open}
+ updateReorderedStatus={updateReorderedStatus}
+ />
+ </Modal>
+ );
+}
+
+PromptsReorderModal.propTypes = {
+ open: PropTypes.bool.isRequired,
+ setOpen: PropTypes.func.isRequired,
+ updateReorderedStatus: PropTypes.func.isRequired,
+};
+
+export { PromptsReorderModal };
diff --git a/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderTitle.jsx b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderTitle.jsx
new file mode 100644
index 000000000..43838b23f
--- /dev/null
+++ b/frontend/src/components/custom-tools/prompts-reorder/PromptsReorderTitle.jsx
@@ -0,0 +1,15 @@
+import { InfoCircleOutlined } from "@ant-design/icons";
+import { Space, Tooltip, Typography } from "antd";
+
+function PromptsReorderTitle() {
+ return (
+ <Space>
+ <Typography.Text>Reorder Prompts</Typography.Text>
+ <Tooltip title="Drag and drop the prompts to arrange them in your desired order.">
+ <InfoCircleOutlined />
+ </Tooltip>
+ </Space>
+ );
+}
+
+export { PromptsReorderTitle };
diff --git a/frontend/src/components/custom-tools/tools-main/ToolsMainActionBtns.jsx b/frontend/src/components/custom-tools/tools-main/ToolsMainActionBtns.jsx
index ee31930e7..5a41c106a 100644
--- a/frontend/src/components/custom-tools/tools-main/ToolsMainActionBtns.jsx
+++ b/frontend/src/components/custom-tools/tools-main/ToolsMainActionBtns.jsx
@@ -1,11 +1,17 @@
-import { BarChartOutlined } from "@ant-design/icons";
+import { BarChartOutlined, UnorderedListOutlined } from "@ant-design/icons";
import { Button, Space, Tooltip } from "antd";
-import { useNavigate } from "react-router-dom";
+import { useNavigate, useParams } from "react-router-dom";
+import { useEffect, useRef, useState, useCallback, useMemo } from "react";
import { useCustomToolStore } from "../../../store/custom-tool-store";
import usePostHogEvents from "../../../hooks/usePostHogEvents";
import { useTokenUsageStore } from "../../../store/token-usage-store";
import { RunAllPrompts } from "../prompt-card/RunAllPrompts";
+import { PromptsReorderModal } from "../prompts-reorder/PromptsReorderModal";
+import { useSessionStore } from "../../../store/session-store";
+import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
+import { useAlertStore } from "../../../store/alert-store";
+import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
// Import single pass related components
let RunSinglePassBtn;
@@ -30,10 +36,14 @@ try {
ChallengeModal =
require("../../../plugins/challenge-modal/ChallengeModal").ChallengeModal;
} catch {
- // The component will remain null of it is not available
+ // The component will remain undefined if it is not available
}
function ToolsMainActionBtns() {
+ const [openReorderModal, setOpenReorderModal] = useState(false);
+ const [isNewOrderLoading, setIsNewOrderLoading] = useState(false);
+ const isReordered = useRef(false);
+ const { id } = useParams();
const {
isMultiPassExtractLoading,
singlePassExtractMode,
@@ -41,13 +51,23 @@ function ToolsMainActionBtns() {
isSimplePromptStudio,
defaultLlmProfile,
selectedDoc,
+ updateCustomTool,
} = useCustomToolStore();
+
const navigate = useNavigate();
const { setPostHogCustomEvent } = usePostHogEvents();
const { tokenUsage } = useTokenUsageStore();
- const tokenUsageId = `single_pass__${defaultLlmProfile}__${selectedDoc?.document_id}`;
+ const { sessionDetails } = useSessionStore();
+ const axiosPrivate = useAxiosPrivate();
+ const { setAlertDetails } = useAlertStore();
+ const handleException = useExceptionHandler();
+
+ const tokenUsageId = useMemo(
+ () => `single_pass__${defaultLlmProfile}__${selectedDoc?.document_id}`,
+ [defaultLlmProfile, selectedDoc?.document_id]
+ );
- const handleOutputAnalyzerBtnClick = () => {
+ const handleOutputAnalyzerBtnClick = useCallback(() => {
navigate("outputAnalyzer");
try {
@@ -55,33 +75,79 @@ function ToolsMainActionBtns() {
info: "Clicked on 'Output Analyzer' button",
});
} catch (err) {
- // If an error occurs while setting custom posthog event, ignore it and continue
+ // If an error occurs while setting custom PostHog event, ignore it and continue
+ }
+ }, [navigate, setPostHogCustomEvent]);
+
+ const updateReorderedStatus = useCallback((status) => {
+ isReordered.current = status;
+ }, []);
+
+ const getPromptDetails = useCallback(() => {
+ const requestOptions = {
+ method: "GET",
+ url: `/api/v1/unstract/${sessionDetails?.orgId}/prompt-studio/${id}`,
+ };
+
+ setIsNewOrderLoading(true);
+ axiosPrivate(requestOptions)
+ .then((res) => {
+ const data = res?.data || {};
+ updateCustomTool({ details: data });
+ })
+ .catch((err) => {
+ setAlertDetails(handleException(err, "Failed to fetch prompt details"));
+ })
+ .finally(() => {
+ setIsNewOrderLoading(false);
+ });
+ }, []);
+
+ // Fetch prompt details after reorder modal closes
+ useEffect(() => {
+ if (!openReorderModal && isReordered.current === true) {
+ getPromptDetails();
+ updateReorderedStatus(false);
}
- };
+ }, [openReorderModal]);
if (isSimplePromptStudio && AddPromptBtn) {
return <AddPromptBtn />;
}
return (
- <Space>
- {singlePassExtractMode && RunSinglePassBtn && <RunSinglePassBtn />}
- {singlePassExtractMode && ChallengeModal && (
- <ChallengeModal
- challengeData={tokenUsage?.[`${tokenUsageId}__challenge_data`]}
- context={tokenUsage?.[`${tokenUsageId}__context`]}
- tokenUsage={tokenUsage?.[tokenUsageId]}
- />
- )}
- {!singlePassExtractMode && <RunAllPrompts />}
- <Tooltip title="Output Analyzer">
- <Button
- icon={<BarChartOutlined />}
- onClick={handleOutputAnalyzerBtnClick}
- disabled={isMultiPassExtractLoading || isSinglePassExtractLoading}
- />
- </Tooltip>
- </Space>
+ <>
+ <Space>
+ {singlePassExtractMode && RunSinglePassBtn && <RunSinglePassBtn />}
+ {singlePassExtractMode && ChallengeModal && (
+ <ChallengeModal
+ challengeData={tokenUsage?.[`${tokenUsageId}__challenge_data`]}
+ context={tokenUsage?.[`${tokenUsageId}__context`]}
+ tokenUsage={tokenUsage?.[tokenUsageId]}
+ />
+ )}
+ {!singlePassExtractMode && <RunAllPrompts />}
+ <Tooltip title="Output Analyzer">
+ <Button
+ icon={<BarChartOutlined />}
+ onClick={handleOutputAnalyzerBtnClick}
+ disabled={isMultiPassExtractLoading || isSinglePassExtractLoading}
+ />
+ </Tooltip>
+ <Tooltip title="Reorder the list of prompts">
+ <Button
+ icon={<UnorderedListOutlined />}
+ onClick={() => setOpenReorderModal(true)}
+ loading={isNewOrderLoading}
+ />
+ </Tooltip>
+ </Space>
+ <PromptsReorderModal
+ open={openReorderModal}
+ setOpen={setOpenReorderModal}
+ updateReorderedStatus={updateReorderedStatus}
+ />
+ </>
);
}
diff --git a/frontend/src/components/widgets/share-permission/SharePermission.jsx b/frontend/src/components/widgets/share-permission/SharePermission.jsx
index 53c5052b4..31c052391 100644
--- a/frontend/src/components/widgets/share-permission/SharePermission.jsx
+++ b/frontend/src/components/widgets/share-permission/SharePermission.jsx
@@ -163,7 +163,7 @@ function SharePermission({
onChange={(e) => handleShareWithEveryone(e.target.checked)}
className="share-per-checkbox"
>
- Share with everyone
+ Share with everyone in current org
</Checkbox>
)}
{permissionEdit && !shareWithEveryone && (