import React from 'react'; import type { IPipeline, IPipelineTag } from '../../../domain'; import { HelpField } from '../../../help'; import type { IOverridableProps } from '../../../overrideRegistry'; import { overridableComponent } from '../../../overrideRegistry'; import type { IFormInputProps } from '../../../presentation'; import { createFakeReactSyntheticEvent, FormField, TextAreaInput, ValidationMessage } from '../../../presentation'; export interface IMetadataPageContentProps { pipeline: IPipeline; updatePipelineConfig: (changes: Partial) => void; } export interface ITagsInput extends IFormInputProps { value?: IPipelineTag[]; } function TagsInput({ name, onChange, value, validation }: ITagsInput) { const errors: string[] = (validation && (validation.messageNode as string[])) || []; const handleChange = (tag: IPipelineTag, index: number) => { const newTags = value.map((x, i) => (i === index ? tag : x)); onChange(createFakeReactSyntheticEvent({ name, value: newTags })); }; const handleDelete = (index: number) => { const newTags = value.filter((_x, i) => i !== index); onChange(createFakeReactSyntheticEvent({ name, value: newTags })); }; const handleAddPair = () => { const newTags = (value || []).concat({ name: '', value: '' }); onChange(createFakeReactSyntheticEvent({ name, value: newTags })); }; return (
{(value || []).map((tag, i) => ( {errors[i] && ( )} ))}
Name Value
handleChange({ name: e.target.value, value: tag.value }, i)} /> handleChange({ name: tag.name, value: e.target.value }, i)} />
); } export function MetadataPage(props: IMetadataPageContentProps) { const { pipeline, updatePipelineConfig } = props; return ( <> updatePipelineConfig({ description: e.target.value })} input={(inputProps) => ( )} /> updatePipelineConfig({ tags: e.target.value })} help={} input={(inputProps) => } /> ); } export const MetadataPageContent = overridableComponent< IMetadataPageContentProps & IOverridableProps, typeof MetadataPage >(MetadataPage, 'metadataPageContent');