Skip to content

Commit e6297c1

Browse files
authored
♻️ Unify global modal, delete unused code
2 parents 601c786 + 3708754 commit e6297c1

File tree

5 files changed

+38
-199
lines changed

5 files changed

+38
-199
lines changed

frontend/app/[locale]/agents/AgentsContent.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from "@/const/modelConfig";
1010

1111
import AgentConfig, {AgentConfigHandle} from "./AgentConfiguration";
12-
import SaveConfirmModal from "./components/SaveConfirmModal";
1312

1413
interface AgentsContentProps {
1514
/** Whether currently saving */
@@ -39,8 +38,6 @@ export default forwardRef<AgentConfigHandle, AgentsContentProps>(function Agents
3938
onSavingStateChange,
4039
}: AgentsContentProps, ref) {
4140
const agentConfigRef = useRef<AgentConfigHandle | null>(null);
42-
const [showSaveConfirm, setShowSaveConfirm] = useState(false);
43-
const pendingNavRef = useRef<null | (() => void)>(null);
4441

4542
// Use custom hook for common setup flow logic
4643
const {
@@ -95,32 +92,6 @@ export default forwardRef<AgentConfigHandle, AgentsContentProps>(function Agents
9592
) : null}
9693
</div>
9794
</motion.div>
98-
99-
<SaveConfirmModal
100-
open={showSaveConfirm}
101-
onCancel={async () => {
102-
// Reload data from backend to discard changes
103-
await agentConfigRef.current?.reloadCurrentAgentData?.();
104-
setShowSaveConfirm(false);
105-
const go = pendingNavRef.current;
106-
pendingNavRef.current = null;
107-
if (go) go();
108-
}}
109-
onSave={async () => {
110-
try {
111-
setInternalIsSaving(true);
112-
await agentConfigRef.current?.saveAllChanges?.();
113-
setShowSaveConfirm(false);
114-
const go = pendingNavRef.current;
115-
pendingNavRef.current = null;
116-
if (go) go();
117-
} catch (e) {
118-
// errors are surfaced by underlying save
119-
} finally {
120-
setInternalIsSaving(false);
121-
}
122-
}}
123-
/>
12495
</>
12596
);
12697
});

