chore: wording and formatting
This commit is contained in:
parent
e350843d4e
commit
a985c95a31
4 changed files with 65 additions and 53 deletions
|
|
@ -88,11 +88,8 @@ const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalFormValu
|
||||||
const isDaily = !isHourly && dayOfMonthPart === "*" && dayOfWeekPart === "*";
|
const isDaily = !isHourly && dayOfMonthPart === "*" && dayOfWeekPart === "*";
|
||||||
|
|
||||||
const frequency = isHourly ? "hourly" : isMonthly ? "monthly" : isDaily ? "daily" : "weekly";
|
const frequency = isHourly ? "hourly" : isMonthly ? "monthly" : isDaily ? "daily" : "weekly";
|
||||||
|
|
||||||
const dailyTime = isHourly ? undefined : `${hourPart.padStart(2, "0")}:${minutePart.padStart(2, "0")}`;
|
const dailyTime = isHourly ? undefined : `${hourPart.padStart(2, "0")}:${minutePart.padStart(2, "0")}`;
|
||||||
|
|
||||||
const weeklyDay = frequency === "weekly" ? dayOfWeekPart : undefined;
|
const weeklyDay = frequency === "weekly" ? dayOfWeekPart : undefined;
|
||||||
|
|
||||||
const monthlyDays = isMonthly ? dayOfMonthPart.split(",") : undefined;
|
const monthlyDays = isMonthly ? dayOfMonthPart.split(",") : undefined;
|
||||||
|
|
||||||
const patterns = schedule.includePatterns || [];
|
const patterns = schedule.includePatterns || [];
|
||||||
|
|
@ -103,8 +100,8 @@ const backupScheduleToFormValues = (schedule?: BackupSchedule): InternalFormValu
|
||||||
return {
|
return {
|
||||||
name: schedule.name,
|
name: schedule.name,
|
||||||
repositoryId: schedule.repositoryId,
|
repositoryId: schedule.repositoryId,
|
||||||
frequency,
|
frequency,
|
||||||
monthlyDays,
|
monthlyDays,
|
||||||
dailyTime,
|
dailyTime,
|
||||||
weeklyDay,
|
weeklyDay,
|
||||||
includePatterns: fileBrowserPaths.length > 0 ? fileBrowserPaths : undefined,
|
includePatterns: fileBrowserPaths.length > 0 ? fileBrowserPaths : undefined,
|
||||||
|
|
@ -257,7 +254,7 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
|
||||||
<SelectItem value="hourly">Hourly</SelectItem>
|
<SelectItem value="hourly">Hourly</SelectItem>
|
||||||
<SelectItem value="daily">Daily</SelectItem>
|
<SelectItem value="daily">Daily</SelectItem>
|
||||||
<SelectItem value="weekly">Weekly</SelectItem>
|
<SelectItem value="weekly">Weekly</SelectItem>
|
||||||
<SelectItem value="monthly">Monthly</SelectItem>
|
<SelectItem value="monthly">Specific days</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
@ -312,41 +309,41 @@ export const CreateScheduleForm = ({ initialValues, formId, onSubmit, volume }:
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{frequency === "monthly" && (
|
{frequency === "monthly" && (
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="monthlyDays"
|
name="monthlyDays"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="md:col-span-2">
|
<FormItem className="md:col-span-2">
|
||||||
<FormLabel>Days of the month</FormLabel>
|
<FormLabel>Days of the month</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<div className="grid grid-cols-7 gap-4 w-max">
|
<div className="grid grid-cols-7 gap-4 w-max">
|
||||||
{Array.from({ length: 31 }, (_, i) => {
|
{Array.from({ length: 31 }, (_, i) => {
|
||||||
const day = (i + 1).toString();
|
const day = (i + 1).toString();
|
||||||
const isSelected = field.value?.includes(day);
|
const isSelected = field.value?.includes(day);
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
key={day}
|
key={day}
|
||||||
variant={isSelected ? "primary" : "secondary"}
|
variant={isSelected ? "primary" : "secondary"}
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const current = field.value || [];
|
const current = field.value || [];
|
||||||
const next = isSelected ? current.filter((d) => d !== day) : [...current, day];
|
const next = isSelected ? current.filter((d) => d !== day) : [...current, day];
|
||||||
field.onChange(next);
|
field.onChange(next);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{day}
|
{day}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>Select one or more days when the backup should run.</FormDescription>
|
<FormDescription>Select one or more days when the backup should run.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,12 @@ export default function ScheduleDetailsPage({ params, loaderData }: Route.Compon
|
||||||
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
||||||
if (!schedule) return;
|
if (!schedule) return;
|
||||||
|
|
||||||
const cronExpression = getCronExpression(formValues.frequency, formValues.dailyTime, formValues.weeklyDay, formValues.monthlyDays);
|
const cronExpression = getCronExpression(
|
||||||
|
formValues.frequency,
|
||||||
|
formValues.dailyTime,
|
||||||
|
formValues.weeklyDay,
|
||||||
|
formValues.monthlyDays,
|
||||||
|
);
|
||||||
|
|
||||||
const retentionPolicy: Record<string, number> = {};
|
const retentionPolicy: Record<string, number> = {};
|
||||||
if (formValues.keepLast) retentionPolicy.keepLast = formValues.keepLast;
|
if (formValues.keepLast) retentionPolicy.keepLast = formValues.keepLast;
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,12 @@ export default function CreateBackup({ loaderData }: Route.ComponentProps) {
|
||||||
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
const handleSubmit = (formValues: BackupScheduleFormValues) => {
|
||||||
if (!selectedVolumeId) return;
|
if (!selectedVolumeId) return;
|
||||||
|
|
||||||
const cronExpression = getCronExpression(formValues.frequency, formValues.dailyTime, formValues.weeklyDay, formValues.monthlyDays);
|
const cronExpression = getCronExpression(
|
||||||
|
formValues.frequency,
|
||||||
|
formValues.dailyTime,
|
||||||
|
formValues.weeklyDay,
|
||||||
|
formValues.monthlyDays,
|
||||||
|
);
|
||||||
|
|
||||||
const retentionPolicy: Record<string, number> = {};
|
const retentionPolicy: Record<string, number> = {};
|
||||||
if (formValues.keepLast) retentionPolicy.keepLast = formValues.keepLast;
|
if (formValues.keepLast) retentionPolicy.keepLast = formValues.keepLast;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import { intervalToDuration } from "date-fns";
|
import { intervalToDuration } from "date-fns";
|
||||||
|
|
||||||
export const getCronExpression = (frequency: string, dailyTime?: string, weeklyDay?: string, monthlyDays?: string[]): string => {
|
export const getCronExpression = (
|
||||||
|
frequency: string,
|
||||||
|
dailyTime?: string,
|
||||||
|
weeklyDay?: string,
|
||||||
|
monthlyDays?: string[],
|
||||||
|
): string => {
|
||||||
if (frequency === "hourly") {
|
if (frequency === "hourly") {
|
||||||
return "0 * * * *";
|
return "0 * * * *";
|
||||||
}
|
}
|
||||||
|
|
@ -16,13 +21,13 @@ export const getCronExpression = (frequency: string, dailyTime?: string, weeklyD
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frequency === "monthly") {
|
if (frequency === "monthly") {
|
||||||
const sortedDays = (monthlyDays || [])
|
const sortedDays = (monthlyDays || [])
|
||||||
.map(Number)
|
.map(Number)
|
||||||
.filter((day) => day >= 1 && day <= 31)
|
.filter((day) => day >= 1 && day <= 31)
|
||||||
.sort((a, b) => a - b);
|
.sort((a, b) => a - b);
|
||||||
const days = sortedDays.length > 0 ? sortedDays.join(",") : "1";
|
const days = sortedDays.length > 0 ? sortedDays.join(",") : "1";
|
||||||
return `${minutes} ${hours} ${days} * *`;
|
return `${minutes} ${hours} ${days} * *`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${minutes} ${hours} * * ${weeklyDay ?? "0"}`;
|
return `${minutes} ${hours} * * ${weeklyDay ?? "0"}`;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue