fix: better defaults in add repo / add plan views

This commit is contained in:
Gareth George
2024-11-26 01:24:59 -08:00
parent c810d27375
commit 4d7be23e8c
3 changed files with 60 additions and 4 deletions
+1 -1
View File
@@ -104,5 +104,5 @@ else
exit 1
fi
echo "Logs are available at /tmp/backrest.log"
echo "Logs are available at ~/.local/share/backrest/processlogs/backrest.log"
echo "Access backrest WebUI at http://localhost:9898"
+30 -2
View File
@@ -15,7 +15,11 @@ import {
} from "antd";
import React, { useEffect, useState } from "react";
import { useShowModal } from "../components/ModalManager";
import { Plan, RetentionPolicy } from "../../gen/ts/v1/config_pb";
import {
Plan,
RetentionPolicy,
Schedule_Clock,
} from "../../gen/ts/v1/config_pb";
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
import { URIAutocomplete } from "../components/URIAutocomplete";
import { formatErrorAlert, useAlertApi } from "../components/Alerts";
@@ -32,6 +36,26 @@ import {
ScheduleFormItem,
} from "../components/ScheduleFormItem";
const planDefaults = new Plan({
schedule: {
schedule: {
case: "cron",
value: "0 * * * *", // every hour
},
clock: Schedule_Clock.LOCAL,
},
retention: {
policy: {
case: "policyTimeBucketed",
value: {
hourly: 24,
daily: 30,
monthly: 12,
},
},
},
});
export const AddPlanModal = ({ template }: { template: Plan | null }) => {
const [confirmLoading, setConfirmLoading] = useState(false);
const showModal = useShowModal();
@@ -39,7 +63,11 @@ export const AddPlanModal = ({ template }: { template: Plan | null }) => {
const [config, setConfig] = useConfig();
const [form] = Form.useForm();
useEffect(() => {
form.setFieldsValue(template ? JSON.parse(template.toJsonString()) : {});
form.setFieldsValue(
template
? JSON.parse(template.toJsonString())
: JSON.parse(planDefaults.toJsonString())
);
}, [template]);
if (!config) {
+29 -1
View File
@@ -23,6 +23,8 @@ import {
CommandPrefix_IONiceLevel,
Hook,
Repo,
Schedule,
Schedule_Clock,
} from "../../gen/ts/v1/config_pb";
import { URIAutocomplete } from "../components/URIAutocomplete";
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
@@ -45,6 +47,28 @@ import {
import { proto3 } from "@bufbuild/protobuf";
import { isWindows } from "../state/buildcfg";
const repoDefaults = new Repo({
prunePolicy: {
maxUnusedPercent: 10,
schedule: {
schedule: {
case: "cron",
value: "0 0 1 * *", // 1st of the month,
},
clock: Schedule_Clock.LAST_RUN_TIME,
},
},
checkPolicy: {
schedule: {
schedule: {
case: "cron",
value: "0 0 1 * *", // 1st of the month,
},
clock: Schedule_Clock.LAST_RUN_TIME,
},
},
});
export const AddRepoModal = ({ template }: { template: Repo | null }) => {
const [confirmLoading, setConfirmLoading] = useState(false);
const showModal = useShowModal();
@@ -52,7 +76,11 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
const [config, setConfig] = useConfig();
const [form] = Form.useForm();
useEffect(() => {
form.setFieldsValue(template ? JSON.parse(template.toJsonString()) : {});
form.setFieldsValue(
template
? JSON.parse(template.toJsonString())
: JSON.parse(repoDefaults.toJsonString())
);
}, [template]);
if (!config) {