import styled from '@emotion/styled'; import {Button} from 'sentry/components/button'; import TextField from 'sentry/components/forms/fields/textField'; import PanelBody from 'sentry/components/panels/panelBody'; import PanelHeader from 'sentry/components/panels/panelHeader'; import {IconAdd, IconDelete} from 'sentry/icons'; import {t} from 'sentry/locale'; import {space} from 'sentry/styles/space'; type Props = { envVariables: { name: string; value: string; }[]; setEnvVariables: (envVariables) => void; }; function SentryFunctionEnvironmentVariables(props: Props) { const {envVariables, setEnvVariables} = props; const addEnvVar = () => { setEnvVariables([...envVariables, {name: '', value: ''}]); }; const handleNameChange = (value: string, pos: number) => { const newEnvVariables = [...envVariables]; while (newEnvVariables.length <= pos) { newEnvVariables.push({name: '', value: ''}); } newEnvVariables[pos] = {...newEnvVariables[pos], name: value}; setEnvVariables(newEnvVariables); }; const handleValueChange = (value: string, pos: number) => { const newEnvVariables = [...envVariables]; while (newEnvVariables.length <= pos) { newEnvVariables.push({name: '', value: ''}); } newEnvVariables[pos] = {...newEnvVariables[pos], value}; setEnvVariables(newEnvVariables); }; const removeEnvVar = (pos: number) => { const newEnvVariables = [...envVariables]; newEnvVariables.splice(pos, 1); setEnvVariables(newEnvVariables); }; return (
{t('Environment Variables')} } aria-label={t('Add Environment Variable')} onClick={addEnvVar} /> {t('Name')} {t('Value')} {envVariables.map((envVariable, i) => { return ( handleNameChange(e, i)} /> handleValueChange(e, i)} /> } aria-label={t('Remove Environment Variable %s', i)} onClick={() => removeEnvVar(i)} /> ); })}
); } export default SentryFunctionEnvironmentVariables; const EnvironmentVariableWrapper = styled('div')` display: grid; grid-template-columns: 1fr 1.5fr min-content; `; const StyledAddButton = styled(Button)` float: right; `; const EnvHeader = styled('div')` text-align: left; margin-top: ${space(2)}; margin-bottom: ${space(1)}; color: ${p => p.theme.gray400}; `; const EnvHeaderRight = styled(EnvHeader)` margin-left: -${space(2)}; `; const ButtonHolder = styled('div')` align-items: center; display: flex; margin-bottom: ${space(2)}; `; const StyledPanelBody = styled(PanelBody)` padding: ${space(2)}; `;