mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
add with data field to branch (#37451)
* add with data field to branch * Fix types --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
1 parent
d6fdb20a2a
commit
4bfdbe32ac
5 files changed
+78
-19
No files matched your search
@@ -42,13 +42,16 @@ import {
|
||||
Form_Shadcn_,
|
||||
Input_Shadcn_,
|
||||
Label_Shadcn_ as Label,
|
||||
Switch,
|
||||
cn,
|
||||
} from 'ui'
|
||||
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
||||
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
||||
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
||||
import { useFlag } from 'hooks/ui/useFlag'
|
||||
|
||||
export const CreateBranchModal = () => {
|
||||
const allowDataBranching = useFlag('allowDataBranching')
|
||||
const { ref } = useParams()
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -141,6 +144,7 @@ export const CreateBranchModal = () => {
|
||||
(val) => gitlessBranching || !githubConnection || (val && val.length > 0),
|
||||
'Git branch name is required when GitHub is connected'
|
||||
),
|
||||
withData: z.boolean().default(false).optional(),
|
||||
})
|
||||
.superRefine(async (val, ctx) => {
|
||||
if (val.gitBranchName && val.gitBranchName.length > 0 && githubConnection?.repository.id) {
|
||||
@@ -164,7 +168,7 @@ export const CreateBranchModal = () => {
|
||||
mode: 'onSubmit',
|
||||
reValidateMode: 'onBlur',
|
||||
resolver: zodResolver(FormSchema),
|
||||
defaultValues: { branchName: '', gitBranchName: '' },
|
||||
defaultValues: { branchName: '', gitBranchName: '', withData: false },
|
||||
})
|
||||
|
||||
const canSubmit = !isCreating && !isChecking
|
||||
@@ -184,6 +188,7 @@ export const CreateBranchModal = () => {
|
||||
branchName: data.branchName,
|
||||
is_default: false,
|
||||
...(data.gitBranchName ? { gitBranch: data.gitBranchName } : {}),
|
||||
...(allowDataBranching ? { withData: data.withData } : {}),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -295,6 +300,7 @@ export const CreateBranchModal = () => {
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isLoadingConnections && <GenericSkeletonLoader />}
|
||||
{isErrorConnections && (
|
||||
<AlertError
|
||||
@@ -315,7 +321,7 @@ export const CreateBranchModal = () => {
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-foreground-light">
|
||||
<p className="text-sm text-foreground-lighter">
|
||||
Keep this preview branch in sync with a chosen GitHub branch
|
||||
</p>
|
||||
</div>
|
||||
@@ -326,6 +332,23 @@ export const CreateBranchModal = () => {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{allowDataBranching && (
|
||||
<FormField_Shadcn_
|
||||
control={form.control}
|
||||
name="withData"
|
||||
render={({ field }) => (
|
||||
<FormItemLayout
|
||||
label="Include data"
|
||||
layout="flex-row-reverse"
|
||||
description="Clone production data into this branch"
|
||||
>
|
||||
<FormControl_Shadcn_>
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</FormControl_Shadcn_>
|
||||
</FormItemLayout>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</DialogSection>
|
||||
|
||||
<DialogSectionSeparator />
|
||||
|
||||
@@ -11,6 +11,7 @@ export type BranchCreateVariables = {
|
||||
branchName: string
|
||||
gitBranch?: string
|
||||
region?: string
|
||||
withData?: boolean
|
||||
}
|
||||
|
||||
export async function createBranch({
|
||||
@@ -19,6 +20,7 @@ export async function createBranch({
|
||||
branchName,
|
||||
gitBranch,
|
||||
region,
|
||||
withData,
|
||||
}: BranchCreateVariables) {
|
||||
const { data, error } = await post('/v1/projects/{ref}/branches', {
|
||||
params: {
|
||||
@@ -29,6 +31,7 @@ export async function createBranch({
|
||||
branch_name: branchName,
|
||||
git_branch: gitBranch,
|
||||
region: region,
|
||||
with_data: withData,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ const WHITELIST_ERRORS = [
|
||||
'already exists in your organization.',
|
||||
]
|
||||
|
||||
type CreateProjectBody = components['schemas']['CreateProjectBody']
|
||||
type CloudProvider = CreateProjectBody['cloud_provider']
|
||||
|
||||
export type ProjectCreateVariables = {
|
||||
name: string
|
||||
organizationSlug: string
|
||||
@@ -51,8 +54,8 @@ export async function createProject({
|
||||
postgresEngine,
|
||||
releaseChannel,
|
||||
}: ProjectCreateVariables) {
|
||||
const body: components['schemas']['CreateProjectBody'] = {
|
||||
cloud_provider: cloudProvider,
|
||||
const body: CreateProjectBody = {
|
||||
cloud_provider: cloudProvider as CloudProvider,
|
||||
organization_slug: organizationSlug,
|
||||
name,
|
||||
db_pass: dbPass,
|
||||
|
||||
Reference in new issue
Block a user