-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: allow renaming rule before creation #8793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+152
−18
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e5fce9
feat: allow renaming rule before creation
uinstinct b7996a5
Merge branch 'main' into rule-add-dialog
uinstinct 169779f
Update gui/src/components/dialogs/AddRuleDialog.tsx
uinstinct b6a8be5
add a default name called "new-rule" in the input
uinstinct 450b647
Merge branch 'main' into rule-add-dialog
uinstinct f7815c3
correct wordings
uinstinct ba64c1a
refactor duplicate condition
uinstinct File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { useContext, useLayoutEffect, useRef, useState } from "react"; | ||
| import { useDispatch } from "react-redux"; | ||
| import { Input, SecondaryButton } from ".."; | ||
| import { IdeMessengerContext } from "../../context/IdeMessenger"; | ||
| import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; | ||
|
|
||
| function AddRuleDialog({ mode }: { mode: "workspace" | "global" }) { | ||
| const dispatch = useDispatch(); | ||
| const ideMessenger = useContext(IdeMessengerContext); | ||
| const [name, setName] = useState("new-rule"); | ||
| const [error, setError] = useState<string | undefined>(); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| useLayoutEffect(() => { | ||
| // focus on input after a short delay | ||
| const timer = setTimeout(() => { | ||
| if (inputRef.current) { | ||
| inputRef.current.focus(); | ||
| } | ||
| }, 100); | ||
| return () => clearTimeout(timer); | ||
| }, []); | ||
|
|
||
| const closeDialog = () => { | ||
| dispatch(setShowDialog(false)); | ||
| dispatch(setDialogMessage(undefined)); | ||
| }; | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| const trimmed = name.trim(); | ||
uinstinct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!trimmed) { | ||
| setError("Rule name is required"); | ||
| return; | ||
| } | ||
| setError(undefined); | ||
| setIsSubmitting(true); | ||
| try { | ||
| if (mode === "global") { | ||
| ideMessenger.post("config/addGlobalRule", { | ||
| baseFilename: trimmed, | ||
| }); | ||
| } else { | ||
| ideMessenger.post("config/addLocalWorkspaceBlock", { | ||
| blockType: "rules", | ||
| baseFilename: trimmed, | ||
| }); | ||
| } | ||
| closeDialog(); | ||
| } catch (err) { | ||
| setIsSubmitting(false); | ||
| setError("Failed to create rule file"); | ||
| } | ||
| }; | ||
|
|
||
| const title = mode === "global" ? "Add global rule" : "Add workspace rule"; | ||
|
|
||
| return ( | ||
| <div className="px-2 pt-4 sm:px-4"> | ||
| <div> | ||
| <h1 className="mb-0">{title}</h1> | ||
| <p className="m-0 mt-2 p-0 text-stone-500"> | ||
| Choose a name for the new rule file. | ||
| </p> | ||
| <form onSubmit={handleSubmit} className="mt-3 flex flex-col gap-2"> | ||
| <label className="flex w-full flex-col gap-1"> | ||
| <span>Rule name</span> | ||
| <Input | ||
| ref={inputRef} | ||
| type="text" | ||
| placeholder="ex: api-guidelines" | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| /> | ||
| </label> | ||
| {error && <p className="text-xs text-red-500">{error}</p>} | ||
| <div className="mt-2 flex flex-row justify-end gap-2"> | ||
| <SecondaryButton | ||
| className="min-w-16" | ||
| disabled={isSubmitting} | ||
| type="submit" | ||
| > | ||
| Create | ||
| </SecondaryButton> | ||
| <SecondaryButton | ||
| type="button" | ||
| className="min-w-16" | ||
| onClick={closeDialog} | ||
| > | ||
| Cancel | ||
| </SecondaryButton> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default AddRuleDialog; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.