Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@patternfly/react-core';
import { OpenDrawerRightIcon } from '@patternfly/react-icons';
import { UpdateObjectAtPropAndValue } from 'mod-arch-shared';
import { useThemeContext } from 'mod-arch-kubeflow';
import FormFieldset from '~/app/pages/modelRegistry/screens/components/FormFieldset';
import FormSection from '~/app/pages/modelRegistry/components/pf-overrides/FormSection';
import { ManageSourceFormData } from '~/app/pages/modelCatalogSettings/useManageSourceData';
Expand All @@ -33,6 +34,7 @@ const YamlSection: React.FC<YamlSectionProps> = ({
setData,
onToggleExpectedFormatDrawer,
}) => {
const { isMUITheme } = useThemeContext();
const [isYamlTouched, setIsYamlTouched] = React.useState(false);
const [filename, setFilename] = React.useState('');
const isYamlContentValid = validateYamlContent(formData.yamlContent);
Expand Down Expand Up @@ -83,6 +85,60 @@ const YamlSection: React.FC<YamlSectionProps> = ({
</div>
);

const expectedFormatButton = onToggleExpectedFormatDrawer ? (
<Button
variant="link"
isInline
onClick={onToggleExpectedFormatDrawer}
data-testid="view-expected-yaml-format-link"
icon={<OpenDrawerRightIcon />}
iconPosition="end"
>
{EXPECTED_YAML_FORMAT_LABEL}
</Button>
) : null;

const descriptionTextNode = (
<FormHelperText>
<HelperText>
<HelperTextItem>{HELP_TEXT.YAML}</HelperTextItem>
</HelperText>
</FormHelperText>
);

const hasError = isYamlTouched && !isYamlContentValid;
const helperTextNode = hasError ? (
<FormHelperText>
<HelperText>
<HelperTextItem variant="error" data-testid="yaml-content-error">
{VALIDATION_MESSAGES.YAML_CONTENT_REQUIRED}
</HelperTextItem>
</HelperText>
</FormHelperText>
) : undefined;

if (isMUITheme) {
return (
<FormSection data-testid="yaml-section">
{expectedFormatButton && (
<Flex justifyContent={{ default: 'justifyContentFlexEnd' }}>
<FlexItem>{expectedFormatButton}</FlexItem>
</Flex>
)}
{descriptionTextNode}
<FormGroup
className={hasError ? 'pf-m-error' : undefined}
label={FORM_LABELS.YAML_CONTENT}
isRequired
fieldId="yaml-content"
>
<FormFieldset component={yamlInput} field={FORM_LABELS.YAML_CONTENT} />
</FormGroup>
{helperTextNode}
</FormSection>
);
}

return (
<FormSection data-testid="yaml-section">
<FormGroup
Expand All @@ -92,40 +148,15 @@ const YamlSection: React.FC<YamlSectionProps> = ({
alignItems={{ default: 'alignItemsCenter' }}
>
<FlexItem>{FORM_LABELS.YAML_CONTENT}</FlexItem>
{onToggleExpectedFormatDrawer && (
<FlexItem>
<Button
variant="link"
isInline
onClick={onToggleExpectedFormatDrawer}
data-testid="view-expected-yaml-format-link"
icon={<OpenDrawerRightIcon />}
iconPosition="end"
>
{EXPECTED_YAML_FORMAT_LABEL}
</Button>
</FlexItem>
)}
{expectedFormatButton && <FlexItem>{expectedFormatButton}</FlexItem>}
</Flex>
}
isRequired
fieldId="yaml-content"
>
<FormFieldset component={yamlInput} field="YAML" />
<FormHelperText>
<HelperText>
<HelperTextItem>{HELP_TEXT.YAML}</HelperTextItem>
</HelperText>
</FormHelperText>
{isYamlTouched && !isYamlContentValid && (
<FormHelperText>
<HelperText>
<HelperTextItem variant="error" data-testid="yaml-content-error">
{VALIDATION_MESSAGES.YAML_CONTENT_REQUIRED}
</HelperTextItem>
</HelperText>
</FormHelperText>
)}
{descriptionTextNode}
{helperTextNode}
</FormGroup>
</FormSection>
);
Expand Down
Loading