import React from 'react'; import PropTypes from 'prop-types'; import { Title, Text, TextVariants, Form, Alert } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; import { SelectField } from '../form/SelectField'; import { GroupedSelectField } from '../form/GroupedSelectField'; export const CategoryAndTemplate = ({ jobCategories, jobTemplates, setJobTemplate, selectedTemplateID, selectedCategory, setCategory, errors, }) => { const templatesGroups = {}; jobTemplates.forEach(template => { if (templatesGroups[template.provider_type]?.options) templatesGroups[template.provider_type].options.push({ label: template.name, value: template.id, }); else templatesGroups[template.provider_type] = { options: [{ label: template.name, value: template.id }], groupLabel: template.provider_type, }; }); const selectedTemplate = jobTemplates.find( template => template.id === selectedTemplateID )?.name; const onSelectCategory = newCategory => { setCategory(newCategory); setJobTemplate(null); }; const { categoryError, allTemplatesError, templateError } = errors; const isError = !!(categoryError || allTemplatesError || templateError); return ( <>