Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions webui/src/views/AddRepoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,32 @@ const repoDefaults = create(RepoSchema, {
},
});

export const AddRepoModal = ({ template }: { template: Repo | null }) => {
export const AddRepoModal = ({ template, templateClone }: { template: Repo | null, templateClone?: Repo | null }) => {
const [confirmLoading, setConfirmLoading] = useState(false);
const showModal = useShowModal();
const alertsApi = useAlertApi()!;
const [config, setConfig] = useConfig();
const [form] = Form.useForm<JsonValue>();
useEffect(() => {
const initVal = template
? toJson(RepoSchema, template, {
alwaysEmitImplicit: true,
})
: toJson(RepoSchema, repoDefaults, { alwaysEmitImplicit: true });
form.setFieldsValue(initVal);
}, [template]);
// This sets the default values for the form
if (templateClone) { // If the user is cloning an existing repository config
useEffect(() => {
const initVal = templateClone
? toJson(RepoSchema, templateClone, {
alwaysEmitImplicit: true,
})
: toJson(RepoSchema, repoDefaults, { alwaysEmitImplicit: true });
form.setFieldsValue(initVal);
}, [templateClone]);
} else {
useEffect(() => { // If the user is opening an existing repository config or creating a new one
const initVal = template
? toJson(RepoSchema, template, {
alwaysEmitImplicit: true,
})
: toJson(RepoSchema, repoDefaults, { alwaysEmitImplicit: true });
form.setFieldsValue(initVal);
}, [template]);
}

if (!config) {
return null;
Expand Down Expand Up @@ -157,6 +169,20 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
}
};

const handleClone = async () => {
setConfirmLoading(true);

try {

showModal(<AddRepoModal template={null} templateClone={template} />)

} catch (e: any) {
alertsApi.error(formatErrorAlert(e, "Operation error: "), 10);
} finally {
setConfirmLoading(false);
}
};

const handleCancel = () => {
showModal(null);
};
Expand All @@ -173,7 +199,7 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
Cancel
</Button>,
template != null ? (
<Tooltip
<><Tooltip
key="delete-tooltip"
title="Removes the repo from the config but will not delete the restic repository"
>
Expand All @@ -187,6 +213,9 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => {
Delete
</ConfirmButton>
</Tooltip>
<Button loading={confirmLoading} key="clone" onClick={handleClone}>
Clone Repository Config
</Button></>
) : null,
<SpinButton
key="check"
Expand Down