-
Notifications
You must be signed in to change notification settings - Fork 21
/
TemplatesCatalogDrawerFooter.tsx
89 lines (81 loc) · 2.86 KB
/
TemplatesCatalogDrawerFooter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react';
import { V1Template } from '@kubevirt-ui/kubevirt-api/console';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import {
generateVMName,
getTemplateVirtualMachineObject,
} from '@kubevirt-utils/resources/template';
import {
useProcessedTemplate,
useVmTemplateSource,
} from '@kubevirt-utils/resources/template/hooks';
import {
Split,
SplitItem,
Stack,
StackItem,
Title,
Tooltip,
TooltipPosition,
} from '@patternfly/react-core';
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons';
import { TemplatesCatalogDrawerCreateForm } from './TemplatesCatalogDrawerCreateForm';
import { TemplatesCatalogDrawerFooterSkeleton } from './TemplatesCatalogDrawerFooterSkeleton';
type TemplateCatalogDrawerFooterProps = {
namespace: string;
template: V1Template | undefined;
onCancel: () => void;
};
export const TemplatesCatalogDrawerFooter: React.FC<TemplateCatalogDrawerFooterProps> = ({
namespace,
template,
onCancel,
}) => {
const { t } = useKubevirtTranslation();
const { isBootSourceAvailable, loaded: bootSourceLoaded } = useVmTemplateSource(template);
const [processedTemplate, processedTemplateLoaded] = useProcessedTemplate(template, namespace);
const canQuickCreate = Boolean(processedTemplate) && isBootSourceAvailable;
const loaded = bootSourceLoaded && processedTemplateLoaded;
if (!loaded) {
return <TemplatesCatalogDrawerFooterSkeleton />;
}
const initialVMName =
getTemplateVirtualMachineObject(processedTemplate)?.metadata?.name || generateVMName(template);
return (
<Stack className="template-catalog-drawer-info">
<div className="template-catalog-drawer-footer-section">
<Stack hasGutter>
<StackItem>
<Split hasGutter>
<SplitItem>
<Title headingLevel="h1" size="lg">
{canQuickCreate
? t('Quick create VirtualMachine')
: t('Customize VirtualMachine')}
</Title>
</SplitItem>
{canQuickCreate && (
<SplitItem className="template-catalog-drawer-footer-tooltip">
<Tooltip
position={TooltipPosition.right}
content={<div>{t('This Template supports quick create VirtualMachine')}</div>}
>
<OutlinedQuestionCircleIcon />
</Tooltip>
</SplitItem>
)}
</Split>
</StackItem>
<TemplatesCatalogDrawerCreateForm
namespace={namespace}
template={template}
canQuickCreate={canQuickCreate}
initialVMName={initialVMName}
isBootSourceAvailable={isBootSourceAvailable}
onCancel={onCancel}
/>
</Stack>
</div>
</Stack>
);
};