Skip to content

Commit

Permalink
TaskRun details Page
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Oct 8, 2020
1 parent d9e4d60 commit 4705e16
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.odc-taskrun-details {
&__status {
dl {
margin-bottom: var(--pf-global--spacer--md);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as React from 'react';
import { SectionHeading, ResourceSummary } from '@console/internal/components/utils';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { Status } from '@console/shared';
import { pipelineRunFilterReducer } from '../../utils/pipeline-filter-reducer';
import PipelineRunDetailsErrorLog from '../pipelineruns/logs/PipelineRunDetailsErrorLog';
import { TaskRunModel } from '../../models';
import './TaskRunDetails.scss';

export interface TaskRunDetailsProps {
obj: K8sResourceKind;
Expand All @@ -15,6 +19,15 @@ const TaskRunDetails: React.FC<TaskRunDetailsProps> = ({ obj: taskRun }) => {
<div className="col-sm-6">
<ResourceSummary resource={taskRun} />
</div>
<div className="col-sm-6 odc-taskrun-details__status">
<dl>
<dt>Status</dt>
<dd>
<Status status={pipelineRunFilterReducer(taskRun)} />
</dd>
</dl>
<PipelineRunDetailsErrorLog pipelineRun={taskRun} />
</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DetailsPage, DetailsPageProps } from '@console/internal/components/fact
import { navFactory, viewYamlComponent } from '@console/internal/components/utils';
import TaskRunDetails from './TaskRunDetails';
import { useTasksBreadcrumbsFor } from '../pipelines/hooks';
import TaskRunLog from './TaskRunLog';

const TaskRunDetailsPage: React.FC<DetailsPageProps> = (props) => {
const { kindObj, match } = props;
Expand All @@ -12,7 +13,16 @@ const TaskRunDetailsPage: React.FC<DetailsPageProps> = (props) => {
<DetailsPage
{...props}
breadcrumbsFor={() => breadcrumbsFor}
pages={[navFactory.details(TaskRunDetails), navFactory.editYaml(viewYamlComponent)]}
pages={[
navFactory.details(TaskRunDetails),
navFactory.editYaml(viewYamlComponent),
{
href: 'logs',
path: 'logs/:name?',
name: 'Logs',
component: TaskRunLog,
},
]}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import { useK8sGet } from '@console/internal/components/utils/k8s-get-hook';
import { K8sResourceKind } from '@console/internal/module/k8s';
import { PodLogs } from '@console/internal/components/pod-logs';
import { StatusBox } from '@console/internal/components/utils/status-box';
import { PodModel } from '@console/internal/models';

export type TaskRunLogProps = {
obj: K8sResourceKind;
};

const TaskRunLog: React.FC<TaskRunLogProps> = ({ obj }) => {
const [pod, podLoaded, podError] = useK8sGet<K8sResourceKind>(
PodModel,
obj.status.podName,
obj.metadata.namespace,
);
if (podLoaded && !podError) {
return <PodLogs obj={pod} />;
}
return <StatusBox loaded={podLoaded} loadError={podError} label="TaskRun Log" />;
};

// to safeguard against cases where Pod is yet to be assigned or is removed
const TaskRunLogWrapper = (props: TaskRunLogProps) =>
props.obj.status?.podName ? (
<TaskRunLog {...props} />
) : (
<StatusBox loadError="Pod not found" label="TaskRun Log" />
);

export default TaskRunLogWrapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';
import { SectionHeading, ResourceSummary } from '@console/internal/components/utils';
import { Status } from '@console/shared';
import PipelineRunDetailsErrorLog from '../../pipelineruns/logs/PipelineRunDetailsErrorLog';
import { shallow } from 'enzyme';
import TaskRunDetails from '../TaskRunDetails';

type Component = typeof TaskRunDetails;
type Props = React.ComponentProps<Component>;
const TaskDetailsProps: Props = {
obj: {
kind: 'TaskRun',
metadata: { name: 'abhi', namespace: 'abhi1' },
status: {
completionTime: '2019-10-29T11:57:53Z',
conditions: [
{
lastTransitionTime: '2019-10-29T11:57:53Z',
reason: 'Failed',
status: 'True',
type: 'Failed',
},
],
},
},
};

describe('TaskRunDetailsPage', () => {
const pipelineRunWrapper = shallow(<TaskRunDetails {...TaskDetailsProps} />);
it('Renders a SectionHeading', () => {
expect(pipelineRunWrapper.find(SectionHeading).exists());
});
it('Renders a Resource Summary', () => {
expect(pipelineRunWrapper.find(ResourceSummary).exists());
});
it('Renders a Status', () => {
expect(pipelineRunWrapper.find(Status).exists());
});
it('Renders a Log snippet', () => {
expect(pipelineRunWrapper.find(PipelineRunDetailsErrorLog).exists());
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import { PodLogs } from '@console/internal/components/pod-logs';
import { StatusBox } from '@console/internal/components/utils/status-box';
import { shallow } from 'enzyme';
import TaskRunLog from '../TaskRunLog';

type Component = typeof TaskRunLog;
type Props = React.ComponentProps<Component>;
const TaskRunLogProps: Props = {
obj: {
kind: 'TaskRun',
metadata: { name: 'abhi', namespace: 'abhi1' },
status: {
completionTime: '2019-10-29T11:57:53Z',
conditions: [
{
lastTransitionTime: '2019-10-29T11:57:53Z',
reason: 'Failed',
status: 'True',
type: 'Failed',
},
],
},
},
};

describe('TaskRunLog Page', () => {
it('Renders a StatusBox', () => {
const pipelineRunWrapper = shallow(<TaskRunLog {...TaskRunLogProps} />);
expect(pipelineRunWrapper.find(StatusBox).exists());
});
it('Renders a PodLog', () => {
TaskRunLogProps.obj.status.podName = 'test';
const pipelineRunWrapper = shallow(<TaskRunLog {...TaskRunLogProps} />);
expect(pipelineRunWrapper.find(PodLogs).exists());
});
});

0 comments on commit 4705e16

Please sign in to comment.