Skip to content

Commit

Permalink
FI-2540: Make input label sizes consistent (#469)
Browse files Browse the repository at this point in the history
* remove text area input

* compose oauth input text fields

* fix labelling bug

* add tests

* adjust styles

* update packages

---------

Co-authored-by: Alyssa Wang <[email protected]>
  • Loading branch information
AlyssaWang and AlyssaWang authored Apr 24, 2024
1 parent 038d0e2 commit 1828405
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 126 deletions.
2 changes: 1 addition & 1 deletion client/src/components/App/__tests__/Page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { testSuites } from '~/components/App/__mocked_data__/mockData';
import Page from '../Page';

describe('The Page Component', () => {
test('sets page title on render', /* async */ () => {
it('sets page title on render', /* async */ () => {
const pageTitle = 'Inferno Test Suites';
const routes = [
{
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/InputsModal/FieldLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const FieldLabel: FC<FieldLabelProps> = ({ requirement, isMissingInput = false }
return (
<>
{isMissingInput && <RequiredInputWarning />}
{fieldLabelText}
{requiredLabel}
{`${fieldLabelText}${requiredLabel}`}
{lockedIcon}
</>
);
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/InputsModal/InputCheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
FormControl,
FormControlLabel,
FormGroup,
FormHelperText,
FormLabel,
ListItem,
Typography,
} from '@mui/material';
import { CheckboxValues, TestInput } from '~/models/testSuiteModels';
import FieldLabel from './FieldLabel';
Expand Down Expand Up @@ -107,7 +107,9 @@ const InputCheckboxGroup: FC<InputCheckboxGroupProps> = ({
<FieldLabel requirement={requirement} isMissingInput={isMissingInput} />
</FormLabel>
{requirement.description && (
<FormHelperText sx={{ mx: 0 }}>{requirement.description}</FormHelperText>
<Typography variant="subtitle1" className={classes.inputDescription}>
{requirement.description}
</Typography>
)}
<FormGroup aria-label={`${requirement.name}-checkboxes-group`}>
{requirement.options?.list_options?.map((option, i) => (
Expand Down
69 changes: 44 additions & 25 deletions client/src/components/InputsModal/InputOAuthCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { ReactJSXElement } from '@emotion/react/types/jsx-namespace';
import {
Card,
CardContent,
FormHelperText,
FormControl,
FormLabel,
Input,
InputLabel,
List,
ListItem,
TextField,
Typography,
} from '@mui/material';
import { OAuthCredentials, TestInput } from '~/models/testSuiteModels';
import FieldLabel from './FieldLabel';
Expand All @@ -24,6 +26,7 @@ export interface InputOAuthCredentialsProps {
export interface InputOAuthField {
name: string;
label?: string | ReactJSXElement;
description?: string; // currently empty
required?: boolean; // default behavior should be false
hide?: boolean; // default behavior should be false
locked?: boolean; // default behavior should be false
Expand Down Expand Up @@ -112,31 +115,45 @@ const InputOAuthCredentials: FC<InputOAuthCredentialsProps> = ({

return (
<ListItem disabled={field.locked} key={field.name}>
<TextField
<FormControl
component="fieldset"
id={`requirement${index}_input`}
disabled={requirement.locked}
required={field.required}
required={!requirement.optional}
error={getIsMissingInput(field)}
id={`requirement${index}_${field.name}`}
label={fieldLabel}
helperText={requirement.description}
value={oAuthCredentials[field.name as keyof OAuthCredentials]}
className={classes.inputField}
variant="standard"
color="secondary"
fullWidth
onBlur={(e) => {
if (e.currentTarget === e.target) {
setHasBeenModified({ ...hasBeenModified, [field.name]: true });
}
}}
onChange={(event) => {
const value = event.target.value;
oAuthCredentials[field.name as keyof OAuthCredentials] = value;
inputsMap.set(requirement.name, JSON.stringify(oAuthCredentials));
setInputsMap(new Map(inputsMap));
}}
InputLabelProps={{ shrink: true }}
/>
className={classes.inputField}
>
<FormLabel htmlFor={`requirement${index}_${field.name}`} className={classes.inputLabel}>
{fieldLabel}
</FormLabel>
{field.description && (
<Typography variant="subtitle1" className={classes.inputDescription}>
{field.description}
</Typography>
)}
<Input
disabled={requirement.locked}
required={field.required}
error={getIsMissingInput(field)}
id={`requirement${index}_${field.name}`}
value={oAuthCredentials[field.name as keyof OAuthCredentials]}
className={classes.inputField}
color="secondary"
fullWidth
onBlur={(e) => {
if (e.currentTarget === e.target) {
setHasBeenModified({ ...hasBeenModified, [field.name]: true });
}
}}
onChange={(event) => {
const value = event.target.value;
oAuthCredentials[field.name as keyof OAuthCredentials] = value;
inputsMap.set(requirement.name, JSON.stringify(oAuthCredentials));
setInputsMap(new Map(inputsMap));
}}
/>
</FormControl>
</ListItem>
);
};
Expand All @@ -153,7 +170,9 @@ const InputOAuthCredentials: FC<InputOAuthCredentialsProps> = ({
<FieldLabel requirement={requirement} />
</InputLabel>
{requirement.description && (
<FormHelperText sx={{ mx: 0 }}>{requirement.description}</FormHelperText>
<Typography variant="subtitle1" className={classes.inputDescription}>
{requirement.description}
</Typography>
)}
<List>{oAuthFields.map((field) => !field.hide && oAuthField(field))}</List>
</CardContent>
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/InputsModal/InputRadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, { FC, useEffect } from 'react';
import {
FormControl,
FormControlLabel,
FormHelperText,
FormLabel,
ListItem,
Radio,
RadioGroup,
Typography,
} from '@mui/material';
import { TestInput } from '~/models/testSuiteModels';
import FieldLabel from './FieldLabel';
Expand Down Expand Up @@ -60,7 +60,9 @@ const InputRadioGroup: FC<InputRadioGroupProps> = ({
<FieldLabel requirement={requirement} />
</FormLabel>
{requirement.description && (
<FormHelperText sx={{ mx: 0 }}>{requirement.description}</FormHelperText>
<Typography variant="subtitle1" className={classes.inputDescription}>
{requirement.description}
</Typography>
)}
<RadioGroup
row
Expand Down
56 changes: 0 additions & 56 deletions client/src/components/InputsModal/InputTextArea.tsx

This file was deleted.

62 changes: 37 additions & 25 deletions client/src/components/InputsModal/InputTextField.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { FC } from 'react';
import { ListItem, TextField } from '@mui/material';
import { FormControl, FormLabel, Input, ListItem, Typography } from '@mui/material';
import { TestInput } from '~/models/testSuiteModels';
import FieldLabel from './FieldLabel';
import useStyles from './styles';
import lightTheme from 'styles/theme';

export interface InputTextFieldProps {
requirement: TestInput;
Expand All @@ -26,33 +25,46 @@ const InputTextField: FC<InputTextFieldProps> = ({

return (
<ListItem>
<TextField
<FormControl
component="fieldset"
id={`requirement${index}_control`}
disabled={requirement.locked}
required={!requirement.optional}
error={isMissingInput}
id={`requirement${index}_input`}
className={classes.inputField}
variant="standard"
color="secondary"
fullWidth
label={<FieldLabel requirement={requirement} isMissingInput={isMissingInput} />}
helperText={requirement.description}
value={inputsMap.get(requirement.name)}
onBlur={(e) => {
if (e.currentTarget === e.target) {
setHasBeenModified(true);
}
}}
onChange={(event) => {
const value = event.target.value;
inputsMap.set(requirement.name, value);
setInputsMap(new Map(inputsMap));
}}
InputLabelProps={{ shrink: true }}
FormHelperTextProps={{
sx: { '&.Mui-disabled': { color: lightTheme.palette.common.grayDark } },
}}
/>
className={classes.inputField}
>
<FormLabel htmlFor={`requirement${index}_input`} className={classes.inputLabel}>
<FieldLabel requirement={requirement} isMissingInput={isMissingInput} />
</FormLabel>
{requirement.description && (
<Typography variant="subtitle1" className={classes.inputDescription}>
{requirement.description}
</Typography>
)}
<Input
disabled={requirement.locked}
required={!requirement.optional}
error={isMissingInput}
id={`requirement${index}_input`}
className={classes.inputField}
color="secondary"
fullWidth
multiline={requirement.type === 'textarea'}
rows={requirement.type === 'textarea' ? 4 : 1}
value={inputsMap.get(requirement.name)}
onBlur={(e) => {
if (e.currentTarget === e.target) {
setHasBeenModified(true);
}
}}
onChange={(event) => {
const value = event.target.value;
inputsMap.set(requirement.name, value);
setInputsMap(new Map(inputsMap));
}}
/>
</FormControl>
</ListItem>
);
};
Expand Down
11 changes: 0 additions & 11 deletions client/src/components/InputsModal/InputsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { OAuthCredentials, RunnableType, TestInput } from '~/models/testSuiteMod
import InputOAuthCredentials from './InputOAuthCredentials';
import InputCheckboxGroup from './InputCheckboxGroup';
import InputRadioGroup from './InputRadioGroup';
import InputTextArea from './InputTextArea';
import InputTextField from './InputTextField';
import CustomTooltip from '../_common/CustomTooltip';
import useStyles from './styles';
Expand Down Expand Up @@ -155,16 +154,6 @@ const InputsModal: FC<InputsModalProps> = ({
key={`input-${index}`}
/>
);
case 'textarea':
return (
<InputTextArea
requirement={requirement}
index={index}
inputsMap={inputsMap}
setInputsMap={(newInputsMap) => handleSetInputsMap(newInputsMap)}
key={`input-${index}`}
/>
);
default:
return (
<InputTextField
Expand Down
Loading

0 comments on commit 1828405

Please sign in to comment.