-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(secrets-overview): re-vamp create secret form #5611
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
+1,428
−213
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
17b3518
feat: re-vamp create secret form
scott-ray-wilson d29cd28
improvement: address feedback
scott-ray-wilson 2f1e303
style: adjust secret input styling
scott-ray-wilson a250324
fix: remove unnecessary z index on secret input
scott-ray-wilson 20c7502
fix: make environments required and add error styling to react select…
scott-ray-wilson 6cf407d
improvement: remove autoFocus on sheet close button
scott-ray-wilson 9c1b2e8
improvement: only show space warning after trim
scott-ray-wilson e5fc2db
fix: use proper slug validation for tag creation
scott-ray-wilson c15484f
improvement: remove duplicate error toast on create secret failure
scott-ray-wilson fdf41e7
improvement: clear full secret form on create more except environments
scott-ray-wilson 1484cfa
fix: correct schema check on tag creation
scott-ray-wilson 58ebf57
fix: refactor secret input to correct cursor placement
scott-ray-wilson 2fddd1b
chore: lint
scott-ray-wilson 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
scott-ray-wilson marked this conversation as resolved.
Show resolved
Hide resolved
scott-ray-wilson marked this conversation as resolved.
Show resolved
Hide resolved
scott-ray-wilson marked this conversation as resolved.
Show resolved
Hide resolved
scott-ray-wilson marked this conversation as resolved.
Show resolved
Hide resolved
scott-ray-wilson marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
|---|---|---|
| @@ -1,20 +1,29 @@ | ||
| import { forwardRef } from "react"; | ||
|
|
||
| import { cn } from "../../utils"; | ||
|
|
||
| function UnstableInput({ className, type, ...props }: React.ComponentProps<"input">) { | ||
| const UnstableInput = forwardRef< | ||
| HTMLInputElement, | ||
| React.ComponentProps<"input"> & { isError?: boolean } | ||
| >(({ className, type, isError, ...props }, ref) => { | ||
| return ( | ||
| <input | ||
| ref={ref} | ||
| type={type} | ||
| data-slot="input" | ||
| className={cn( | ||
| "h-9 w-full min-w-0 rounded-md border border-border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50", | ||
| "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", | ||
| "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", | ||
| "aria-invalid:border-danger aria-invalid:ring-danger/20 dark:aria-invalid:ring-danger/40", | ||
| "selection:bg-foreground selection:text-background", | ||
| className | ||
| )} | ||
| aria-invalid={isError} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| UnstableInput.displayName = "UnstableInput"; | ||
|
|
||
| export { UnstableInput }; |
188 changes: 188 additions & 0 deletions
188
frontend/src/components/v3/generic/PasswordGenerator/PasswordGenerator.tsx
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,188 @@ | ||
| import { useMemo, useState } from "react"; | ||
| import { CheckIcon, CopyIcon, KeyRoundIcon, RefreshCwIcon } from "lucide-react"; | ||
|
|
||
| import { useTimedReset } from "@app/hooks"; | ||
|
|
||
| import { Button } from "../Button"; | ||
| import { Checkbox } from "../Checkbox"; | ||
| import { UnstableIconButton } from "../IconButton"; | ||
| import { Label } from "../Label"; | ||
| import { Popover, PopoverContent, PopoverTrigger } from "../Popover"; | ||
|
|
||
| type PasswordOptionsType = { | ||
| length: number; | ||
| useUppercase: boolean; | ||
| useLowercase: boolean; | ||
| useNumbers: boolean; | ||
| useSpecialChars: boolean; | ||
| }; | ||
|
|
||
| export type PasswordGeneratorProps = { | ||
| onUsePassword?: (password: string) => void; | ||
| isDisabled?: boolean; | ||
| minLength?: number; | ||
| maxLength?: number; | ||
| }; | ||
|
|
||
| export const PasswordGenerator = ({ | ||
| onUsePassword, | ||
| isDisabled = false, | ||
| minLength = 12, | ||
| maxLength = 64 | ||
| }: PasswordGeneratorProps) => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [, isCopying, setCopyText] = useTimedReset<string>({ | ||
| initialState: "Copy" | ||
| }); | ||
| const [refresh, setRefresh] = useState(false); | ||
| const [passwordOptions, setPasswordOptions] = useState<PasswordOptionsType>({ | ||
| length: minLength, | ||
| useUppercase: true, | ||
| useLowercase: true, | ||
| useNumbers: true, | ||
| useSpecialChars: true | ||
| }); | ||
|
|
||
| const password = useMemo(() => { | ||
| const charset = { | ||
| uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
| lowercase: "abcdefghijklmnopqrstuvwxyz", | ||
| numbers: "0123456789", | ||
| specialChars: "-_.~!*" | ||
| }; | ||
|
|
||
| let availableChars = ""; | ||
| if (passwordOptions.useUppercase) availableChars += charset.uppercase; | ||
| if (passwordOptions.useLowercase) availableChars += charset.lowercase; | ||
| if (passwordOptions.useNumbers) availableChars += charset.numbers; | ||
| if (passwordOptions.useSpecialChars) availableChars += charset.specialChars; | ||
|
|
||
| if (availableChars === "") availableChars = charset.lowercase + charset.numbers; | ||
|
|
||
| let newPassword = ""; | ||
| for (let i = 0; i < passwordOptions.length; i += 1) { | ||
| const randomIndex = Math.floor(Math.random() * availableChars.length); | ||
| newPassword += availableChars[randomIndex]; | ||
scott-ray-wilson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return newPassword; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [passwordOptions, refresh]); | ||
|
|
||
| const copyToClipboard = () => { | ||
| navigator.clipboard | ||
| .writeText(password) | ||
| .then(() => { | ||
| setCopyText("Copied"); | ||
| }) | ||
| .catch(() => { | ||
| setCopyText("Copy failed"); | ||
| }); | ||
| }; | ||
|
|
||
| const usePassword = () => { | ||
| onUsePassword?.(password); | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Popover open={isOpen} onOpenChange={setIsOpen}> | ||
| <PopoverTrigger asChild> | ||
| <UnstableIconButton variant="outline" size="md" isDisabled={isDisabled}> | ||
| <KeyRoundIcon /> | ||
| </UnstableIconButton> | ||
| </PopoverTrigger> | ||
| <PopoverContent className="w-[30rem]" align="end"> | ||
| <div className="flex flex-col gap-4"> | ||
| <div> | ||
| <p className="text-sm font-medium">Generate Random Value</p> | ||
| <p className="mt-0.5 text-xs text-muted">Generate strong unique values</p> | ||
| </div> | ||
|
|
||
| <div className="rounded-md border border-border bg-container/50 p-3"> | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <p className="flex-1 font-mono text-sm break-all select-all">{password}</p> | ||
| <div className="flex shrink-0 gap-1"> | ||
| <UnstableIconButton | ||
| variant="ghost" | ||
| size="xs" | ||
| onClick={() => setRefresh((prev) => !prev)} | ||
| > | ||
| <RefreshCwIcon /> | ||
| </UnstableIconButton> | ||
| <UnstableIconButton variant="ghost" size="xs" onClick={copyToClipboard}> | ||
| {isCopying ? <CheckIcon /> : <CopyIcon />} | ||
| </UnstableIconButton> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div> | ||
| <div className="mb-2 flex items-center justify-between"> | ||
| <Label className="text-xs text-accent">Length: {passwordOptions.length}</Label> | ||
| </div> | ||
| <input | ||
| type="range" | ||
| min={minLength} | ||
| max={maxLength} | ||
| value={passwordOptions.length} | ||
| onChange={(e) => | ||
| setPasswordOptions({ ...passwordOptions, length: Number(e.target.value) }) | ||
| } | ||
| className="h-1.5 w-full cursor-pointer appearance-none rounded-full bg-foreground/10 accent-project [&::-webkit-slider-thumb]:size-3.5 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-foreground [&::-webkit-slider-thumb]:shadow-sm" | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex flex-wrap gap-6"> | ||
| <Label className="flex cursor-pointer items-center gap-1.5 text-xs"> | ||
| <Checkbox | ||
| variant="project" | ||
| isChecked={passwordOptions.useUppercase} | ||
| onCheckedChange={(checked) => | ||
| setPasswordOptions({ ...passwordOptions, useUppercase: checked as boolean }) | ||
| } | ||
| /> | ||
| A-Z | ||
| </Label> | ||
| <Label className="flex cursor-pointer items-center gap-1.5 text-xs"> | ||
| <Checkbox | ||
| variant="project" | ||
| isChecked={passwordOptions.useLowercase} | ||
| onCheckedChange={(checked) => | ||
| setPasswordOptions({ ...passwordOptions, useLowercase: checked as boolean }) | ||
| } | ||
| /> | ||
| a-z | ||
| </Label> | ||
| <Label className="flex cursor-pointer items-center gap-1.5 text-xs"> | ||
| <Checkbox | ||
| variant="project" | ||
| isChecked={passwordOptions.useNumbers} | ||
| onCheckedChange={(checked) => | ||
| setPasswordOptions({ ...passwordOptions, useNumbers: checked as boolean }) | ||
| } | ||
| /> | ||
| 0-9 | ||
| </Label> | ||
| <Label className="flex cursor-pointer items-center gap-1.5 text-xs"> | ||
| <Checkbox | ||
| variant="project" | ||
| isChecked={passwordOptions.useSpecialChars} | ||
| onCheckedChange={(checked) => | ||
| setPasswordOptions({ ...passwordOptions, useSpecialChars: checked as boolean }) | ||
| } | ||
| /> | ||
| -_.~!* | ||
| </Label> | ||
| </div> | ||
|
|
||
| {onUsePassword && ( | ||
| <Button variant="project" size="xs" onClick={usePassword} className="w-full"> | ||
| Use Value | ||
| </Button> | ||
| )} | ||
| </div> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| }; | ||
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 @@ | ||
| export { PasswordGenerator, type PasswordGeneratorProps } from "./PasswordGenerator"; |
Oops, something went wrong.
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.