Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pipeline trigger resource pages and related links in details pages #5005

Merged
merged 1 commit into from Apr 16, 2020

Conversation

karthikjeeyar
Copy link
Contributor

@karthikjeeyar karthikjeeyar commented Apr 9, 2020

Fixes:- https://issues.redhat.com/browse/ODC-3427

Analysis / Root cause:
User should be able to traverse between the trigger resources quickly from the details page.

Solution Description:
Added custom pages for the trigger resources and added the links of the related resources.

screenshot:
pipeline-details-link

Pipeline Details
image

Trigger Template Details
image

Eventlistener-details
image

Unit test:
image

image

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

cc: @serenamarie125 @andrewballantyne

@karthikjeeyar
Copy link
Contributor Author

/kind feature

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 9, 2020
@karthikjeeyar
Copy link
Contributor Author

/assign @andrewballantyne

@@ -31,6 +37,22 @@ export const PipelineRunDetails: React.FC<PipelineRunDetailsProps> = ({ obj: pip
</dd>
</dl>
<br />
<dl>
<dt>Triggered by</dt>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, you overstepped your story. Please undo changes here. They'll not be adequate to cover the need. See my PR if you're curious how rough it was lol. There is a need to get the username and apply it to the PipelineRun (can't just use the current user at time of read).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this is the story that covers the Pipeline Run / Trigged By content: https://issues.redhat.com/browse/ODC-3323

@@ -57,4 +75,28 @@ describe('PipelineRun details page', () => {
.filter({ kind: referenceForModel(PipelineResourceModel) });
expect(resources).toHaveLength(0);
});

it('should return username when labels are not present in the pipeline run object', () => {
expect(wrapper.find('[data-test-id="triggered-by"]').text()).toBe('kube:admin');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naturally undo all of these as well.

Comment on lines 13 to 21
const { template, bindings } =
eventListener?.spec?.triggers?.reduce(
(res, trigger) => {
res.template.push(trigger.template.name);
trigger.bindings.map((b) => res.bindings.push(b.name));
return res;
},
{ ...resources },
) || resources;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { template, bindings } =
eventListener?.spec?.triggers?.reduce(
(res, trigger) => {
res.template.push(trigger.template.name);
trigger.bindings.map((b) => res.bindings.push(b.name));
return res;
},
{ ...resources },
) || resources;
const { template, bindings } =
(eventListener.spec.triggers || []).reduce(
(acc, trigger) => ({
bindings: [...acc.bindings, trigger.bindings],
template: [...acc.template, trigger.template],
}),
{ template: [], bindings: [] },
);

Rule of thumb is not to mutate outside resources during a .map or .reduce as they are intended to be as pure as possible. It's just easier for others to rationalize them out if you keep to these guidelines.

Also, EventListenerKind has spec.triggers as being a required path. So we either have an invalid type or unnecessary null-checks.

One last thing is that .reduce will return the default if the array is empty so this structure allows you not to need to do an extra ||.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated it.

import ResourceLinkList from '../resource-overview/ResourceLinkList';

export interface EventListenerDetailsProps {
obj: K8sResourceKind;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
obj: K8sResourceKind;
obj: EventListenerKind;

import { ResourceLink } from '@console/internal/components/utils';
import './ResourceLinkList.scss';

type ResourceLinkListProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we change the API of this to make it easier to call.

Model, "links" & namespace is all we really need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ResourceLink component kind determines which badge to use, so it is also required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what the concern is... you can compute the values with the ModelKind:

// calling file
<ResourceLinkList model={TriggerBindingModel} ... />

// ResourceLinkList
const title = model.labelPlural;
const kind = referenceForModel(model);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the api to make it easier to call

</div>
)}
{pipeline.spec && pipeline.spec.tasks && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Oh right... Pipeline spec is poorly typed. I appreciate you updating this to match types - but spec is never not there to have a proper Pipeline and since 0.9 or so of the Operator, you have to have at least 1 task.

Maybe we just update the type of the Pipeline kind and remove this check.

Comment on lines 26 to 30
<React.Fragment key={name}>
<dd>
<ResourceLink kind={kind} name={name} namespace={namespace} title={name} inline />
</dd>
</React.Fragment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<React.Fragment key={name}>
<dd>
<ResourceLink kind={kind} name={name} namespace={namespace} title={name} inline />
</dd>
</React.Fragment>
<dd key={name}>
<ResourceLink kind={kind} name={name} namespace={namespace} title={name} inline />
</dd>

Fragments are there to support multiple "root" children. Recommend you read the Fragments page on the React docs as this is not the first time I have mentioned a fragment issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure why added this 🤦 , clearly we dont need this, will remove it.

@karthikjeeyar karthikjeeyar force-pushed the trigger-pages branch 2 times, most recently from 6c2768c to 82834f2 Compare April 13, 2020 11:57
@karthikjeeyar
Copy link
Contributor Author

/retest

Copy link
Contributor

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions for you!

  1. Does this PR cover adding trigger information on the Pipeline Run details page? I don't see a screenshot of that.
  2. When Trigger Templates are shown, I think they should have the associated URL below them, at least that was the design. I know that piece of information is optional, but just checking
  3. On the Pipeline details page, can we move the Trigger Templates above the Tasks : https://docs.google.com/document/d/11vShZz7TX7b8YUyTG5zBMZXFnQmPEJ8nqUapCL70yyk/edit#heading=h.woem8ztgbvh5

@karthikjeeyar
Copy link
Contributor Author

@serenamarie125
PLR links are covered in this PR #5011

I have moved the trigger template above the Tasks section.

image

Copy link
Contributor

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the rework & explanations @karthikjeeyar LGTM! Approved by UX

@@ -8,7 +8,6 @@ import { PipelineModel, PipelineResourceModel } from '../../../models';
export interface PipelineRunDetailsProps {
obj: PipelineRun;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Net zero changes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -10,7 +10,6 @@ import PipelineRunVisualization from '../PipelineRunVisualization';

const mockPipelineRun =
pipelineTestData[PipelineExampleNames.SIMPLE_PIPELINE].pipelineRuns[DataState.SUCCESS];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Net zero changes please.

import { ResourceLink } from '@console/internal/components/utils';
import './ResourceLinkList.scss';

type ResourceLinkListProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what the concern is... you can compute the values with the ModelKind:

// calling file
<ResourceLinkList model={TriggerBindingModel} ... />

// ResourceLinkList
const title = model.labelPlural;
const kind = referenceForModel(model);

const EventListenerDetails: React.FC<EventListenerDetailsProps> = ({ obj: eventListener }) => {
const { template, bindings } = (eventListener?.spec?.triggers || []).reduce(
(acc, trigger) => ({
bindings: [...acc.bindings, ...trigger.bindings.map((binding) => binding.name)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, my example neglected that it was an array. Hmmm... the array of objects is there because bindings can have two types ClusterTriggerBinding and TriggerBinding... can you add this to the tech debt ticket? I think we need to swing back once we get an operator update as ClusterTriggerBinding doesn't exist on 0.10.8 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task to update binding logic for 10.0.8 https://issues.redhat.com/browse/ODC-3557

@andrewballantyne
Copy link
Contributor

Few questions for you!

  1. When Trigger Templates are shown, I think they should have the associated URL below them, at least that was the design. I know that piece of information is optional, but just checking

Oh crud! I forgot about this on my first review pass. Please add this @karthikjeeyar - the URL is awkward to get so we'll have to write another hook for this.

I'll see what I can write for this while you're asleep :)

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please focus on the spec and if it makes it optional. We need to start aligning our Kind definitions and our Code. It becomes unruly having to guess every time you write new code seeing optionals literally everywhere.

.odc-trigger-template-list {
margin-bottom: var(--pf-global--spacer--lg);
&__url {
margin-left: calc(10 * var(--pf-global--BorderWidth--lg));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, what? I know we request for pf variables... but this is a bit of malicious compliance lol. I'll have to look at what you're trying to do lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to align the Url with the TT name
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed... we'll need to iterate on this solution heh... I'd prefer a px number over "10 border widths" lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This var(--pf-global--BorderWidth--lg) is in px, so calc(10* 3px) is resulting in 30px.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to a pixel value. Using a variable incorrectly is not a good idea.

@karthikjeeyar karthikjeeyar force-pushed the trigger-pages branch 2 times, most recently from 03031f8 to 8e3cbf8 Compare April 16, 2020 11:35
.odc-trigger-template-list {
margin-bottom: var(--pf-global--spacer--lg);
&__url {
margin-left: calc(10 * var(--pf-global--BorderWidth--lg));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to a pixel value. Using a variable incorrectly is not a good idea.

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 16, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, karthikjeeyar, serenamarie125

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 16, 2020
@openshift-merge-robot openshift-merge-robot merged commit 08c9ebf into openshift:master Apr 16, 2020
@spadgett spadgett added this to the v4.5 milestone Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants