Skip to content

Add Environment Variables - Various improvements. #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Icon from '@mdi/react';
import Autocomplete from '@mui/material/Autocomplete';
import Box from '@mui/material/Box';
import Chip from '@mui/material/Chip';
import ListItem from '@mui/material/ListItem';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
Expand Down Expand Up @@ -69,6 +70,20 @@
[getOptions]
);

const loadAllOptions = async () => {
const response = await getOptions('');
const allOptions = [...response.qualitative_environments, ...response.quantitative_environments];

Check warning on line 75 in app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx#L73-L75

Added lines #L73 - L75 were not covered by tests

const sortedOptions = allOptions.sort((a, b) => a.name.localeCompare(b.name));
setOptions(sortedOptions);

Check warning on line 78 in app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx#L77-L78

Added lines #L77 - L78 were not covered by tests
};

// This function is a repeat of a function in another file for pluralising. It should be edited to an imported function. GridColumnDefinitionsUtils.tsx when PR goes through
const getFormattedUnit = (unit: string) => {

Check warning on line 82 in app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx#L82

Added line #L82 was not covered by tests
const unitSuffix = unit.endsWith('er') ? 's' : '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the second time we've seen this logic. I would suggest making it a standalone function.

I would add a new function next to the pluralize function in .../utils/Utils.tsx since it tackles a similar kind of issue.

return `${unit}${unitSuffix}`;

Check warning on line 84 in app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx#L84

Added line #L84 was not covered by tests
};

return (
<Autocomplete
id="environments-autocomplete"
Expand Down Expand Up @@ -119,7 +134,6 @@

if (reason === 'clear') {
setInputValue('');
setOptions([]);
return;
}

Expand All @@ -128,6 +142,9 @@
setOptions(() => newOptions);
});
}}
onFocus={() => {
loadAllOptions();

Check warning on line 146 in app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/observations/observations-table/configure-columns/components/environment/search/EnvironmentsSearchAutocomplete.tsx#L146

Added line #L146 was not covered by tests
}}
value={null} // The selected value is not displayed in the input field or tracked by this component
onChange={(_, value) => {
if (!value) {
Expand Down Expand Up @@ -157,8 +174,8 @@
: renderOption.environment_quantitative_id
}`}
data-testid="environments-autocomplete-option">
<Stack gap={0.75} mt={-0.25}>
<Box>
<Stack direction="row" alignItems="center" justifyContent="space-between" width="100%" gap={2}>
<Box flex={1}>
<Typography component="div" variant="body1" fontWeight={700}>
{renderOption.name}
</Typography>
Expand All @@ -176,6 +193,20 @@
{renderOption.description}
</Typography>
</Box>
{'environment_quantitative_id' in renderOption && renderOption.unit && (
<Chip
label={getFormattedUnit(renderOption.unit)}
size="small"
sx={{
bgcolor: 'grey.200',
color: 'text.secondary',
height: '24px',
borderRadius: '12px',
fontWeight: 500
// This font is not bold enough, but 600 value jumps to super bold and I gave up. Doesn't look right imo
}}
/>
)}
</Stack>
</ListItem>
);
Expand Down
Loading