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 } from '@@/form-components/InputList/InputList'; import type { Values } from './types'; import { parseDotEnvFile } from './utils'; import { EnvironmentVariableItem } from './EnvironmentVariableItem'; export function SimpleMode({ value, onChange, onAdvancedModeClick, errors, canUndoDelete, }: { value: Values; onChange: (value: Values) => void; onAdvancedModeClick: () => void; errors?: ArrayError; canUndoDelete?: boolean; }) { return ( <> Switch to advanced mode to copy & paste multiple variables
onChange([...value, ...add])} />
); } function FileEnv({ onChooseFile }: { onChooseFile: (file: Values) => 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); } }