feat: generate rule button + dialog scaffolding
This commit is contained in:
parent
d22ab74b15
commit
a2adf2fe98
5 changed files with 153 additions and 4 deletions
26
gui/src/components/GenerateRuleDialog/RuleTemplateChip.tsx
Normal file
26
gui/src/components/GenerateRuleDialog/RuleTemplateChip.tsx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import React from "react";
|
||||
import { Button } from "../ui";
|
||||
|
||||
interface RuleTemplateChipProps {
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
text: string;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export function RuleTemplateChip({
|
||||
icon: Icon,
|
||||
text,
|
||||
onClick,
|
||||
}: RuleTemplateChipProps) {
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="flex items-center gap-2"
|
||||
variant="secondary"
|
||||
>
|
||||
<Icon className="h-3.5 w-3.5" />
|
||||
<span>{text}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
84
gui/src/components/GenerateRuleDialog/index.tsx
Normal file
84
gui/src/components/GenerateRuleDialog/index.tsx
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import { useContext, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { Button } from "../ui";
|
||||
import { RuleTemplateChip } from "./RuleTemplateChip";
|
||||
import { RuleTemplate, ruleTemplates } from "./ruleTemplates";
|
||||
|
||||
function GenerateRuleDialog() {
|
||||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const [textareaValue, setTextareaValue] = useState("");
|
||||
|
||||
const lastChatMessage = useAppSelector(
|
||||
(state) => state.session.history[state.session.history.length - 1],
|
||||
);
|
||||
|
||||
const closeDialog = () => {
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
};
|
||||
|
||||
function onSubmit(e: any) {
|
||||
e.preventDefault();
|
||||
// Logic to generate rule will go here
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
function handleRuleTemplateClick(ruleTemplate: RuleTemplate) {
|
||||
setTextareaValue(ruleTemplate.template);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="px-2 pb-2 pt-4 sm:px-4">
|
||||
<div>
|
||||
<div className="text-center">
|
||||
<h2 className="mb-0">Generate Rule</h2>
|
||||
<p className="text-description m-0 mt-2 p-0">
|
||||
This will generate a new rule using the content of your chat history
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-1">
|
||||
<div className="flex flex-col gap-2">
|
||||
<textarea
|
||||
className="border-input-border bg-input text-input-foreground placeholder:text-input-placeholder focus:border-border-focus min-w-0 max-w-full resize-none rounded border p-2 text-sm text-xs focus:outline-none"
|
||||
placeholder="Describe your rule..."
|
||||
rows={4}
|
||||
value={textareaValue}
|
||||
onChange={(e) => setTextareaValue(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-wrap items-center justify-center gap-2">
|
||||
{ruleTemplates.map((template, index) => (
|
||||
<RuleTemplateChip
|
||||
key={index}
|
||||
icon={template.icon}
|
||||
text={template.title}
|
||||
onClick={() => handleRuleTemplateClick(template)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-row justify-center gap-5">
|
||||
<Button
|
||||
type="button"
|
||||
className="min-w-16"
|
||||
onClick={closeDialog}
|
||||
variant="outline"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button className="min-w-16">Generate</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default GenerateRuleDialog;
|
||||
15
gui/src/components/GenerateRuleDialog/ruleTemplates.ts
Normal file
15
gui/src/components/GenerateRuleDialog/ruleTemplates.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { DocumentTextIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
export interface RuleTemplate {
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
title: string;
|
||||
template: string;
|
||||
}
|
||||
|
||||
export const ruleTemplates: RuleTemplate[] = [
|
||||
{
|
||||
icon: DocumentTextIcon,
|
||||
title: "Summarize learnings",
|
||||
template: "Lorem ipsum dolor est"
|
||||
}
|
||||
];
|
||||
|
|
@ -1,7 +1,14 @@
|
|||
import { BarsArrowDownIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
BarsArrowDownIcon,
|
||||
PlusIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { ChatHistoryItem } from "core";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import FeedbackButtons from "../FeedbackButtons";
|
||||
import GenerateRuleDialog from "../GenerateRuleDialog";
|
||||
import { CopyIconButton } from "../gui/CopyIconButton";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
|
||||
|
|
@ -20,8 +27,25 @@ export default function ResponseActions({
|
|||
isTruncated,
|
||||
onDelete,
|
||||
}: ResponseActionsProps) {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const onGenerateRule = () => {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<GenerateRuleDialog />));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mx-2 flex cursor-default items-center justify-end space-x-1 bg-transparent pb-0 text-xs text-gray-400">
|
||||
<div className="text-description-muted mx-2 flex cursor-default items-center justify-end space-x-1 bg-transparent pb-0 text-xs">
|
||||
<div
|
||||
className="border-border mr-1 border-y-0 border-l-0 border-r border-solid border-gray-500 pr-2"
|
||||
onClick={onGenerateRule}
|
||||
>
|
||||
<span className="flex cursor-pointer items-center hover:brightness-125">
|
||||
<PlusIcon className="mr-1 h-3 w-3" />
|
||||
<span className="whitespace-nowrap">Generate rule</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{isTruncated && (
|
||||
<HeaderButtonWithToolTip
|
||||
tabIndex={-1}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ const buttonVariants = {
|
|||
primary:
|
||||
"px-3 py-1.5 border-none text-background bg-foreground hover:enabled:brightness-125",
|
||||
secondary:
|
||||
"px-3 py-1.5 border border-input-border text-foreground bg-input hover:enabled:bg-background hover:enabled:opacity-90",
|
||||
"px-3 py-1.5 border-none text-foreground bg-input hover:enabled:bg-gray-500/20",
|
||||
outline:
|
||||
"px-3 py-1.5 border-[0.5px] border-foreground text-foreground bg-transparent hover:enabled:bg-foreground/10",
|
||||
"px-3 py-1.5 border border-foreground text-foreground bg-transparent hover:enabled:bg-input",
|
||||
ghost:
|
||||
"px-2 py-1.5 border-none text-foreground bg-gray-500/40 hover:enabled:brightness-125",
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue