Skip to content

Commit

Permalink
Fixed environment info for env, select branch env
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Nov 8, 2024
1 parent 9c67210 commit dc43940
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 62 deletions.
92 changes: 50 additions & 42 deletions src/components/create-job-form/pipeline-form-build-branches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
Typography,
} from '@equinor/eds-core-react';
import { type ChangeEvent, type FormEvent, useState } from 'react';
import { pollingInterval } from '../../store/defaults';
import {
useGetEnvironmentSummaryQuery,
useTriggerPipelineBuildDeployMutation,
useTriggerPipelineBuildMutation,
} from '../../store/radix-api';
Expand All @@ -28,10 +26,6 @@ export function PipelineFormBuildBranches({
const [triggerBuild, buildState] = useTriggerPipelineBuildMutation();
const [triggerBuildDeploy, buildDeployState] =
useTriggerPipelineBuildDeployMutation();
const { data: environments } = useGetEnvironmentSummaryQuery(
{ appName },
{ pollingInterval }
);

const state = pipelineName === 'build-deploy' ? buildDeployState : buildState;

Expand Down Expand Up @@ -108,46 +102,60 @@ export function PipelineFormBuildBranches({
</option>
))}
</NativeSelect>
<div className="grid grid--gap-small input">
<Typography
group="input"
variant="text"
token={{ color: 'currentColor' }}
>
Environment (optional)
</Typography>
<NativeSelect
id="ToEnvironmentSelect"
label=""
name="toEnvironment"
onChange={(e) => setToEnvironment(e.target.value)}
value={toEnvironment}
>
<option value="">— Please select —</option>
{environments?.map(({ name }, i) => (
<option key={i} value={name}>
{name}
</option>
))}
</NativeSelect>
</div>
{isAnyValidRegex(selectedBranch) && (
<fieldset>
<TextField
id="branch_full_name_field"
label="Branch full name"
helperText={`Pattern: ${selectedBranch}`}
name="branchFullName"
value={branchFullName}
onChange={handleOnTextChange}
/>
</fieldset>
<>
<Typography
group="input"
variant="text"
token={{ color: 'currentColor' }}
>
Git branch full name
</Typography>
<fieldset>
<TextField
id="branch_full_name_field"
helperText={`Pattern: ${selectedBranch}`}
name="branchFullName"
value={branchFullName}
onChange={handleOnTextChange}
/>
</fieldset>
</>
)}
{selectedBranch && branches[selectedBranch]?.length > 1 && (
<div className="grid grid--gap-small input">
<Typography
group="input"
variant="text"
token={{ color: 'currentColor' }}
>
Environment (optional)
</Typography>
<NativeSelect
id="ToEnvironmentSelect"
label=""
name="toEnvironment"
onChange={(e) => setToEnvironment(e.target.value)}
value={toEnvironment}
>
<option value="">
All environments build from the branch{' '}
{branch ?? selectedBranch}
</option>
{branches[selectedBranch]?.map((envName) => (
<option key={envName} value={envName}>
{envName}
</option>
))}
</NativeSelect>
</div>
)}
{pipelineName === 'build-deploy' && (
{pipelineName === 'build-deploy' && branches && selectedBranch && (
<TargetEnvs
branches={branches}
targetEnvs={
toEnvironment ? [toEnvironment] : branches[selectedBranch]
}
branch={branch}
selectedBranch={selectedBranch}
/>
)}
</div>
Expand Down
6 changes: 2 additions & 4 deletions src/components/create-job-form/target-envs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { Typography } from '@equinor/eds-core-react';
import { Fragment } from 'react';

type Props = {
selectedBranch?: string;
branches: Record<string, Array<string>>;
targetEnvs: Array<string>;
branch?: string;
};
export function TargetEnvs({ selectedBranch, branches, branch }: Props) {
const targetEnvs = branches[selectedBranch] || [];
export function TargetEnvs({ targetEnvs, branch }: Props) {
const penultimateId = targetEnvs.length - 2;

return targetEnvs.length > 0 ? (
Expand Down
39 changes: 24 additions & 15 deletions src/components/job-overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ export const JobOverview = ({ appName, jobName }: Props) => {
</Typography>
</Typography>
)}
{job.branch && (
<div>
<Typography>
Branch <strong>{job.branch}</strong>
</Typography>
</div>
)}
{job.deployedToEnvironment && (
<div>
<Typography>
Environment{' '}
<Typography
as={Link}
to={routeWithParams(routes.appEnvironment, {
appName,
envName: job.deployedToEnvironment,
})}
link
>
{job.deployedToEnvironment}
</Typography>
</Typography>
</div>
)}
<Typography>
Triggered by <strong>{job.triggeredBy || 'N/A'}</strong>
{job.commitID && (
Expand Down Expand Up @@ -315,21 +339,6 @@ export const JobOverview = ({ appName, jobName }: Props) => {
</Typography>
</Typography>
))}
{job.branch && (
<div>
<Typography>
Branch <strong>{job.branch}</strong>
</Typography>
</div>
)}
{job.deployedToEnvironment && (
<div>
<Typography>
Environment{' '}
<strong>{job.deployedToEnvironment}</strong>
</Typography>
</div>
)}
{job.components && (
<ComponentList
appName={appName}
Expand Down
2 changes: 1 addition & 1 deletion src/components/page-environment/environment-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const EnvironmentOverview: FunctionComponent<{
<Typography>
Environment <strong>{envName}</strong>
</Typography>
{environment.branchMapping ? (
{environment.branchMapping && environment.activeDeployment ? (
<Typography>
Built and deployed from{' '}
<Typography
Expand Down
2 changes: 2 additions & 0 deletions src/store/radix-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,8 @@ export type DeploymentSummary = {
activeFrom: string;
/** ActiveTo Timestamp when the deployment ends */
activeTo?: string;
/** Name of the branch used to build the deployment */
builtFromBranch?: string;
/** CommitID the commit ID of the branch to build */
commitID?: string;
/** Array of component summaries */
Expand Down

0 comments on commit dc43940

Please sign in to comment.