Merge pull request #1601 from github/koesie10/completed-status
Add display of duration and completion status
This commit is contained in:
@@ -24,3 +24,16 @@ export function formatDate(value: Date): string {
|
||||
|
||||
return dateFormatter.format(value);
|
||||
}
|
||||
|
||||
// These are overloads for the function that allow us to not add an extra
|
||||
// type check when the value is definitely not undefined.
|
||||
export function parseDate(value: string): Date;
|
||||
export function parseDate(value: string | undefined | null): Date | undefined;
|
||||
|
||||
export function parseDate(value: string | undefined | null): Date | undefined {
|
||||
if (value === undefined || value === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return new Date(value);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ export interface VariantAnalysis {
|
||||
actor_id: number,
|
||||
query_language: VariantAnalysisQueryLanguage,
|
||||
query_pack_url: string,
|
||||
created_at: string,
|
||||
updated_at: string,
|
||||
status: VariantAnalysisStatus,
|
||||
completed_at?: string,
|
||||
actions_workflow_run_id?: number,
|
||||
failure_reason?: VariantAnalysisFailureReason,
|
||||
scanned_repositories?: VariantAnalysisScannedRepository[],
|
||||
|
||||
@@ -15,8 +15,11 @@ export interface VariantAnalysis {
|
||||
repositoryLists?: string[],
|
||||
repositoryOwners?: string[],
|
||||
},
|
||||
createdAt: string,
|
||||
updatedAt: string,
|
||||
executionStartTime: number;
|
||||
status: VariantAnalysisStatus,
|
||||
completedAt?: string,
|
||||
actionsWorkflowRunId?: number,
|
||||
failureReason?: VariantAnalysisFailureReason,
|
||||
scannedRepos?: VariantAnalysisScannedRepository[],
|
||||
|
||||
@@ -56,7 +56,10 @@ export function processUpdatedVariantAnalysis(
|
||||
query: previousVariantAnalysis.query,
|
||||
databases: previousVariantAnalysis.databases,
|
||||
executionStartTime: previousVariantAnalysis.executionStartTime,
|
||||
createdAt: response.created_at,
|
||||
updatedAt: response.updated_at,
|
||||
status: processApiStatus(response.status),
|
||||
completedAt: response.completed_at,
|
||||
actionsWorkflowRunId: response.actions_workflow_run_id,
|
||||
scannedRepos: scannedRepos,
|
||||
skippedRepos: skippedRepos
|
||||
|
||||
@@ -10,13 +10,11 @@ import {
|
||||
import { QueryDetails } from './QueryDetails';
|
||||
import { VariantAnalysisActions } from './VariantAnalysisActions';
|
||||
import { VariantAnalysisStats } from './VariantAnalysisStats';
|
||||
import { parseDate } from '../../pure/date';
|
||||
|
||||
export type VariantAnalysisHeaderProps = {
|
||||
variantAnalysis: VariantAnalysis;
|
||||
|
||||
duration?: number | undefined;
|
||||
completedAt?: Date | undefined;
|
||||
|
||||
onOpenQueryFileClick: () => void;
|
||||
onViewQueryTextClick: () => void;
|
||||
|
||||
@@ -41,8 +39,6 @@ const Row = styled.div`
|
||||
|
||||
export const VariantAnalysisHeader = ({
|
||||
variantAnalysis,
|
||||
duration,
|
||||
completedAt,
|
||||
onOpenQueryFileClick,
|
||||
onViewQueryTextClick,
|
||||
onStopQueryClick,
|
||||
@@ -85,8 +81,8 @@ export const VariantAnalysisHeader = ({
|
||||
completedRepositoryCount={completedRepositoryCount}
|
||||
resultCount={resultCount}
|
||||
hasWarnings={hasSkippedRepos}
|
||||
duration={duration}
|
||||
completedAt={completedAt}
|
||||
createdAt={parseDate(variantAnalysis.createdAt)}
|
||||
completedAt={parseDate(variantAnalysis.completedAt)}
|
||||
onViewLogsClick={onViewLogsClick}
|
||||
/>
|
||||
</Container>
|
||||
|
||||
@@ -17,7 +17,7 @@ export type VariantAnalysisStatsProps = {
|
||||
hasWarnings?: boolean;
|
||||
|
||||
resultCount?: number | undefined;
|
||||
duration?: number | undefined;
|
||||
createdAt: Date;
|
||||
completedAt?: Date | undefined;
|
||||
|
||||
onViewLogsClick: () => void;
|
||||
@@ -35,7 +35,7 @@ export const VariantAnalysisStats = ({
|
||||
completedRepositoryCount = 0,
|
||||
hasWarnings,
|
||||
resultCount,
|
||||
duration,
|
||||
createdAt,
|
||||
completedAt,
|
||||
onViewLogsClick,
|
||||
}: VariantAnalysisStatsProps) => {
|
||||
@@ -59,6 +59,14 @@ export const VariantAnalysisStats = ({
|
||||
return 'Succeeded';
|
||||
}, [variantAnalysisStatus, hasWarnings]);
|
||||
|
||||
const duration = useMemo(() => {
|
||||
if (!completedAt) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return completedAt.getTime() - createdAt.getTime();
|
||||
}, [completedAt, createdAt]);
|
||||
|
||||
return (
|
||||
<Row>
|
||||
<StatItem title="Results">
|
||||
|
||||
@@ -21,6 +21,8 @@ describe(VariantAnalysisAnalyzedRepos.name, () => {
|
||||
},
|
||||
databases: {},
|
||||
executionStartTime: 1611234567890,
|
||||
createdAt: '2021-01-21T13:09:27.890Z',
|
||||
updatedAt: '2021-01-21T13:09:27.890Z',
|
||||
status: VariantAnalysisStatus.InProgress,
|
||||
scannedRepos: [
|
||||
{
|
||||
|
||||
@@ -20,6 +20,8 @@ describe(VariantAnalysisOutcomePanels.name, () => {
|
||||
},
|
||||
databases: {},
|
||||
executionStartTime: 1611234567890,
|
||||
createdAt: '2021-01-21T13:09:27.890Z',
|
||||
updatedAt: '2021-01-21T13:09:27.890Z',
|
||||
status: VariantAnalysisStatus.InProgress,
|
||||
scannedRepos: [
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ describe(VariantAnalysisStats.name, () => {
|
||||
variantAnalysisStatus={VariantAnalysisStatus.InProgress}
|
||||
totalRepositoryCount={10}
|
||||
onViewLogsClick={onViewLogsClick}
|
||||
createdAt={new Date()}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
@@ -31,6 +32,7 @@ describe(VariantAnalysisStats.name, () => {
|
||||
render({ resultCount: 123456 });
|
||||
|
||||
expect(screen.getByText('123,456')).toBeInTheDocument();
|
||||
expect(screen.queryAllByText('-').length).toBe(1);
|
||||
});
|
||||
|
||||
it('renders the number of repositories as a formatted number', () => {
|
||||
@@ -100,4 +102,30 @@ describe(VariantAnalysisStats.name, () => {
|
||||
expect(screen.getByText('Succeeded')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Succeeded warnings')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render the duration when the completedAt is not set', () => {
|
||||
render({ createdAt: new Date('2021-05-01T00:00:00Z') });
|
||||
|
||||
expect(screen.queryAllByText('-').length).toBe(2);
|
||||
expect(screen.queryByText('Less than a second')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the duration when it is less than a second', () => {
|
||||
render({ createdAt: new Date('2021-05-01T00:00:00Z'), completedAt: new Date('2021-05-01T00:00:00Z') });
|
||||
|
||||
expect(screen.getByText('Less than a second')).toBeInTheDocument();
|
||||
expect(screen.queryAllByText('-').length).toBe(1);
|
||||
});
|
||||
|
||||
it('renders the duration when it is less than a minute', () => {
|
||||
render({ createdAt: new Date('2021-05-01T00:00:00Z'), completedAt: new Date('2021-05-01T00:00:34Z') });
|
||||
|
||||
expect(screen.getByText('34 seconds')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders the duration when it is more than a minute', () => {
|
||||
render({ createdAt: new Date('2021-05-01T00:00:00Z'), completedAt: new Date('2021-05-01T00:10:22Z') });
|
||||
|
||||
expect(screen.getByText('10 minutes')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,7 +37,10 @@ describe('Variant Analysis processor', function() {
|
||||
'repositories': ['1', '2', '3'],
|
||||
},
|
||||
'executionStartTime': mockSubmission.startTime,
|
||||
'createdAt': mockApiResponse.created_at,
|
||||
'updatedAt': mockApiResponse.updated_at,
|
||||
'status': 'succeeded',
|
||||
'completedAt': mockApiResponse.completed_at,
|
||||
'actionsWorkflowRunId': mockApiResponse.actions_workflow_run_id,
|
||||
'scannedRepos': [
|
||||
transformScannedRepo(VariantAnalysisRepoStatus.Succeeded, scannedRepos[0]),
|
||||
|
||||
@@ -28,6 +28,8 @@ export function createMockApiResponse(
|
||||
actor_id: faker.datatype.number(),
|
||||
query_language: VariantAnalysisQueryLanguage.Javascript,
|
||||
query_pack_url: 'https://example.com/foo',
|
||||
created_at: faker.date.recent().toISOString(),
|
||||
updated_at: faker.date.recent().toISOString(),
|
||||
status: status,
|
||||
actions_workflow_run_id: faker.datatype.number(),
|
||||
scanned_repositories: scannedRepos,
|
||||
|
||||
@@ -27,6 +27,8 @@ export function createMockVariantAnalysis(
|
||||
repositories: ['1', '2', '3'],
|
||||
},
|
||||
executionStartTime: faker.datatype.number(),
|
||||
createdAt: faker.date.recent().toISOString(),
|
||||
updatedAt: faker.date.recent().toISOString(),
|
||||
status: status,
|
||||
actionsWorkflowRunId: faker.datatype.number(),
|
||||
scannedRepos: scannedRepos,
|
||||
|
||||
Reference in New Issue
Block a user