feat: allow for manual rule creation
This commit is contained in:
parent
2fb364dc61
commit
6df32dd772
3 changed files with 48 additions and 21 deletions
|
|
@ -19,12 +19,14 @@ interface GenerationScreenProps {
|
|||
inputPrompt: string;
|
||||
onBack: () => void;
|
||||
onSuccess: () => void;
|
||||
isManualMode?: boolean;
|
||||
}
|
||||
|
||||
export function GenerationScreen({
|
||||
inputPrompt,
|
||||
onBack,
|
||||
onSuccess,
|
||||
isManualMode = false,
|
||||
}: GenerationScreenProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
|
|
@ -55,10 +57,12 @@ export function GenerationScreen({
|
|||
}
|
||||
});
|
||||
|
||||
// Start generation once when component mounts
|
||||
// Start generation once when component mounts (only if not in manual mode)
|
||||
useEffect(() => {
|
||||
void generateRule();
|
||||
}, []);
|
||||
if (!isManualMode) {
|
||||
void generateRule();
|
||||
}
|
||||
}, [isManualMode]);
|
||||
|
||||
const handleRuleTypeChange = (newRuleType: RuleType) => {
|
||||
setSelectedRuleType(newRuleType);
|
||||
|
|
@ -130,7 +134,7 @@ export function GenerationScreen({
|
|||
}
|
||||
};
|
||||
|
||||
const showNameSpinner = isGenerating && !formData.name;
|
||||
const showNameSpinner = isGenerating && !formData.name && !isManualMode;
|
||||
const tooltipId = "rule-type-tooltip";
|
||||
|
||||
return (
|
||||
|
|
@ -156,7 +160,7 @@ export function GenerationScreen({
|
|||
type="text"
|
||||
className="border-input-border bg-input text-input-foreground placeholder:text-input-placeholder focus:border-border-focus box-border w-full rounded-md border px-3 py-2 text-xs focus:outline-none"
|
||||
placeholder={showNameSpinner ? "" : "Enter rule name..."}
|
||||
disabled={isGenerating}
|
||||
disabled={isGenerating && !isManualMode}
|
||||
{...register("name")}
|
||||
/>
|
||||
{showNameSpinner && (
|
||||
|
|
@ -189,9 +193,9 @@ export function GenerationScreen({
|
|||
onChange={(e) =>
|
||||
handleRuleTypeChange(e.target.value as RuleType)
|
||||
}
|
||||
disabled={isGenerating}
|
||||
disabled={isGenerating && !isManualMode}
|
||||
>
|
||||
{isGenerating ? (
|
||||
{isGenerating && !isManualMode ? (
|
||||
<option value=""></option>
|
||||
) : (
|
||||
<>
|
||||
|
|
@ -248,7 +252,8 @@ export function GenerationScreen({
|
|||
<textarea
|
||||
className="border-input-border bg-input text-input-foreground placeholder:text-input-placeholder focus:border-border-focus mt-1 box-border w-full resize-none rounded border p-2 text-xs focus:outline-none"
|
||||
rows={10}
|
||||
disabled={isGenerating}
|
||||
disabled={isGenerating && !isManualMode}
|
||||
placeholder="Your rule content..."
|
||||
{...register("rule")}
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -260,7 +265,7 @@ export function GenerationScreen({
|
|||
className="min-w-16"
|
||||
onClick={onBack}
|
||||
variant="outline"
|
||||
disabled={isGenerating}
|
||||
disabled={isGenerating && !isManualMode}
|
||||
>
|
||||
Back
|
||||
</Button>
|
||||
|
|
@ -268,7 +273,9 @@ export function GenerationScreen({
|
|||
className="min-w-16"
|
||||
onClick={handleContinue}
|
||||
disabled={
|
||||
isGenerating || (!formData.rule && !error) || !formData.name
|
||||
(isGenerating && !isManualMode) ||
|
||||
(!formData.rule && !error) ||
|
||||
!formData.name
|
||||
}
|
||||
>
|
||||
Continue
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ interface InputScreenProps {
|
|||
onInputChange: (prompt: string) => void;
|
||||
onGenerate: (prompt: string) => void;
|
||||
onCancel: () => void;
|
||||
onManualWrite: () => void;
|
||||
}
|
||||
|
||||
export function InputScreen({
|
||||
|
|
@ -15,6 +16,7 @@ export function InputScreen({
|
|||
onInputChange,
|
||||
onGenerate,
|
||||
onCancel,
|
||||
onManualWrite,
|
||||
}: InputScreenProps) {
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
|
@ -62,18 +64,26 @@ export function InputScreen({
|
|||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-row justify-center gap-5">
|
||||
<Button
|
||||
type="button"
|
||||
className="min-w-16"
|
||||
onClick={onCancel}
|
||||
variant="outline"
|
||||
<div className="my-4 flex flex-col items-center gap-2">
|
||||
<div className="flex flex-row justify-center gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
className="min-w-16"
|
||||
onClick={onCancel}
|
||||
variant="outline"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button className="min-w-16" disabled={!inputPrompt.trim()}>
|
||||
Generate
|
||||
</Button>
|
||||
</div>
|
||||
<span
|
||||
className="text-description cursor-pointer text-xs underline"
|
||||
onClick={onManualWrite}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button className="min-w-16" disabled={!inputPrompt.trim()}>
|
||||
Generate
|
||||
</Button>
|
||||
Or, write a rule from scratch
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10,16 +10,24 @@ export function GenerateRuleDialog() {
|
|||
const dispatch = useDispatch();
|
||||
const [screen, setScreen] = useState<Screen>("input");
|
||||
const [inputPrompt, setInputPrompt] = useState("");
|
||||
const [isManualMode, setIsManualMode] = useState(false);
|
||||
|
||||
const closeDialog = () => {
|
||||
setScreen("input");
|
||||
setInputPrompt("");
|
||||
setIsManualMode(false);
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
};
|
||||
|
||||
const handleGenerate = (prompt: string) => {
|
||||
setInputPrompt(prompt);
|
||||
setIsManualMode(false);
|
||||
setScreen("generation");
|
||||
};
|
||||
|
||||
const handleManualWrite = () => {
|
||||
setIsManualMode(true);
|
||||
setScreen("generation");
|
||||
};
|
||||
|
||||
|
|
@ -38,6 +46,7 @@ export function GenerateRuleDialog() {
|
|||
onInputChange={setInputPrompt}
|
||||
onGenerate={handleGenerate}
|
||||
onCancel={closeDialog}
|
||||
onManualWrite={handleManualWrite}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -47,6 +56,7 @@ export function GenerateRuleDialog() {
|
|||
inputPrompt={inputPrompt}
|
||||
onBack={handleBack}
|
||||
onSuccess={handleSuccess}
|
||||
isManualMode={isManualMode}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue