-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6aa657
commit 4515660
Showing
12 changed files
with
554 additions
and
10 deletions.
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
88 changes: 88 additions & 0 deletions
88
...onents/deployments/deployment-schedules/deployment-schedule-dialog/cron-schedule-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,88 @@ | ||
import { CronInput } from "@/components/ui/cron-input"; | ||
import { | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Switch } from "@/components/ui/switch"; | ||
import { TimezoneSelect } from "@/components/ui/timezone-select"; | ||
import { UseFormReturn } from "react-hook-form"; | ||
import type { FormSchema } from "./use-create-or-edit-schedule-form"; | ||
|
||
type CronScheduleFormProps = { | ||
form: UseFormReturn<FormSchema>; | ||
}; | ||
|
||
export const CronScheduleForm = ({ form }: CronScheduleFormProps) => ( | ||
<div className="flex flex-col gap-4"> | ||
<FormField | ||
control={form.control} | ||
name="active" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Active</FormLabel> | ||
<FormControl> | ||
<Switch | ||
className="block" | ||
checked={field.value} | ||
onCheckedChange={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<div className="flex gap-2"> | ||
<div className="w-3/4"> | ||
<FormField | ||
control={form.control} | ||
name="schedule.cron" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Value</FormLabel> | ||
<FormControl> | ||
<CronInput {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
<FormField | ||
control={form.control} | ||
name="schedule.day_or" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Day Or</FormLabel> | ||
<FormControl> | ||
<Switch | ||
className="block" | ||
checked={field.value} | ||
onCheckedChange={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
<FormField | ||
control={form.control} | ||
name="schedule.timezone" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Timezone</FormLabel> | ||
<FormControl> | ||
<TimezoneSelect | ||
selectedValue={field.value} | ||
onSelect={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
); |
103 changes: 103 additions & 0 deletions
103
...eployments/deployment-schedules/deployment-schedule-dialog/deployment-schedule-dialog.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,103 @@ | ||
import type { DeploymentSchedule } from "@/components/deployments/deployment-schedules/types"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "@/components/ui/dialog"; | ||
import { Form, FormMessage } from "@/components/ui/form"; | ||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
|
||
import { CronScheduleForm } from "./cron-schedule-form"; | ||
import { IntervalScheduleForm } from "./interval-schedule-form"; | ||
import { RRuleScheduleForm } from "./rrule-schedule-form"; | ||
import { useCreateOrEditScheduleForm } from "./use-create-or-edit-schedule-form"; | ||
|
||
type DeploymentScheduleDialogProps = { | ||
deployment_id: string; | ||
onOpenChange: (open: boolean) => void; | ||
onSubmit: () => void; | ||
open: boolean; | ||
scheduleToEdit?: DeploymentSchedule; | ||
}; | ||
|
||
export const DeploymentScheduleDialog = ({ | ||
deployment_id, | ||
onOpenChange, | ||
onSubmit, | ||
open, | ||
scheduleToEdit, | ||
}: DeploymentScheduleDialogProps) => { | ||
const { form, saveOrUpdate, isLoading } = useCreateOrEditScheduleForm({ | ||
deployment_id, | ||
onSubmit, | ||
scheduleToEdit, | ||
}); | ||
|
||
const SCHEDULE_TAB_OPTIONS = [ | ||
{ | ||
value: "interval", | ||
label: "Interval", | ||
Component: () => <IntervalScheduleForm form={form} />, | ||
}, | ||
{ | ||
value: "cron", | ||
label: "Cron", | ||
Component: () => <CronScheduleForm form={form} />, | ||
}, | ||
{ value: "rrule", label: "RRule", Component: () => <RRuleScheduleForm /> }, | ||
] as const; | ||
|
||
const scheduleTab = form.watch("tab"); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={onOpenChange}> | ||
<DialogContent aria-describedby={undefined}> | ||
<DialogHeader> | ||
<DialogTitle>{scheduleToEdit ? "Edit" : "Add"} Schedule</DialogTitle> | ||
</DialogHeader> | ||
|
||
<Form {...form}> | ||
<form | ||
onSubmit={(e) => void form.handleSubmit(saveOrUpdate)(e)} | ||
className="space-y-4" | ||
> | ||
<FormMessage>{form.formState.errors.root?.message}</FormMessage> | ||
<Tabs | ||
defaultValue={SCHEDULE_TAB_OPTIONS[0].value} | ||
value={scheduleTab} | ||
> | ||
<TabsList> | ||
{SCHEDULE_TAB_OPTIONS.map(({ value, label }) => ( | ||
<TabsTrigger | ||
key={value} | ||
value={value} | ||
onClick={() => form.setValue("tab", value)} | ||
> | ||
{label} | ||
</TabsTrigger> | ||
))} | ||
</TabsList> | ||
{SCHEDULE_TAB_OPTIONS.map(({ value, Component }) => ( | ||
<TabsContent key={value} value={value}> | ||
<Component /> | ||
</TabsContent> | ||
))} | ||
</Tabs> | ||
<DialogFooter> | ||
<DialogTrigger asChild> | ||
<Button variant="outline">Close</Button> | ||
</DialogTrigger> | ||
<Button type="submit" loading={isLoading}> | ||
Save | ||
</Button> | ||
</DialogFooter> | ||
</form> | ||
</Form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
ui-v2/src/components/deployments/deployment-schedules/deployment-schedule-dialog/index.ts
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 @@ | ||
export { DeploymentScheduleDialog } from "./deployment-schedule-dialog"; |
73 changes: 73 additions & 0 deletions
73
...ts/deployments/deployment-schedules/deployment-schedule-dialog/interval-schedule-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,73 @@ | ||
import { Calendar } from "@/components/ui/calendar"; | ||
import { | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form"; | ||
import { Switch } from "@/components/ui/switch"; | ||
import { TimezoneSelect } from "@/components/ui/timezone-select"; | ||
import { UseFormReturn } from "react-hook-form"; | ||
import type { FormSchema } from "./use-create-or-edit-schedule-form"; | ||
|
||
type IntervalScheduleFormProps = { | ||
form: UseFormReturn<FormSchema>; | ||
}; | ||
|
||
export const IntervalScheduleForm = ({ form }: IntervalScheduleFormProps) => ( | ||
<div className="flex flex-col gap-4"> | ||
<FormField | ||
control={form.control} | ||
name="active" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Active</FormLabel> | ||
<FormControl> | ||
<Switch | ||
className="block" | ||
checked={field.value} | ||
onCheckedChange={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<div className="flex gap-2"></div> | ||
<FormField | ||
control={form.control} | ||
name="schedule.anchor_date" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Anchor date</FormLabel> | ||
<FormControl> | ||
<Calendar | ||
mode="single" | ||
selected={new Date(field.value)} | ||
onSelect={(value) => String(field.onChange(value))} | ||
required | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="schedule.timezone" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Timezone</FormLabel> | ||
<FormControl> | ||
<TimezoneSelect | ||
selectedValue={field.value} | ||
onSelect={field.onChange} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
); |
8 changes: 8 additions & 0 deletions
8
...nents/deployments/deployment-schedules/deployment-schedule-dialog/rrule-schedule-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,8 @@ | ||
import { Typography } from "@/components/ui/typography"; | ||
|
||
export const RRuleScheduleForm = () => ( | ||
<Typography> | ||
Sorry, modifying RRule schedules via the UI is currently unsupported; select | ||
a different schedule type above or modify your schedule in code. | ||
</Typography> | ||
); |
Oops, something went wrong.