import { Edit, Plus } from 'lucide-react'; import { useState } from 'react'; import { readFileAsText } from '@/portainer/services/fileUploadReact'; import { Button } from '@@/buttons'; import { TextTip } from '@@/Tip/TextTip'; import { FileUploadField } from '@@/form-components/FileUpload'; import { InputList } from '@@/form-components/InputList'; import { ArrayError, ItemProps } from '@@/form-components/InputList/InputList'; import { InputLabeled } from '@@/form-components/Input/InputLabeled'; import { FormError } from '../FormError'; import { type EnvVar, type Value } from './types'; import { parseDotEnvFile } from './utils'; export function SimpleMode({ value, onChange, onAdvancedModeClick, errors, }: { value: Value; onChange: (value: Value) => void; onAdvancedModeClick: () => void; errors?: ArrayError; }) { return ( <> Switch to advanced mode to copy & paste multiple variables
onChange([...value, ...add])} />
); } function Item({ item, onChange, disabled, error, readOnly, index, }: ItemProps) { return (
handleChange({ name: e.target.value })} disabled={disabled} readOnly={readOnly} placeholder="e.g. FOO" size="small" id={`env-name${index}`} /> handleChange({ value: e.target.value })} disabled={disabled} readOnly={readOnly} placeholder="e.g. bar" size="small" id={`env-value${index}`} />
{!!error && (
{Object.values(error)[0]}
)}
); function handleChange(partial: Partial) { onChange({ ...item, ...partial }); } } function FileEnv({ onChooseFile }: { onChooseFile: (file: Value) => void }) { const [file, setFile] = useState(null); const fileTooBig = file && file.size > 1024 * 1024; return ( <> {fileTooBig && ( File too large! Try uploading a file smaller than 1MB )} ); async function handleChange(file: File) { setFile(file); if (!file) { return; } const text = await readFileAsText(file); if (!text) { return; } const parsed = parseDotEnvFile(text); onChooseFile(parsed); } }