-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add create instance from snapshot feature [WD-14411] (#858)
## Done - Add duplicate snapshot feature
- Loading branch information
Showing
11 changed files
with
418 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Select, SelectProps } from "@canonical/react-components"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { fetchClusterMembers } from "api/cluster"; | ||
import { useSettings } from "context/useSettings"; | ||
import React, { FC } from "react"; | ||
import { queryKeys } from "util/queryKeys"; | ||
import { isClusteredServer } from "util/settings"; | ||
|
||
const ClusterMemberSelector: FC<SelectProps> = ({ | ||
label, | ||
disabled, | ||
...props | ||
}) => { | ||
const { data: settings } = useSettings(); | ||
const isClustered = isClusteredServer(settings); | ||
const { data: clusterMembers = [], isLoading: clusterMembersLoading } = | ||
useQuery({ | ||
queryKey: [queryKeys.cluster], | ||
queryFn: fetchClusterMembers, | ||
enabled: isClustered, | ||
}); | ||
|
||
return isClustered ? ( | ||
<Select | ||
{...props} | ||
label={label ?? "Cluster member"} | ||
options={clusterMembers.map((clusterMember) => { | ||
return { | ||
label: clusterMember.server_name, | ||
value: clusterMember.server_name, | ||
}; | ||
})} | ||
disabled={disabled || clusterMembersLoading} | ||
/> | ||
) : null; | ||
}; | ||
|
||
export default ClusterMemberSelector; |
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
48 changes: 48 additions & 0 deletions
48
src/pages/instances/actions/snapshots/CreateInstanceFromSnapshotBtn.tsx
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,48 @@ | ||
import { FC } from "react"; | ||
import { LxdInstance, LxdInstanceSnapshot } from "types/instance"; | ||
import { Button, Icon } from "@canonical/react-components"; | ||
import usePortal from "react-useportal"; | ||
import CreateInstanceFromSnapshotForm from "../../forms/CreateInstanceFromSnapshotForm"; | ||
|
||
interface Props { | ||
instance: LxdInstance; | ||
snapshot: LxdInstanceSnapshot; | ||
isDeleting: boolean; | ||
isRestoring: boolean; | ||
} | ||
|
||
const CreateInstanceFromSnapshotBtn: FC<Props> = ({ | ||
instance, | ||
snapshot, | ||
isDeleting, | ||
isRestoring, | ||
}) => { | ||
const { openPortal, closePortal, isOpen, Portal } = usePortal(); | ||
|
||
return ( | ||
<> | ||
{isOpen && ( | ||
<Portal> | ||
<CreateInstanceFromSnapshotForm | ||
close={closePortal} | ||
instance={instance} | ||
snapshot={snapshot} | ||
/> | ||
</Portal> | ||
)} | ||
<Button | ||
appearance="base" | ||
hasIcon | ||
dense | ||
aria-label="Create instance" | ||
disabled={isDeleting || isRestoring} | ||
onClick={openPortal} | ||
title="Create instance" | ||
> | ||
<Icon name="plus" /> | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default CreateInstanceFromSnapshotBtn; |
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.