diff --git a/packages/bruno-app/src/components/EnvironmentVariablesTable/StyledWrapper.js b/packages/bruno-app/src/components/EnvironmentVariablesTable/StyledWrapper.js index f2e058c2f..dd6675165 100644 --- a/packages/bruno-app/src/components/EnvironmentVariablesTable/StyledWrapper.js +++ b/packages/bruno-app/src/components/EnvironmentVariablesTable/StyledWrapper.js @@ -15,6 +15,7 @@ const Wrapper = styled.div` overflow-y: auto; border-radius: 8px; border: solid 1px ${(props) => props.theme.border.border0}; + transition: height 75ms cubic-bezier(0,1.12,.84,.64); } table { diff --git a/packages/bruno-app/src/components/EnvironmentVariablesTable/index.js b/packages/bruno-app/src/components/EnvironmentVariablesTable/index.js index 7a88aefaa..6302d64a8 100644 --- a/packages/bruno-app/src/components/EnvironmentVariablesTable/index.js +++ b/packages/bruno-app/src/components/EnvironmentVariablesTable/index.js @@ -18,10 +18,11 @@ import { stripEnvVarUid } from 'utils/environments'; const MIN_H = 35 * 2; const MIN_COLUMN_WIDTH = 80; +const MIN_ROW_HEIGHT = 35; const TableRow = React.memo( - ({ children, item }) => ( - + ({ children, item, style, ...rest }) => ( + {children} ), @@ -56,7 +57,8 @@ const EnvironmentVariablesTable = ({ const hasDraftForThisEnv = draft?.environmentUid === environment.uid; - const [tableHeight, setTableHeight] = useState(MIN_H); + const rowCount = (environment.variables?.length || 0) + 1; + const [tableHeight, setTableHeight] = useState(rowCount * MIN_ROW_HEIGHT); // Use environment UID as part of tableId so each environment has its own column widths const tableId = `env-vars-table-${environment.uid}`; @@ -483,6 +485,7 @@ const EnvironmentVariablesTable = ({ )} - fixedItemHeight={35} computeItemKey={(virtualIndex, item) => `${environment.uid}-${item.index}`} itemContent={(virtualIndex, { variable, index: actualIndex }) => { const isLastRow = actualIndex === formik.values.length - 1; @@ -535,7 +537,7 @@ const EnvironmentVariablesTable = ({ id={`${actualIndex}.name`} name={`${actualIndex}.name`} value={variable.name} - placeholder={!variable.value || (typeof variable.value === 'string' && variable.value.trim() === '') ? 'Name' : ''} + placeholder={!variable.name || (typeof variable.name === 'string' && variable.name.trim() === '') ? 'Name' : ''} onChange={(e) => handleNameChange(actualIndex, e)} onFocus={() => handleRowFocus(variable.uid)} onBlur={() => { @@ -560,7 +562,7 @@ const EnvironmentVariablesTable = ({ collection={_collection} name={`${actualIndex}.value`} value={variable.value} - placeholder={isLastEmptyRow ? 'Value' : ''} + placeholder={variable.value == null || (typeof variable.value === 'string' && variable.value.trim() === '') ? 'Value' : ''} isSecret={variable.secret} readOnly={typeof variable.value !== 'string'} onChange={(newValue) => { @@ -570,6 +572,19 @@ const EnvironmentVariablesTable = ({ formik.setFieldValue(`${actualIndex}.ephemeral`, undefined, false); formik.setFieldValue(`${actualIndex}.persistedValue`, undefined, false); } + // Append a new empty row when editing value on the last row + if (isLastRow) { + setTimeout(() => { + formik.setFieldValue(formik.values.length, { + uid: uuid(), + name: '', + value: '', + type: 'text', + secret: false, + enabled: true + }, false); + }, 0); + } }} onSave={handleSave} /> @@ -610,6 +625,8 @@ const EnvironmentVariablesTable = ({ /> )} + {/* We should re-think of these buttons placement in component as we use TableVirtuoso which because of + these buttons renders at some transition: height 0.1s ease` */}