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

Bug 1869600: add resource icon to the items in the select task dropdown in the pipeline builder page #6345

Merged

Conversation

debsmita1
Copy link
Contributor

@debsmita1 debsmita1 commented Aug 17, 2020

Fixes:

Root Analysis:
Tasks and ClusterTasks are not visually distinguishable in the Select Task dropdown list in the pipeline builder page.

Solution Description:

  • added resource badge to the items in the Select Task dropdown
  • fixed the issue with Task & ClusterTask having the same name
  • fixed the issue with Tasks not showing up again in the dropdown if it is already selected

GIF:
taskdropdown

@debsmita1
Copy link
Contributor Author

/kind bug

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 17, 2020
@debsmita1 debsmita1 changed the title add resource icon to task and cluster-task Bug 1869600: add resource icon to the items in the select task dropdown in the pipeline builder page Aug 18, 2020
@openshift-ci-robot
Copy link
Contributor

@debsmita1: This pull request references Bugzilla bug 1869600, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.6.0) matches configured target release for branch (4.6.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1869600: add resource icon to the items in the select task dropdown in the pipeline builder page

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Aug 18, 2020
@divyanshiGupta
Copy link
Contributor

@debsmita1 I think we should also add the resource badge to the builder nodes as without the badge the user wont be able to distinguish between the resources with same name just by looking at the pipeline. For example in the attached image one resource is a Task and the other is ClusterTask
image

cc: @beaumorley @bgliwa01

@debsmita1
Copy link
Contributor Author

@debsmita1 I think we should also add the resource badge to the builder nodes as without the badge the user wont be able to distinguish between the resources with same name just by looking at the pipeline. For example in the attached image one resource is a Task and the other is ClusterTask
image

cc: @beaumorley @bgliwa01

@andrewballantyne ^

@andrewballantyne
Copy link
Contributor

@debsmita1 I think we should also add the resource badge to the builder nodes as without the badge the user wont be able to distinguish between the resources with same name just by looking at the pipeline. For example in the attached image one resource is a Task and the other is ClusterTask
image
cc: @beaumorley @bgliwa01

@andrewballantyne ^

No, I think at this point it does not matter. Selecting in a mixed list is a problem because you don't know which is which... but the name in the bubble is a custom name (it just pre-selects as the name of task you took). If you click on the bubble the badge is at the top of the sidebar and the "name" field is a custom name you can use for this task irrespective of what it was originally named.

So I think we are good with just the badge in the dropdown list. @bgliwa01 Please let me know your thoughts.

@bgliwa01
Copy link

Agreed @andrewballantyne

@debsmita1 debsmita1 force-pushed the add-resource-badge branch 2 times, most recently from c065fd2 to 4283248 Compare August 19, 2020 14:27
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.

I'm going to test around a bit and see how this idea goes... but I think this solves the layout issue if we always generate a new name (with a hash if conflicted).

@@ -82,7 +84,7 @@ const TaskListNode: React.FC<TaskListNodeProps> = ({ element, unselectedText })
<div className="pf-c-dropdown pf-m-expanded">
<ul className="pf-c-dropdown__menu pf-m-align-right oc-kebab__popper-items odc-task-list-node__list-items">
{options.map((option) => (
<li key={option.label}>
<li key={`${option.label}-${option.icon?.['props']?.kind}`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of digging into props unless you absolutely have to... I think since we have a little sandbox of code here, we could change things up a bit with the help of TypeScript.

type KeyedKebabOption = KebabOption & { key: string };

const taskToOption = (task: PipelineResourceTask, callback: NewTaskNodeCallback): KeyedKebabOption => {

That way we return a option.key value that we can use. You can set key simply to ${kind}-${name} with the data.

return {
name: resource.metadata.name,
name: `${resource.metadata.name}-${kind.toLowerCase()}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we do this, we are not really avoiding the problem entirely. We are likely to be okay, but let's avoid anything that will lead to potentially another bug (or if QE is on game, a failure of the QE Review).

Recommend a generate name function (maybe we can put this in shared, or here -- wherever for now):

export const safeName = (reservedNames: string[], desiredName: string): string => {
  if (reservedNames.includes(desiredName)) {
    const newName = `${desiredName}-${getRandomChars()}`; // maybe `getRandomChars(3)`?
    if (reservedNames.includes(newName)) {
      return safeName(reservedNames, desiredName);
    }
    return newName;
  }
  return desiredName;
};

// use like:
name: safeName(reservedNames, resource.metadata.name),

Then you update the two uses of convertResourceToTask to include a 3rd param (I'd make it the first param personally) of a string[].

Sample usage:

  const usedNames = tasks.map((t) => t.name);
  const newPipelineTask: PipelineTask = convertResourceToTask(usedNames, resource, runAfter);

@@ -135,7 +135,10 @@ export const useNodes = (

// TODO: Fix id collisions then remove this utility; we shouldn't need to trim the tasks
const noDuplicates = (resource: PipelineResourceTask) =>
!taskGroupRef.current.tasks.find((pt) => pt.name === resource.metadata.name);
!taskGroupRef.current.tasks.find(
(pt) => pt.taskRef.name === resource.metadata.name && pt.taskRef.kind === resource.kind,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't do resource.metadata.name against pt.taskRef.name because this will prevent any double uses of a given task. This isn't the end of the world, but likely will be a problem for some use-cases.

However! With my recent changes suggested, I think we can actually get rid of this function since we'll always will generate a new name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing this piece of code should fix this bug https://issues.redhat.com/browse/ODC-3182, isn't it ?

Copy link
Contributor

@andrewballantyne andrewballantyne Aug 21, 2020

Choose a reason for hiding this comment

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

That is correct @debsmita1 good find of that ticket. That should indeed resolve that issue.

@openshift-ci-robot openshift-ci-robot added the component/core Related to console core functionality label Aug 21, 2020
@debsmita1
Copy link
Contributor Author

/retest

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.

Couple tiny feedback points.

@@ -201,14 +201,16 @@ const addListNode: UpdateOperationAction<UpdateOperationAddData> = (tasks, listT
}
};

const getTaskNames = (tasks: PipelineTask[]) => tasks.map((t) => t.name);
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 this was needed as it's a single operation, but technically it is DRY 😄 So nicely done 👍

@@ -10,6 +10,7 @@ import {
import { getTaskParameters } from '../resource-utils';
import { TASK_ERROR_STRINGS, TaskErrorType } from './const';
import { PipelineBuilderFormikValues, PipelineBuilderFormValues, TaskErrorMap } from './types';
import { getRandomChars } from '@console/shared';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Sort

@@ -528,6 +528,8 @@ export type KebabOption = {
icon?: React.ReactNode;
};

export type KeyedKebabOption = KebabOption & { key: string };
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 we needed to add this to the common code. This was just for our use-case. I think it's probably best to move this back to TaskListNode.tsx. The current KebabOption uses the label as the key... so this feels a little weird in the common code.

@@ -29,15 +30,28 @@ export const taskParamIsRequired = (param: PipelineResourceTaskParam): boolean =
return !('default' in param);
};

export const safeName = (reservedNames: string[], desiredName: string): string => {
if (reservedNames.includes(desiredName)) {
const newName = `${desiredName}-${getRandomChars(5)}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd have gone with the default (6) or shorten it to 3 (half). Not sure this makes really any difference though. Was there a scenario you were worried about using less characters? (ie, any specific reason for 5?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason. Changed it to 3

@openshift-ci-robot
Copy link
Contributor

@debsmita1: This pull request references Bugzilla bug 1869600, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.6.0) matches configured target release for branch (4.6.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1869600: add resource icon to the items in the select task dropdown in the pipeline builder page

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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 lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 21, 2020
@andrewballantyne
Copy link
Contributor

/lgtm cancel

@divyanshiGupta Actually could you do a review here as well. Trying to encourage two point reviews. Didn't see you didn't add a lgtm until I did.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 21, 2020
@openshift-ci-robot openshift-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2020
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2020
Copy link
Member

@invincibleJai invincibleJai left a comment

Choose a reason for hiding this comment

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

Verified the changes looks good !!

@invincibleJai
Copy link
Member

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, debsmita1, invincibleJai

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

@debsmita1
Copy link
Contributor Author

/test e2e-gcp-console

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit b544100 into openshift:master Aug 24, 2020
@openshift-ci-robot
Copy link
Contributor

@debsmita1: All pull requests linked via external trackers have merged: openshift/console#6345. Bugzilla bug 1869600 has been moved to the MODIFIED state.

In response to this:

Bug 1869600: add resource icon to the items in the select task dropdown in the pipeline builder page

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@debsmita1
Copy link
Contributor Author

/cherrypick release-4.5

@openshift-cherrypick-robot

@debsmita1: #6345 failed to apply on top of branch "release-4.5":

Applying: add resource icon to task and cluster-task
Using index info to reconstruct a base tree...
M	frontend/packages/dev-console/src/components/pipelines/pipeline-builder/update-utils.ts
M	frontend/packages/dev-console/src/components/pipelines/pipeline-topology/TaskListNode.tsx
Falling back to patching base and 3-way merge...
Auto-merging frontend/packages/dev-console/src/components/pipelines/pipeline-topology/TaskListNode.tsx
CONFLICT (content): Merge conflict in frontend/packages/dev-console/src/components/pipelines/pipeline-topology/TaskListNode.tsx
Auto-merging frontend/packages/dev-console/src/components/pipelines/pipeline-builder/update-utils.ts
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 add resource icon to task and cluster-task
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherrypick release-4.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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. bugzilla/severity-medium Referenced Bugzilla bug's severity is medium for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/core Related to console core functionality component/dev-console Related to dev-console kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants