Skip to content

Commit

Permalink
Add search (Autocomplete) in create pipelines (#1368)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Feature

### Detail
Autocomplete for environments and teams in the following frontend views
as requested in #1012.
This PR implements it for createPipelines

### Relates
- #1012 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
dlpzx authored Jun 27, 2024
1 parent 6c909a3 commit 976ec6b
Showing 1 changed file with 9 additions and 119 deletions.
128 changes: 9 additions & 119 deletions frontend/src/modules/Pipelines/views/PipelineCreateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ import {
useSettings
} from 'design';
import { SET_ERROR, useDispatch } from 'globalErrors';
import {
listEnvironmentGroups,
listValidEnvironments,
useClient
} from 'services';
import { listValidEnvironments, useClient } from 'services';
import { createDataPipeline } from '../services';
import { PipelineEnvironmentCreateForm } from '../components';
import { EnvironmentTeamDropdown } from 'modules/Shared';

const PipelineCreateForm = (props) => {
const navigate = useNavigate();
Expand All @@ -44,7 +41,6 @@ const PipelineCreateForm = (props) => {
const client = useClient();
const { settings } = useSettings();
const [loading, setLoading] = useState(true);
const [groupOptions, setGroupOptions] = useState([]);
const [environmentOptions, setEnvironmentOptions] = useState([]);
const devOptions = [
{ value: 'cdk-trunk', label: 'CDK Pipelines - Trunk-based' },
Expand Down Expand Up @@ -78,29 +74,6 @@ const PipelineCreateForm = (props) => {
setLoading(false);
}, [client, dispatch]);

const fetchGroups = async (environmentUri) => {
try {
const response = await client.query(
listEnvironmentGroups({
filter: Defaults.selectListFilter,
environmentUri
})
);
if (!response.errors) {
setGroupOptions(
response.data.listEnvironmentGroups.nodes.map((g) => ({
value: g.groupUri,
label: g.groupUri
}))
);
} else {
dispatch({ type: SET_ERROR, error: response.errors[0].message });
}
} catch (e) {
dispatch({ type: SET_ERROR, error: e.message });
}
};

useEffect(() => {
if (client) {
fetchEnvironments().catch((e) =>
Expand Down Expand Up @@ -330,96 +303,13 @@ const PipelineCreateForm = (props) => {
<Grid item lg={5} md={6} xs={12}>
<Card sx={{ mb: 3 }}>
<CardHeader title="CICD" />
<CardContent>
<TextField
fullWidth
error={Boolean(
touched.environment && errors.environment
)}
helperText={
touched.environment && errors.environment
}
label="CICD Environment"
name="environment"
onChange={(event) => {
setFieldValue('SamlGroupName', '');
fetchGroups(
event.target.value.environmentUri
).catch((e) =>
dispatch({ type: SET_ERROR, error: e.message })
);
setFieldValue('environment', event.target.value);
}}
select
value={values.environment}
variant="outlined"
>
{environmentOptions.map((environment) => (
<MenuItem
key={environment.environmentUri}
value={environment}
>
{environment.label}
</MenuItem>
))}
</TextField>
</CardContent>
<CardContent>
<TextField
fullWidth
error={Boolean(
touched.SamlGroupName && errors.SamlGroupName
)}
helperText={
touched.SamlGroupName && errors.SamlGroupName
}
label="Team"
name="SamlGroupName"
onChange={(event) => {
setFieldValue(
'SamlGroupName',
event.target.value
);
}}
select
value={values.SamlGroupName}
variant="outlined"
>
{groupOptions.map((group) => (
<MenuItem key={group.value} value={group.value}>
{group.label}
</MenuItem>
))}
</TextField>
</CardContent>
<CardContent>
<TextField
disabled
fullWidth
label="Region"
name="region"
value={
values.environment
? values.environment.region
: ''
}
variant="outlined"
/>
</CardContent>
<CardContent>
<TextField
disabled
fullWidth
label="Organization"
name="organization"
value={
values.environment
? values.environment.organization.label
: ''
}
variant="outlined"
/>
</CardContent>
<EnvironmentTeamDropdown
setFieldValue={setFieldValue}
handleChange={handleChange}
values={values}
touched={touched}
errors={errors}
/>
<CardContent>
<TextField
fullWidth
Expand Down

0 comments on commit 976ec6b

Please sign in to comment.