-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(storage) adjust store pool detail header
- Loading branch information
Showing
10 changed files
with
193 additions
and
76 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
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
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
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,74 @@ | ||
import React, { FC, useState } from "react"; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
import RenameHeader, { RenameHeaderValues } from "components/RenameHeader"; | ||
import { useNotify } from "context/notify"; | ||
import { useFormik } from "formik"; | ||
import * as Yup from "yup"; | ||
import { LxdStoragePool } from "types/storage"; | ||
import { renameStoragePool } from "api/storage-pools"; | ||
import DeleteStorageBtn from "pages/storage/actions/DeleteStorageBtn"; | ||
import { testDuplicateName } from "util/storage"; | ||
|
||
interface Props { | ||
name: string; | ||
storagePool: LxdStoragePool; | ||
project: string; | ||
} | ||
|
||
const StorageDetailHeader: FC<Props> = ({ name, storagePool, project }) => { | ||
const navigate = useNavigate(); | ||
const notify = useNotify(); | ||
const controllerState = useState<AbortController | null>(null); | ||
|
||
const RenameSchema = Yup.object().shape({ | ||
name: Yup.string() | ||
.test(...testDuplicateName(project, controllerState)) | ||
.required("This field is required"), | ||
}); | ||
|
||
const formik = useFormik<RenameHeaderValues>({ | ||
initialValues: { | ||
name, | ||
isRenaming: false, | ||
}, | ||
validationSchema: RenameSchema, | ||
onSubmit: (values) => { | ||
if (name === values.name) { | ||
void formik.setFieldValue("isRenaming", false); | ||
formik.setSubmitting(false); | ||
return; | ||
} | ||
renameStoragePool(name, values.name, project) | ||
.then(() => { | ||
navigate( | ||
`/ui/${project}/storage/${values.name}`, | ||
notify.queue(notify.success("Storage pool renamed.")) | ||
); | ||
void formik.setFieldValue("isRenaming", false); | ||
}) | ||
.catch((e) => { | ||
notify.failure("Renaming failed", e); | ||
}) | ||
.finally(() => formik.setSubmitting(false)); | ||
}, | ||
}); | ||
|
||
return ( | ||
<RenameHeader | ||
name={name} | ||
parentItem={<Link to={`/ui/${project}/storage`}>Storage pools</Link>} | ||
controls={ | ||
<DeleteStorageBtn | ||
key="delete" | ||
storage={storagePool} | ||
project={project} | ||
/> | ||
} | ||
isLoaded={true} | ||
formik={formik} | ||
renameDisabledReason="Cannot rename storage pools" | ||
/> | ||
); | ||
}; | ||
|
||
export default StorageDetailHeader; |
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
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
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
Oops, something went wrong.