frontend/app/[locale]/agents/components/AgentSetupOrchestrator.tsx

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export default function AgentSetupOrchestrator({
118118

119119

120120

121-
// Embedding auto-unselect notice modal
122-
const [isEmbeddingAutoUnsetOpen, setIsEmbeddingAutoUnsetOpen] =
123-
useState(false);
121+
124122
const lastProcessedAgentIdForEmbedding = useRef<number | null>(null);
125123

126124
// Flag to track if we need to refresh enabledToolIds after tools update
@@ -672,7 +670,12 @@ export default function AgentSetupOrchestrator({
672670
} catch (error) {
673671
// Even if API fails, still inform user and prevent usage in UI
674672
} finally {
675-
setIsEmbeddingAutoUnsetOpen(true);
673+
confirm({
674+
title: t("embedding.agentToolAutoDeselectModal.title"),
675+
content: t("embedding.agentToolAutoDeselectModal.content"),
676+
okText: t("common.confirm"),
677+
onOk: () => {},
678+
});
676679
lastProcessedAgentIdForEmbedding.current = currentAgentId;
677680
}
678681
};
@@ -2011,32 +2014,6 @@ export default function AgentSetupOrchestrator({
20112014
});
20122015
};
20132016

2014-
// Handle exit edit mode
2015-
const handleExitEdit = () => {
2016-
setIsEditingAgent(false);
2017-
setEditingAgent(null);
2018-
// Use the parent's exit creation handler to properly clear cache
2019-
if (isCreatingNewAgent && onExitCreation) {
2020-
onExitCreation();
2021-
} else {
2022-
setIsCreatingNewAgent(false);
2023-
}
2024-
setBusinessLogic("");
2025-
setDutyContent("");
2026-
setConstraintContent("");
2027-
setFewShotsContent("");
2028-
setAgentName?.("");
2029-
setAgentDescription?.("");
2030-
// Reset mainAgentId and enabledAgentIds
2031-
setMainAgentId(null);
2032-
setEnabledAgentIds([]);
2033-
// Reset selected tools
2034-
setSelectedTools([]);
2035-
setEnabledToolIds([]);
2036-
// Notify parent component about editing state change
2037-
onEditingStateChange?.(false, null);
2038-
};
2039-
20402017
// Refresh tool list
20412018
const handleToolsRefresh = useCallback(
20422019
async (showSuccessMessage = true) => {
@@ -2295,8 +2272,6 @@ export default function AgentSetupOrchestrator({
22952272
isCreatingNewAgent={isCreatingNewAgent}
22962273
canSaveAgent={localCanSaveAgent}
22972274
getButtonTitle={getLocalButtonTitle}
2298-
onDeleteAgent={onDeleteAgent || (() => {})}
2299-
onDeleteSuccess={handleExitEdit}
23002275
editingAgent={editingAgentFromParent || editingAgent}
23012276
onViewCallRelationship={handleViewCallRelationship}
23022277
/>
@@ -2443,37 +2418,7 @@ export default function AgentSetupOrchestrator({
24432418
}
24442419
/>
24452420
{/* Auto unselect knowledge_base_search notice when embedding not configured */}
2446-
<Modal
2447-
title={t("embedding.agentToolAutoDeselectModal.title")}
2448-
open={isEmbeddingAutoUnsetOpen}
2449-
onCancel={() => setIsEmbeddingAutoUnsetOpen(false)}
2450-
centered
2451-
footer={
2452-
<div className="flex justify-end mt-6 gap-4">
2453-
<Button
2454-
type="primary"
2455-
onClick={() => setIsEmbeddingAutoUnsetOpen(false)}
2456-
>
2457-
{t("common.confirm")}
2458-
</Button>
2459-
</div>
2460-
}
2461-
width={520}
2462-
>
2463-
<div className="py-2">
2464-
<div className="flex items-center">
2465-
<WarningFilled
2466-
className="text-yellow-500 mt-1 mr-2"
2467-
style={{ fontSize: "48px" }}
2468-
/>
2469-
<div className="ml-3 mt-2">
2470-
<div className="text-sm leading-6">
2471-
{t("embedding.agentToolAutoDeselectModal.content")}
2472-
</div>
2473-
</div>
2474-
</div>
2475-
</div>
2476-
</Modal>
2421+
24772422
{/* Agent call relationship modal */}
24782423
<AgentCallRelationshipModal
24792424
visible={callRelationshipModalVisible}

frontend/app/[locale]/agents/components/PromptManager.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { updateAgent } from "@/services/agentConfigService";
1717
import { modelService } from "@/services/modelService";
1818
import { ModelOption } from "@/types/modelConfig";
1919

20-
import AgentConfigModal from "./agent/AgentConfigModal";
20+
import AgentConfigModal, { AgentConfigModalProps } from "./agent/AgentConfigModal";
2121

2222
import log from "@/lib/logger";
2323

@@ -229,8 +229,6 @@ export interface PromptManagerProps {
229229
onGenerateAgent?: (model: ModelOption) => void;
230230
onSaveAgent?: () => void;
231231
onDebug?: () => void;
232-
onDeleteAgent?: () => void;
233-
onDeleteSuccess?: () => void;
234232
getButtonTitle?: () => string;
235233
onViewCallRelationship?: () => void;
236234

@@ -276,8 +274,6 @@ export default function PromptManager({
276274
onGenerateAgent,
277275
onSaveAgent,
278276
onDebug,
279-
onDeleteAgent,
280-
onDeleteSuccess,
281277
getButtonTitle,
282278
onViewCallRelationship,
283279
editingAgent,
@@ -692,8 +688,6 @@ export default function PromptManager({
692688
onExpandCard={handleExpandCard}
693689
isGeneratingAgent={isGeneratingAgent}
694690
onDebug={onDebug}
695-
onDeleteAgent={onDeleteAgent}
696-
onDeleteSuccess={onDeleteSuccess}
697691
onSaveAgent={onSaveAgent}
698692
isCreatingNewAgent={isCreatingNewAgent}
699693
editingAgent={editingAgent}

frontend/app/[locale]/agents/components/agent/AgentConfigModal.tsx

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export interface AgentConfigModalProps {
4848
isGeneratingAgent?: boolean;
4949
// Add new props for action buttons
5050
onDebug?: () => void;
51-
onDeleteAgent?: () => void;
52-
onDeleteSuccess?: () => void; // New prop for handling delete success
5351
onSaveAgent?: () => void;
5452
isCreatingNewAgent?: boolean;
5553
editingAgent?: Agent | null;
@@ -84,8 +82,6 @@ export default function AgentConfigModal({
8482
isGeneratingAgent = false,
8583
// Add new props for action buttons
8684
onDebug,
87-
onDeleteAgent,
88-
onDeleteSuccess,
8985
onSaveAgent,
9086
isCreatingNewAgent = false,
9187
editingAgent = null,
@@ -107,9 +103,6 @@ export default function AgentConfigModal({
107103
// Add segmented state management
108104
const [activeSegment, setActiveSegment] = useState<string>("agent-info");
109105

110-
// Add state for delete confirmation modal
111-
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
112-
113106
// Add state for agent name validation error
114107
const [agentNameError, setAgentNameError] = useState<string>("");
115108
// Add state for agent name status check
@@ -473,16 +466,6 @@ export default function AgentConfigModal({
473466
}
474467
}, [isCreatingNewAgent, currentDisplayName, originalDisplayName]);
475468

476-
// Handle delete confirmation
477-
const handleDeleteConfirm = useCallback(() => {
478-
setIsDeleteModalVisible(false);
479-
// Execute the delete operation
480-
onDeleteAgent?.();
481-
// Call the success callback immediately after triggering delete
482-
// The actual success/failure will be handled by the parent component
483-
onDeleteSuccess?.();
484-
}, [onDeleteAgent, onDeleteSuccess]);
485-
486469
// Optimized click handlers using useCallback
487470
const handleSegmentClick = useCallback((segment: string) => {
488471
setActiveSegment(segment);
@@ -1196,25 +1179,6 @@ export default function AgentConfigModal({
11961179
</div>
11971180
</div>
11981181
)}
1199-
1200-
{/* Delete Confirmation Modal */}
1201-
<Modal
1202-
title={t("businessLogic.config.modal.deleteTitle")}
1203-
open={isDeleteModalVisible}
1204-
onOk={handleDeleteConfirm}
1205-
onCancel={() => setIsDeleteModalVisible(false)}
1206-
okText={t("businessLogic.config.modal.button.confirm")}
1207-
cancelText={t("businessLogic.config.modal.button.cancel")}
1208-
okButtonProps={{
1209-
danger: true,
1210-
}}
1211-
>
1212-
<p>
1213-
{t("businessLogic.config.modal.deleteContent", {
1214-
name: agentName || "Unnamed Agent",
1215-
})}
1216-
</p>
1217-
</Modal>
12181182
</div>
12191183
);
12201184
}

frontend/app/[locale]/knowledges/components/document/DocumentChunk.tsx

Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Pagination,
1717
Input,
1818
} from "antd";
19-
import { WarningFilled } from "@ant-design/icons";
19+
import { useConfirmModal } from "@/hooks/useConfirmModal";
2020
import {
2121
Download,
2222
ScanText,
@@ -81,6 +81,7 @@ const DocumentChunk: React.FC<DocumentChunkProps> = ({
8181
}) => {
8282
const { t } = useTranslation();
8383
const { message } = App.useApp();
84+
const { confirm } = useConfirmModal();
8485
const [chunks, setChunks] = useState<Chunk[]>([]);
8586
const [total, setTotal] = useState<number>(0);
8687
const [loading, setLoading] = useState(false);
@@ -107,8 +108,6 @@ const DocumentChunk: React.FC<DocumentChunkProps> = ({
107108
const [chunkSubmitting, setChunkSubmitting] = useState(false);
108109
const [editingChunk, setEditingChunk] = useState<Chunk | null>(null);
109110
const [chunkForm] = Form.useForm<ChunkFormValues>();
110-
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
111-
const [chunkToDelete, setChunkToDelete] = useState<Chunk | null>(null);
112111
const [tooltipResetKey, setTooltipResetKey] = useState(0);
113112

114113
const resetChunkSearch = React.useCallback(() => {
@@ -455,39 +454,32 @@ const DocumentChunk: React.FC<DocumentChunkProps> = ({
455454
}
456455

457456
forceCloseTooltips();
458-
setChunkToDelete(chunk);
459-
setDeleteModalOpen(true);
460-
};
461-
462-
const handleDeleteConfirm = async () => {
463-
if (!chunkToDelete?.id || !knowledgeBaseName) {
464-
return;
465-
}
466-
467-
try {
468-
await knowledgeBaseService.deleteChunk(
469-
knowledgeBaseName,
470-
chunkToDelete.id
471-
);
472-
message.success(t("document.chunk.success.delete"));
473-
setDeleteModalOpen(false);
474-
setChunkToDelete(null);
475-
forceCloseTooltips();
476-
await refreshChunks();
477-
} catch (error) {
478-
log.error("Failed to delete chunk:", error);
479-
message.error(
480-
error instanceof Error && error.message
481-
? error.message
482-
: t("document.chunk.error.deleteFailed")
483-
);
484-
}
485-
};
486-
487-
const handleDeleteCancel = () => {
488-
setDeleteModalOpen(false);
489-
setChunkToDelete(null);
490-
forceCloseTooltips();
457+
458+
confirm({
459+
title: t("document.chunk.confirm.deleteTitle"),
460+
content: t("document.chunk.confirm.deleteContent"),
461+
okText: t("common.delete"),
462+
cancelText: t("common.cancel"),
463+
danger: true,
464+
onOk: async () => {
465+
try {
466+
await knowledgeBaseService.deleteChunk(knowledgeBaseName, chunk.id);
467+
message.success(t("document.chunk.success.delete"));
468+
forceCloseTooltips();
469+
await refreshChunks();
470+
} catch (error) {
471+
log.error("Failed to delete chunk:", error);
472+
message.error(
473+
error instanceof Error && error.message
474+
? error.message
475+
: t("document.chunk.error.deleteFailed")
476+
);
477+
}
478+
},
479+
onCancel: () => {
480+
forceCloseTooltips();
481+
},
482+
});
491483
};
492484

493485
const renderDocumentLabel = (doc: Document, chunkCount: number) => {
@@ -847,34 +839,7 @@ const DocumentChunk: React.FC<DocumentChunkProps> = ({
847839
</Form.Item>
848840
</Form>
849841
</Modal>
850-
<Modal
851-
title={t("document.chunk.confirm.deleteTitle")}
852-
open={deleteModalOpen}
853-
onCancel={handleDeleteCancel}
854-
centered
855-
footer={
856-
<div className="flex justify-end mt-6 gap-4">
857-
<Button onClick={handleDeleteCancel}>{t("common.cancel")}</Button>
858-
<Button type="primary" danger onClick={handleDeleteConfirm}>
859-
{t("common.delete")}
860-
</Button>
861-
</div>
862-
}
863-
>
864-
<div className="py-2">
865-
<div className="flex items-center">
866-
<WarningFilled
867-
className="text-yellow-500 mt-1 mr-2"
868-
style={{ fontSize: "48px" }}
869-
/>
870-
<div className="ml-3 mt-2">
871-
<div className="text-sm leading-6">
872-
{t("document.chunk.confirm.deleteContent")}
873-
</div>
874-
</div>
875-
</div>
876-
</div>
877-
</Modal>
842+
878843
</TooltipProvider>
879844
);
880845
};

0 commit comments

Comments
 (0)