Skip to content

Commit

Permalink
Custom support statement for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Nov 30, 2020
1 parent 867b5d8 commit 46a17ff
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 154 deletions.
Expand Up @@ -142,20 +142,13 @@
"No Eviction Strategy": "No Eviction Strategy",
"Provider": "Provider",
"Boot source": "Boot source",
"The image has been added to the cluster via the operator.": "The image has been added to the cluster via the operator.",
"The image has been added to the cluster by a user.": "The image has been added to the cluster by a user.",
"Add source": "Add source",
"Provide a source for the template across the cluster.": "Provide a source for the template across the cluster.",
"Boot source error": "Boot source error",
"Error with the provided boot source.": "Error with the provided boot source.",
"More information on boot sources": "More information on boot sources",
"Storage": "Storage",
"Workload profile": "Workload profile",
"View full details": "View full details",
"Template details": "Template details",
"Create": "Create",
"Red Hat supported templates are labeled below.": "Red Hat supported templates are labeled below.",
"Learn more about template support": "Learn more about template support",
"See template details for support.": "See template details for support.",
"Learn more about Red Hat support": "Learn more about Red Hat support.",
"With Wizard": "With Wizard",
"With YAML": "With YAML",
"With Import wizard": "With Import wizard",
Expand Down
Expand Up @@ -29,6 +29,9 @@ export const getInitialVmSettings = (data: CommonData): VMSettings => {
[VMSettingsField.TEMPLATE_PROVIDER]: {
isHidden: asHidden(!isCreateTemplate),
},
[VMSettingsField.TEMPLATE_SUPPORTED]: {
isHidden: asHidden(!isCreateTemplate),
},
[VMSettingsField.OPERATING_SYSTEM]: {
isRequired: asRequired(true),
},
Expand Down
Expand Up @@ -40,6 +40,7 @@ export const titleResolver: RenderableFieldResolver = {
[VMSettingsField.IMAGE_URL]: 'URL',
[VMSettingsField.START_VM]: 'Start virtual machine on creation',
[VMSettingsField.TEMPLATE_PROVIDER]: 'Template provider',
[VMSettingsField.TEMPLATE_SUPPORTED]: 'Add support label to this template',
};

export const placeholderResolver = {
Expand Down
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Form, TextArea, TextInput } from '@patternfly/react-core';
import { Checkbox, Form, TextArea, TextInput } from '@patternfly/react-core';
import { connect } from 'react-redux';
import { iGet, iGetIn } from '../../../../utils/immutable';
import { FormFieldMemoRow } from '../../form/form-field-row';
Expand Down Expand Up @@ -28,6 +28,7 @@ import { URLSource } from './url-source';

import '../../create-vm-wizard-footer.scss';
import './vm-settings-tab.scss';
import { getFieldId } from '../../utils/renderable-field-utils';

export const VMSettingsTabComponent: React.FC<VMSettingsTabComponentProps> = ({
iUserTemplate,
Expand Down Expand Up @@ -73,6 +74,18 @@ export const VMSettingsTabComponent: React.FC<VMSettingsTabComponentProps> = ({
example: your company name
</div>
</FormFieldMemoRow>
<FormFieldMemoRow
className="kv-create-vm__input-checkbox"
field={getField(VMSettingsField.TEMPLATE_SUPPORTED)}
fieldType={FormFieldType.INLINE_CHECKBOX}
>
<FormField>
<Checkbox
id={getFieldId(VMSettingsField.TEMPLATE_SUPPORTED)}
onChange={onChange(VMSettingsField.TEMPLATE_SUPPORTED)}
/>
</FormField>
</FormFieldMemoRow>
<FormFieldMemoRow
field={getField(VMSettingsField.DESCRIPTION)}
fieldType={FormFieldType.TEXT_AREA}
Expand Down
Expand Up @@ -76,6 +76,7 @@ export enum VMSettingsField {
IMAGE_URL = 'IMAGE_URL',
START_VM = 'START_VM',
TEMPLATE_PROVIDER = 'TEMPLATE_PROVIDER',
TEMPLATE_SUPPORTED = 'TEMPLATE_SUPPORTED',
}

export enum ImportProvidersField {
Expand Down
Expand Up @@ -33,18 +33,19 @@ const renderableFieldOrder: { [key in RenderableField]: number } = {
[VMWareProviderField.STATUS]: 17,
[VMSettingsField.NAME]: 18,
[VMSettingsField.TEMPLATE_PROVIDER]: 19,
[VMSettingsField.DESCRIPTION]: 20,
[VMSettingsField.OPERATING_SYSTEM]: 21,
[VMSettingsField.CLONE_COMMON_BASE_DISK_IMAGE]: 22,
[VMSettingsField.MOUNT_WINDOWS_GUEST_TOOLS]: 23,
[VMSettingsField.FLAVOR]: 24,
[VMSettingsField.MEMORY]: 25,
[VMSettingsField.CPU]: 26,
[VMSettingsField.WORKLOAD_PROFILE]: 27,
[VMSettingsField.PROVISION_SOURCE_TYPE]: 28,
[VMSettingsField.CONTAINER_IMAGE]: 29,
[VMSettingsField.IMAGE_URL]: 30,
[VMSettingsField.START_VM]: 31,
[VMSettingsField.TEMPLATE_SUPPORTED]: 20,
[VMSettingsField.DESCRIPTION]: 21,
[VMSettingsField.OPERATING_SYSTEM]: 22,
[VMSettingsField.CLONE_COMMON_BASE_DISK_IMAGE]: 23,
[VMSettingsField.MOUNT_WINDOWS_GUEST_TOOLS]: 24,
[VMSettingsField.FLAVOR]: 25,
[VMSettingsField.MEMORY]: 26,
[VMSettingsField.CPU]: 27,
[VMSettingsField.WORKLOAD_PROFILE]: 28,
[VMSettingsField.PROVISION_SOURCE_TYPE]: 29,
[VMSettingsField.CONTAINER_IMAGE]: 30,
[VMSettingsField.IMAGE_URL]: 31,
[VMSettingsField.START_VM]: 32,
};

const idResolver: RenderableFieldResolver = {
Expand Down Expand Up @@ -79,6 +80,7 @@ const idResolver: RenderableFieldResolver = {
[VMSettingsField.IMAGE_URL]: 'provision-source-url',
[VMSettingsField.START_VM]: 'start-vm',
[VMSettingsField.TEMPLATE_PROVIDER]: 'template-provider',
[VMSettingsField.TEMPLATE_SUPPORTED]: 'template-supported',
};

export const getFieldId = (key: RenderableField) => idResolver[key];
Expand Down
Expand Up @@ -38,6 +38,7 @@ export type BootSourceState = {
storageClass: { value: string };
accessMode: { value: string };
accessModes: { value: string[] };
provider?: { value: string };
};

export enum BOOT_ACTION_TYPE {
Expand All @@ -54,6 +55,7 @@ export enum BOOT_ACTION_TYPE {
SET_STORAGE_CLASS = 'storageClass',
SET_ACCESS_MODES = 'accessModes',
SET_ACCESS_MODE = 'accessMode',
SET_PROVIDER = 'provider',
}

export type BootSourceAction =
Expand All @@ -69,7 +71,8 @@ export type BootSourceAction =
| { type: BOOT_ACTION_TYPE.SET_PVC_SIZE; payload: BootSourceState['pvcSize']['value'] }
| { type: BOOT_ACTION_TYPE.SET_STORAGE_CLASS; payload: BootSourceState['storageClass']['value'] }
| { type: BOOT_ACTION_TYPE.SET_ACCESS_MODES; payload: BootSourceState['accessModes']['value'] }
| { type: BOOT_ACTION_TYPE.SET_ACCESS_MODE; payload: BootSourceState['accessMode']['value'] };
| { type: BOOT_ACTION_TYPE.SET_ACCESS_MODE; payload: BootSourceState['accessMode']['value'] }
| { type: BOOT_ACTION_TYPE.SET_PROVIDER; payload: BootSourceState['provider']['value'] };

export const initBootFormState: BootSourceState = {
dataSource: undefined,
Expand All @@ -91,6 +94,7 @@ export const initBootFormState: BootSourceState = {
storageClass: undefined,
accessMode: { value: AccessMode.READ_WRITE_ONCE.getValue() },
accessModes: { value: [AccessMode.READ_WRITE_ONCE.getValue()] },
provider: undefined,
};

export const bootFormReducer = (
Expand Down
Expand Up @@ -231,7 +231,7 @@ export const BootSourceForm: React.FC<BootSourceFormProps> = ({ state, dispatch,
/>
</FormRow>
{[
DataVolumeSourceType.PVC,
DataVolumeSourceType.UPLOAD,
DataVolumeSourceType.HTTP,
DataVolumeSourceType.REGISTRY,
].includes(DataVolumeSourceType.fromString(state.dataSource?.value)) && (
Expand All @@ -258,6 +258,19 @@ export const BootSourceForm: React.FC<BootSourceFormProps> = ({ state, dispatch,
</RequestSizeInput>
</FormRow>
)}
{withUpload && (
<FormRow fieldId="form-ds-provider" title="Source provider">
<TextInput
value={state.provider?.value}
type="text"
onChange={(payload) => dispatch({ type: BOOT_ACTION_TYPE.SET_PROVIDER, payload })}
aria-label="Source provider"
/>
<div className="pf-c-form__helper-text" aria-live="polite">
Example: your company name
</div>
</FormRow>
)}
<ExpandableSection toggleText="Advanced">
<FormRow fieldId="form-ds-sc" title="Storage class" isRequired>
<FormSelect
Expand Down
Expand Up @@ -49,7 +49,7 @@ import {
import { TemplateItem } from '../../../types/template';
import { isTemplateSourceError, TemplateSourceStatus } from '../../../statuses/template/types';
import { usePinnedTemplates } from '../../../hooks/use-pinned-templates';
import { BOOT_SOURCE_COMMUNITY, BOOT_SOURCE_USER, BOOT_SOURCE_REQUIRED } from '../../../constants';
import { BOOT_SOURCE_AVAILABLE, BOOT_SOURCE_REQUIRED } from '../../../constants';
import { FormPFSelect } from '../../form/form-pf-select';
import { VMTemplateSupport } from '../../vm-templates/vm-template';

Expand Down Expand Up @@ -342,8 +342,7 @@ export const SelectTemplate: React.FC<SelectTemplateProps> = ({
}
className="kv-select-template__filter"
>
<SelectOption value={BOOT_SOURCE_COMMUNITY} />
<SelectOption value={BOOT_SOURCE_USER} />
<SelectOption value={BOOT_SOURCE_AVAILABLE} />
<SelectOption value={BOOT_SOURCE_REQUIRED} />
</FormPFSelect>
</ToolbarFilter>
Expand Down
Expand Up @@ -97,6 +97,7 @@ export const AddTemplateSourceModal: React.FC<ModalComponentProps &
url: state.url?.value,
dataSource: state.dataSource?.value,
storageClass: state.storageClass?.value,
provider: state.provider?.value,
})
.setNamespace(baseImageNamespace)
.asResource();
Expand Down
Expand Up @@ -2,11 +2,22 @@ import * as React from 'react';
import { TemplateKind } from '@console/internal/module/k8s';
import { Label } from '@patternfly/react-core';

import { isTemplateSupported } from '../../selectors/vm-template/basic';
import {
getTemplateSupport,
getTemplateProvider,
isCommonTemplate,
} from '../../selectors/vm-template/basic';

type VMTemplateLabelProps = {
template: TemplateKind;
};

export const VMTemplateLabel: React.FC<VMTemplateLabelProps> = ({ template }) =>
isTemplateSupported(template) && <Label color="green">Red Hat supported</Label>;
export const VMTemplateLabel: React.FC<VMTemplateLabelProps> = ({ template }) => {
const supportLevel = getTemplateSupport(template);
const provider = getTemplateProvider(template);
return (
!!supportLevel && (
<Label color={isCommonTemplate(template) ? 'green' : 'blue'}>{provider} supported</Label>
)
);
};

0 comments on commit 46a17ff

Please sign in to comment.