Skip to content

Commit

Permalink
feat(storage) default storage pool for volume creation [WD-7675]
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <mason.hu@canonical.com>
  • Loading branch information
mas-who committed Dec 8, 2023
1 parent 225aa1e commit 4ac25bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/pages/storage/StorageVolumes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ const StorageVolumes: FC = () => {
return <Loader text="Loading storage volumes..." />;
}

const defaultPoolForVolumeCreate =
filters.pools.length === 1 ? filters.pools[0] : "";

return volumes.length === 0 ? (
<EmptyState
className="empty-state"
Expand All @@ -392,7 +395,10 @@ const StorageVolumes: FC = () => {
<StorageVolumesFilter key={project} volumes={volumes} />
</div>
<div>
<CreateVolumeBtn project={project} />
<CreateVolumeBtn
project={project}
defaultPool={defaultPoolForVolumeCreate}
/>
</div>
</div>
<Pagination
Expand Down
10 changes: 7 additions & 3 deletions src/pages/storage/actions/CreateVolumeBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { useNavigate } from "react-router-dom";

interface Props {
project: string;
defaultPool?: string;
className?: string;
}

const CreateVolumeBtn: FC<Props> = ({ project, className }) => {
const CreateVolumeBtn: FC<Props> = ({ project, className, defaultPool }) => {
const navigate = useNavigate();

const handleAdd = () => {
navigate(`/ui/project/${project}/storage/volumes/create
`);
navigate(
`/ui/project/${project}/storage/volumes/create${
defaultPool ? `?pool=${defaultPool}` : ""
}`,
);
};

return (
Expand Down
6 changes: 4 additions & 2 deletions src/pages/storage/forms/StorageVolumeCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { queryKeys } from "util/queryKeys";
import SubmitButton from "components/SubmitButton";
import { createStorageVolume } from "api/storage-pools";
import NotificationRow from "components/NotificationRow";
import { useNavigate, useParams } from "react-router-dom";
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import { testDuplicateStorageVolumeName } from "util/storageVolume";
import BaseLayout from "components/BaseLayout";
import {
Expand All @@ -17,6 +17,7 @@ import {
import StorageVolumeForm from "pages/storage/forms/StorageVolumeForm";
import { MAIN_CONFIGURATION } from "pages/storage/forms/StorageVolumeFormMenu";
import { slugify } from "util/slugify";
import { POOL } from "../StorageVolumesFilter";

const StorageVolumeCreate: FC = () => {
const navigate = useNavigate();
Expand All @@ -25,6 +26,7 @@ const StorageVolumeCreate: FC = () => {
const [section, setSection] = useState(slugify(MAIN_CONFIGURATION));
const controllerState = useState<AbortController | null>(null);
const { project } = useParams<{ project: string }>();
const [searchParams] = useSearchParams();

if (!project) {
return <>Missing project</>;
Expand All @@ -44,7 +46,7 @@ const StorageVolumeCreate: FC = () => {
type: "custom",
name: "",
project: project,
pool: "",
pool: searchParams.get(POOL) || "",
size: "GiB",
isReadOnly: false,
isCreating: true,
Expand Down

0 comments on commit 4ac25bc

Please sign in to comment.