provision to delete rule file
This commit is contained in:
17
core/core.ts
17
core/core.ts
@@ -432,6 +432,23 @@ export class Core {
|
||||
}
|
||||
});
|
||||
|
||||
on("config/deleteRule", async (msg) => {
|
||||
try {
|
||||
const filepath = msg.data.filepath;
|
||||
const fileExists = await this.ide.fileExists(filepath);
|
||||
if (fileExists) {
|
||||
await this.ide.removeFile(filepath);
|
||||
walkDirCache.invalidate();
|
||||
await this.configHandler.reloadConfig(
|
||||
"Rule file deleted (config/deleteRule message)",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to delete rule file:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
on("config/openProfile", async (msg) => {
|
||||
await this.configHandler.openConfigProfile(msg.data.profileId);
|
||||
});
|
||||
|
||||
@@ -95,6 +95,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
||||
void,
|
||||
];
|
||||
"config/addGlobalRule": [undefined | { baseFilename?: string }, void];
|
||||
"config/deleteRule": [{ filepath: string }, void];
|
||||
"config/newPromptFile": [undefined, void];
|
||||
"config/newAssistantFile": [undefined, void];
|
||||
"config/ideSettingsUpdate": [IdeSettings, void];
|
||||
|
||||
@@ -23,6 +23,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
||||
"config/ideSettingsUpdate",
|
||||
"config/addLocalWorkspaceBlock",
|
||||
"config/addGlobalRule",
|
||||
"config/deleteRule",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/refreshProfiles",
|
||||
|
||||
@@ -84,6 +84,8 @@ class MessageTypes {
|
||||
"config/newAssistantFile",
|
||||
"config/ideSettingsUpdate",
|
||||
"config/addLocalWorkspaceBlock",
|
||||
"config/addGlobalRule",
|
||||
"config/deleteRule",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/refreshProfiles",
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
BookmarkIcon as BookmarkOutline,
|
||||
EyeIcon,
|
||||
PencilIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
|
||||
import {
|
||||
@@ -21,6 +22,7 @@ import { getRuleDisplayName } from "core/llm/rules/rules-utils";
|
||||
import { useContext, useMemo, useState } from "react";
|
||||
import { DropdownButton } from "../../../components/DropdownButton";
|
||||
import AddRuleDialog from "../../../components/dialogs/AddRuleDialog";
|
||||
import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog";
|
||||
import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip";
|
||||
import Switch from "../../../components/gui/Switch";
|
||||
import {
|
||||
@@ -132,6 +134,7 @@ interface RuleCardProps {
|
||||
|
||||
const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const policy = useAppSelector((state) =>
|
||||
rule.name
|
||||
? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING
|
||||
@@ -162,6 +165,36 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
||||
);
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
if (!rule.sourceFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(
|
||||
setDialogMessage(
|
||||
<ConfirmationDialog
|
||||
title="Delete Rule"
|
||||
text="Are you sure you want to delete this rule file?"
|
||||
confirmText="Delete"
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
await ideMessenger.request("config/deleteRule", {
|
||||
filepath: rule.sourceFile!,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to delete rule file:", error);
|
||||
}
|
||||
}}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
dispatch(setShowDialog(true));
|
||||
};
|
||||
|
||||
const canDeleteRule =
|
||||
rule.sourceFile &&
|
||||
!["default-chat", "default-agent", "default-plan"].includes(rule.source);
|
||||
|
||||
const smallFont = fontSize(-2);
|
||||
const tinyFont = fontSize(-3);
|
||||
return (
|
||||
@@ -209,6 +242,11 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
||||
<PencilIcon className="h-3 w-3 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
{canDeleteRule && (
|
||||
<HeaderButtonWithToolTip onClick={handleDelete} text="Delete">
|
||||
<TrashIcon className="h-3 w-3 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user