Skip to content

Commit

Permalink
use NativeSelect for select dropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
Pespiri committed Aug 3, 2021
1 parent e8d0e28 commit fb2f90a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/components/create-job-form/pipeline-form-build-deploy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NativeSelect } from '@equinor/eds-core-react';
import PropTypes from 'prop-types';
import React from 'react';

Expand Down Expand Up @@ -52,14 +53,14 @@ export const PipelineFormBuildDeploy = ({ onChange, branch, branches }) => {

return (
<FormField label="Git branch to build">
<select value={branch} onChange={handleChange}>
<NativeSelect value={branch} onChange={handleChange}>
<option value="">— Please select —</option>
{Object.keys(branches).map((branch) => (
<option key={branch} value={branch}>
{branch}
</option>
))}
</select>
</NativeSelect>
{branch && (
<p>
<TargetEnvs branch={branch} branches={branches} />
Expand Down
5 changes: 3 additions & 2 deletions src/components/create-job-form/pipeline-form-build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NativeSelect } from '@equinor/eds-core-react';
import PropTypes from 'prop-types';
import React from 'react';

Expand All @@ -9,14 +10,14 @@ export const PipelineFormBuild = ({ onChange, branch, branches }) => {

return (
<FormField label="Git branch to build">
<select value={branch} onChange={handleChange}>
<NativeSelect value={branch} onChange={handleChange}>
<option value="">— Please select —</option>
{Object.keys(branches).map((branch) => (
<option key={branch} value={branch}>
{branch}
</option>
))}
</select>
</NativeSelect>
</FormField>
);
};
Expand Down
28 changes: 11 additions & 17 deletions src/components/create-job-form/pipeline-form-promote.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { NativeSelect } from '@equinor/eds-core-react';
import PropTypes from 'prop-types';
import React from 'react';

import EnvironmentBadge from '../environment-badge';
import FormField from '../form-field';
import RelativeToNow from '../time/relative-to-now';

import DeploymentSummaryModel from '../../models/deployment-summary';
import EnvironmentSummaryModel from '../../models/environment-summary';

import { smallDeploymentName } from '../../utils/string';
import { formatDateTime } from '../../utils/datetime';

import FormField from '../form-field';
import { smallDeploymentName } from '../../utils/string';

export const PipelineFormPromote = ({
onChange,
Expand All @@ -22,27 +20,23 @@ export const PipelineFormPromote = ({
const handleChange = (ev) => {
const newValue = ev.target.value;
const newState = { [ev.target.name]: newValue };
let isValid = false;
let isValid;

if (ev.target.name === 'toEnvironment') {
isValid = deploymentName && newValue;
} else {
isValid = toEnvironment && newValue;

// Account for having selected an environment first; if it is the target
// of the newly-selected deployment then we invalidate the form
const selectedEnv = environments.find((e) => e.name === toEnvironment);
if (
isValid =
selectedEnv &&
selectedEnv.activeDeployment &&
selectedEnv.activeDeployment.name === newValue
) {
isValid = false;
}
? false
: toEnvironment && newValue;

// When selecting a deployment to promote we need to add its environment
// to the state that is sent to the API (the "fromEnvironment" argument)

const selectedDeployment = deployments.find((d) => d.name === newValue);
newState.fromEnvironment = selectedDeployment.environment;
}
Expand Down Expand Up @@ -89,7 +83,7 @@ export const PipelineFormPromote = ({
return (
<React.Fragment>
<FormField help={getDeploymentHelp()} label="Deployment to promote">
<select
<NativeSelect
onChange={handleChange}
name="deploymentName"
value={deploymentName}
Expand All @@ -107,10 +101,10 @@ export const PipelineFormPromote = ({
))}
</optgroup>
))}
</select>
</NativeSelect>
</FormField>
<FormField label="Target environment">
<select
<NativeSelect
name="toEnvironment"
onChange={handleChange}
value={toEnvironment}
Expand All @@ -128,7 +122,7 @@ export const PipelineFormPromote = ({
{env.name}
</option>
))}
</select>
</NativeSelect>
</FormField>
</React.Fragment>
);
Expand Down

0 comments on commit fb2f90a

Please sign in to comment.