-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
refactor(ui): simplify implementation of github provider using PAT #1963
Merged
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
97e793f
refactor(ui): implify implementation of github provider using PAT
liangfung ba204e4
update
liangfung 184f0fc
remove useless component
liangfung 27fec4f
format
liangfung 6bb0b12
[autofix.ci] apply automated fixes
autofix-ci[bot] a7dc4d8
justify size
liangfung 63e13ac
[autofix.ci] apply automated fixes
autofix-ci[bot] 7d51440
restructure-repository-providers
wsxiaoys 0c6b508
consolidate layouts
wsxiaoys 24127f9
adjust ux
wsxiaoys 1387407
update ux
wsxiaoys 0035535
fix spacing
wsxiaoys 4883119
update
wsxiaoys b820202
fix ui
wsxiaoys 7348e5a
update
wsxiaoys c448073
update
wsxiaoys 817ca98
update
wsxiaoys 96cc538
[autofix.ci] apply automated fixes
autofix-ci[bot] d3b7483
remove usless file
wsxiaoys d4faa7a
update
wsxiaoys 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 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
28 changes: 28 additions & 0 deletions
28
ee/tabby-ui/app/(dashboard)/settings/(integrations)/git/components/tabs-header.tsx
This file contains 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,28 @@ | ||
'use client' | ||
|
||
import Link from 'next/link' | ||
import { usePathname } from 'next/navigation' | ||
|
||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs' | ||
|
||
export default function GitTabsHeader() { | ||
const pathname = usePathname() | ||
const defualtValue = pathname.startsWith('/settings/git/generic') | ||
? 'generic' | ||
: 'gitops' | ||
|
||
return ( | ||
<Tabs defaultValue={defualtValue}> | ||
<div className="sticky top-0 mb-4 flex"> | ||
<TabsList className="grid grid-cols-2"> | ||
<TabsTrigger value="gitops" asChild> | ||
<Link href="/settings/git/gitops">Gitops</Link> | ||
</TabsTrigger> | ||
<TabsTrigger value="generic" asChild> | ||
<Link href="/settings/git/generic">Generic Git Repositories</Link> | ||
</TabsTrigger> | ||
</TabsList> | ||
</div> | ||
</Tabs> | ||
) | ||
} |
File renamed without changes.
This file contains 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 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 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
35 changes: 35 additions & 0 deletions
35
ee/tabby-ui/app/(dashboard)/settings/(integrations)/git/generic/new/components/new-page.tsx
This file contains 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,35 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { CardTitle } from '@/components/ui/card' | ||
import { IconChevronLeft } from '@/components/ui/icons' | ||
|
||
import RepositoryForm from './create-repository-form' | ||
|
||
export const NewRepository = () => { | ||
const router = useRouter() | ||
|
||
const onCreated = () => { | ||
router.replace('/settings/git/generic') | ||
} | ||
|
||
return ( | ||
<> | ||
<CardTitle className="py-6"> | ||
<div className="-ml-1 flex items-center"> | ||
<Button | ||
onClick={() => router.back()} | ||
variant={'ghost'} | ||
className="h-6 px-1" | ||
> | ||
<IconChevronLeft className="h-5 w-5" /> | ||
</Button> | ||
<span className="ml-2">Create Generic git repository</span> | ||
</div> | ||
</CardTitle> | ||
<RepositoryForm onCreated={onCreated} /> | ||
</> | ||
) | ||
} |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
ee/tabby-ui/app/(dashboard)/settings/(integrations)/git/generic/page.tsx
This file contains 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,5 @@ | ||
import Repository from './components/repository' | ||
|
||
export default function Generic() { | ||
return <Repository /> | ||
} |
This file contains 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
183 changes: 183 additions & 0 deletions
183
...by-ui/app/(dashboard)/settings/(integrations)/git/gitops/components/git-provider-form.tsx
This file contains 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,183 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import { zodResolver } from '@hookform/resolvers/zod' | ||
import { useForm, UseFormReturn } from 'react-hook-form' | ||
import * as z from 'zod' | ||
|
||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage | ||
} from '@/components/ui/form' | ||
import { IconGitHub } from '@/components/ui/icons' | ||
import { Input } from '@/components/ui/input' | ||
import { Label } from '@/components/ui/label' | ||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' | ||
|
||
export const createGitProviderSchema = z.object({ | ||
provider: z.string(), | ||
displayName: z | ||
.string() | ||
.trim() | ||
.regex( | ||
/^[\w-]+$/, | ||
'Display name must contain only alphanumeric characters, underscores, and hyphens' | ||
), | ||
accessToken: z.string() | ||
}) | ||
|
||
export const updateGitProviderSchema = createGitProviderSchema.extend({ | ||
provider: createGitProviderSchema.shape.provider.optional() | ||
}) | ||
|
||
export type CreateGitProviderFormValues = z.infer< | ||
typeof createGitProviderSchema | ||
> | ||
export type UpdateGitProviderFormValues = z.infer< | ||
typeof updateGitProviderSchema | ||
> | ||
|
||
interface GitProviderFormProps { | ||
isNew?: boolean | ||
defaultValues?: Partial<z.infer<typeof createGitProviderSchema>> | ||
footer: React.ReactNode | ||
onSubmit: (values: any) => Promise<any> | ||
} | ||
|
||
export const GitProviderForm = React.forwardRef< | ||
{ | ||
form: UseFormReturn< | ||
CreateGitProviderFormValues | UpdateGitProviderFormValues | ||
> | ||
}, | ||
GitProviderFormProps | ||
>(({ isNew, defaultValues, footer, onSubmit }, ref) => { | ||
const formSchema = isNew ? createGitProviderSchema : updateGitProviderSchema | ||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues | ||
}) | ||
|
||
React.useImperativeHandle( | ||
ref, | ||
() => { | ||
return { | ||
form | ||
} | ||
}, | ||
[form] | ||
) | ||
|
||
return ( | ||
<Form {...form}> | ||
<div className="grid gap-2"> | ||
<form className="grid gap-6" onSubmit={form.handleSubmit(onSubmit)}> | ||
{isNew && ( | ||
<FormField | ||
control={form.control} | ||
name="provider" | ||
disabled={!isNew} | ||
render={({ field: { onChange, ...rest } }) => ( | ||
<FormItem> | ||
<FormLabel required>Choose Git provider</FormLabel> | ||
<FormControl> | ||
<RadioGroup | ||
className="flex flex-wrap gap-6" | ||
orientation="horizontal" | ||
onValueChange={onChange} | ||
{...rest} | ||
> | ||
<div className="flex items-center space-x-2"> | ||
<RadioGroupItem value="github" id="github" /> | ||
<Label | ||
className="flex cursor-pointer items-center gap-1" | ||
htmlFor="github" | ||
> | ||
<IconGitHub className="h-5 w-5" /> | ||
<span>GitHub.com</span> | ||
</Label> | ||
</div> | ||
</RadioGroup> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
)} | ||
<FormField | ||
control={form.control} | ||
name="displayName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel required>Display name</FormLabel> | ||
<FormDescription> | ||
A display name to help identifying among different configs | ||
using the same Git provider. | ||
</FormDescription> | ||
<FormControl> | ||
<Input | ||
placeholder="e.g. GitHub" | ||
autoCapitalize="none" | ||
autoCorrect="off" | ||
autoComplete="off" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="accessToken" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel required={isNew}>Access Token</FormLabel> | ||
<FormDescription> | ||
<div> | ||
Create a dedicated service user and generate a fine-grained | ||
personal access token with the member role for the | ||
organization or all projects to be managed. | ||
</div> | ||
<div className="ml-2">• Contents (Read-only)</div> | ||
</FormDescription> | ||
<FormControl> | ||
<Input | ||
placeholder="e.g. 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0NB" | ||
autoCapitalize="none" | ||
autoCorrect="off" | ||
autoComplete="off" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
{footer} | ||
{/* <div className="flex items-center justify-between"> | ||
<div> | ||
<FormMessage /> | ||
</div> | ||
<div> | ||
<Button | ||
type="submit" | ||
disabled={isSubmitting || (!isNew && !isDirty)} | ||
> | ||
{isSubmitting && <IconSpinner className="mr-2" />} | ||
{isNew ? 'Create' : 'Update'} | ||
</Button> | ||
</div> | ||
</div> */} | ||
</form> | ||
</div> | ||
</Form> | ||
) | ||
}) | ||
|
||
GitProviderForm.displayName = 'GitProviderForm' |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rmove?