Skip to content

Commit

Permalink
fix replica possibly being undefined before use
Browse files Browse the repository at this point in the history
  • Loading branch information
Pespiri committed Dec 7, 2023
1 parent 2816397 commit 44f2426
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 83 deletions.
115 changes: 60 additions & 55 deletions src/components/page-scheduled-job/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,63 +193,68 @@ export const PageScheduledJob: FunctionComponent<PageScheduledJobProps> = ({
<AsyncResource asyncState={scheduledJobState}>
{job && (
<>
<Replica
logState={pollLogsState}
replica={replica}
downloadCb={downloadLazyLogCb(
`${replica.name}.txt`,
getLog,
{
appName,
envName,
jobComponentName,
scheduledJobName,
file: 'true',
},
false
)}
title={
<>
<Typography>
Name{' '}
<strong>{smallScheduledJobName(scheduledJobName)}</strong>
</Typography>
{job.jobId && (
{replica && (
<Replica
logState={pollLogsState}
replica={replica}
downloadCb={downloadLazyLogCb(
`${replica.name}.txt`,
getLog,
{
appName,
envName,
jobComponentName,
scheduledJobName,
file: 'true',
},
false
)}
title={
<>
<Typography>
Job ID <strong>{job.jobId}</strong>
Name{' '}
<strong>{smallScheduledJobName(scheduledJobName)}</strong>
</Typography>
)}
<Typography>
Job <strong>{jobComponentName}</strong>
</Typography>
</>
}
duration={<ScheduleJobDuration job={job} />}
status={<ProgressStatusBadge status={job.status} />}
state={
<ScheduledJobState
{...{ ...job, replicaList: sortedReplicas }}
/>
}
resources={
<>
<ReplicaResources resources={job.resources} />
<Typography>
Backoff Limit <strong>{job.backoffLimit}</strong>
</Typography>
<Typography>
Time Limit{' '}
<strong>
{!isNullOrUndefined(job.timeLimitSeconds) ? (
<Duration start={0} end={job.timeLimitSeconds * 1000} />
) : (
'Not set'
)}
</strong>
</Typography>
</>
}
/>
{job.jobId && (
<Typography>
Job ID <strong>{job.jobId}</strong>
</Typography>
)}
<Typography>
Job <strong>{jobComponentName}</strong>
</Typography>
</>
}
duration={<ScheduleJobDuration job={job} />}
status={<ProgressStatusBadge status={job.status} />}
state={
<ScheduledJobState
{...{ ...job, replicaList: sortedReplicas }}
/>
}
resources={
<>
<ReplicaResources resources={job.resources} />
<Typography>
Backoff Limit <strong>{job.backoffLimit}</strong>
</Typography>
<Typography>
Time Limit{' '}
<strong>
{!isNullOrUndefined(job.timeLimitSeconds) ? (
<Duration
start={0}
end={job.timeLimitSeconds * 1000}
/>
) : (
'Not set'
)}
</strong>
</Typography>
</>
}
/>
)}

{(job.failedCount > 0 || pollJobLogFailed) && (
<JobReplicaLogAccordion
Expand Down
50 changes: 22 additions & 28 deletions src/components/replica/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ReplicaElements {
}

export interface ReplicaProps extends ReplicaElements {
replica?: ReplicaSummaryNormalizedModel;
replica: ReplicaSummaryNormalizedModel;
logState?: FetchQueryResult<string>;
isCollapsibleOverview?: boolean;
isCollapsibleLog?: boolean;
Expand Down Expand Up @@ -107,41 +107,36 @@ const Overview: FunctionComponent<
<section className="grid grid--gap-medium overview">
<div className="grid grid--gap-medium grid--overview-columns">
<div className="grid grid--gap-medium">
{title ||
(replica && (
<Typography>
Replica <strong>{smallReplicaName(replica.name)}</strong>
</Typography>
))}
{title || (
<Typography>
Replica <strong>{smallReplicaName(replica.name)}</strong>
</Typography>
)}
<ReplicaImage replica={replica} />
{status ||
(replica && <ReplicaStatusBadge status={replica.status} />)}
{status || <ReplicaStatusBadge status={replica.status} />}
</div>
<div className="grid grid--gap-medium">
{duration ||
(replica && (
<>
<ReplicaDuration created={replica.created} />
{replica.containerStarted && (
<ContainerDuration started={replica.containerStarted} />
)}
</>
))}
{duration || (
<>
<ReplicaDuration created={replica.created} />
{replica.containerStarted && (
<ContainerDuration started={replica.containerStarted} />
)}
</>
)}
</div>
<div className="grid grid--gap-medium">
{resources ||
(replica && <ReplicaResources resources={replica.resources} />)}
{resources || <ReplicaResources resources={replica.resources} />}
</div>
</div>
</section>
<section className="grid grid--gap-medium">
{state || (replica && <ReplicaState {...replica} />)}
{state || <ReplicaState {...replica} />}
</section>
</>
);

export const Replica: FunctionComponent<ReplicaProps> = ({
replica,
logState,
isCollapsibleOverview,
isCollapsibleLog,
Expand All @@ -160,20 +155,20 @@ export const Replica: FunctionComponent<ReplicaProps> = ({
</Accordion.HeaderTitle>
</Accordion.Header>
<Accordion.Panel>
<Overview replica={replica} {...rest} />
<Overview {...rest} />
</Accordion.Panel>
</Accordion.Item>
</Accordion>
) : (
<>
<Typography variant="h4">Overview</Typography>
<Overview replica={replica} {...rest} />
<Overview {...rest} />
</>
)}

<section>
<AsyncResource asyncState={logState} errorContent={'No log or replica'}>
{replica && logState.data ? (
{logState.data ? (
isCollapsibleLog ? (
<Accordion className="accordion elevated" chevronPosition="right">
<Accordion.Item isExpanded>
Expand Down Expand Up @@ -211,9 +206,8 @@ export const Replica: FunctionComponent<ReplicaProps> = ({
);

Replica.propTypes = {
replica: PropTypes.shape(
ReplicaSummaryNormalizedModelValidationMap
) as PropTypes.Validator<ReplicaSummaryNormalizedModel>,
replica: PropTypes.shape(ReplicaSummaryNormalizedModelValidationMap)
.isRequired as PropTypes.Validator<ReplicaSummaryNormalizedModel>,
logState: PropTypes.object as PropTypes.Validator<FetchQueryResult<string>>,
isCollapsibleOverview: PropTypes.bool,
isCollapsibleLog: PropTypes.bool,
Expand Down

0 comments on commit 44f2426

Please sign in to comment.