Skip to content

Add labels to CreatePipelineRun modal#699

Merged
tekton-robot merged 1 commit into
tektoncd:masterfrom
ncskier:issue323
Dec 6, 2019
Merged

Add labels to CreatePipelineRun modal#699
tekton-robot merged 1 commit into
tektoncd:masterfrom
ncskier:issue323

Conversation

@ncskier

@ncskier ncskier commented Nov 5, 2019

Copy link
Copy Markdown
Member

Changes

Fixes #323
This PR turns the Annotations component into a reusable KeyValueList
component. This KeyValueList component is used to manage annotations in
the SecretsModal, and it is used in the CreatePipelineRun modal to
manage labels.

Here's an image of the labels in the CreatePipelineRun modal (feedback is welcome 🙂):
Screen Shot 2019-11-05 at 5 26 43 PM

/cc @AlanGreene
/cc @carlos-logro

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide
for more details.

@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 5, 2019
@ncskier
ncskier marked this pull request as ready for review November 5, 2019 23:27
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 5, 2019

@carlos-logro carlos-logro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great PR Brandon! Most of my feedback are suggestions and minor changes you missed in the new test file.

Comment thread src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread src/containers/CreatePipelineRun/CreatePipelineRun.js Outdated
Comment thread src/containers/CreatePipelineRun/CreatePipelineRun.js Outdated
.toString(36)
.substring(2, 11)
valuePlaceholder: 'https://github.com',
id: 'annotation0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as per Alan Green's comment on using index or array length for key value:

key should be a value derived from the data being rendered as react uses it to determine which elements need to be updated during the render cycle in response to data change, using the array index is not a good idea as it can lead to unexpected behaviour.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok... it was this before

Math.random()
    .toString(36)
    .substr(2, 9);

so I'll update the id to this in the SecretsModal and CreatePipelineRun modal.

Comment thread src/containers/SecretsModal/SecretsModal.js
annotations: [
{
label: `tekton.dev/git-0`,
key: 'tekton.dev/git-0',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the difference between key & keyPlaceholder?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The key, is the actual text that is in the "key" TextInput (the value prop), whereas the keyPlaceholder is the placeholder text in the "key" TextInput (the placeholder prop).

Do you think that these names are confusing/do you have an idea for an alternative name?

@AlanGreene

Copy link
Copy Markdown
Member

I'd like to get some design input on the controls for adding/removing items from the list, in particular for removal... IMO having the remove button at the top of the list remove an item from the bottom of the list seems odd. Since this is a pattern we're starting to reuse in multiple places in the UI we should make sure we're not causing confusion.
image

@ncskier

ncskier commented Nov 7, 2019

Copy link
Copy Markdown
Member Author

Thanks for the thorough feedback @carlos-logro & @AlanGreene 🙂 I have updated the code to addressed all of your comments.

I'd like to get some design input on the controls for adding/removing items from the list, in particular for removal... IMO having the remove button at the top of the list remove an item from the bottom of the list seems odd. Since this is a pattern we're starting to reuse in multiple places in the UI we should make sure we're not causing confusion.

@AlanGreene you make a good point about the remove behavior being a little unintuitive. Fortunately, since the KeyValueList is now a reusable component, it will be relatively easy to modify 😁 Since we already have this component in the Dashboard, would it be alright if we handle this redesign under a separate issue (separate from this PR)? I think that it could get messy redesigning the component under this PR, because this PR is primarily concerned with adding labels to the Create PipelineRun modal.

@AlanGreene

Copy link
Copy Markdown
Member

Hey @ncskier, yes let's create an issue to make sure that's tracked and try to get to it soon. I'll take another looks at your changes this evening.

Comment thread packages/components/src/components/KeyValueList/KeyValue.test.js Outdated
Comment thread packages/components/src/components/KeyValueList/KeyValue.test.js
Comment thread packages/components/src/components/KeyValueList/KeyValueList.js Outdated
: 'removeIcon'
}
onClick={onRemove}
aria-label={`Remove Button. Removes ${legendText} entry.`}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above, would this be useful for all users?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, I'm not sure what you mean by this. What would I do differently if it was useful or wasn't useful for all users?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

aria-label will only be read by screen readers or similar assistive technologies. If the text in this label is useful / intended for all users it should be a tooltip, an actual label, or some other visible element on the page.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, gotcha, thanks for clarifying. I personally don't think that the text will help users without screen readers. I think that the icons on the buttons are pretty self-explanatory.

Comment thread packages/utils/src/utils/index.js Outdated
}

// Generates a unique id
export function generateId() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we need to guarantee uniqueness we should either use a UUID or add additional context to reduce likelihood of a conflict with other elements on the page that may be difficult to debug. Do we already have another value we could use instead? e.g. are the keys required to be unique already?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it used the index in the list before, but I received this comment, so I changed it to the generateId() function.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm a little confused about this, but I added a prefix for each id based on the item in the KeyValueList; for example:

id: generateId(`annotation${annotations.length}-`)

Do you think this is alright?

Comment thread src/containers/CreatePipelineRun/CreatePipelineRun.js Outdated
/>
</FormGroup>
)}
<FormGroup legendText="">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should the legend text be applied to the FormGroup instead or can we remove the group here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The current style has the legend text inline with the Add & Remove buttons. We can't do this with a normal FormGroup legendText. So, instead, I'm using the styles that were in the SecretModal which make it look like a FormGroup's legendText.

Comment thread src/containers/SecretsModal/SecretsModal.js Outdated
Comment thread src/containers/SecretsModal/SecretsModal.js Outdated
Comment thread src/containers/CreatePipelineRun/CreatePipelineRun.js Outdated
@ncskier
ncskier force-pushed the issue323 branch 7 times, most recently from c4a8681 to eef6064 Compare November 21, 2019 20:45
@ncskier
ncskier requested a review from AlanGreene November 21, 2019 20:46
@ncskier

ncskier commented Nov 22, 2019

Copy link
Copy Markdown
Member Author

Thanks for the review @AlanGreene! I think that I've addressed all of your comments. Can you please take another look when you get the chance?

{ legendText }
)}
/>
<Add

@AlanGreene AlanGreene Nov 25, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry I didn't pick up on this in previous reviews, I didn't realise these were just icons and not buttons.
We should use Button components here with the icon prop set, this will ensure keyboard accessibility etc. works as expected. If you want to hide the button border and background you can set kind="ghost". See LabelFilter, LogoutButton, or Rerun for examples.

defaultMessage: 'Labels'
})}
invalidText={intl.formatMessage(
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can't translate fragments of a sentence in isolation (e.g. 'kubernetes labels syntax'), it won't work for many languages.
Instead what we want is to add placeholders for the link markup so the sentence can be translated as a whole, with the correct context for each part.

Something like this:
'Labels must follow the {0}kubernetes labels syntax{1}.'

@ncskier ncskier Dec 5, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@AlanGreene I don't think it lets me split up JSX tags like that:
Screen Shot 2019-12-05 at 2 02 15 PM
(is this what you were suggesting?)

@ncskier ncskier Dec 5, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I could maybe do something like this to use an icon instead of text as the link, so we won't have to translate it?
Screen Shot 2019-12-05 at 5 31 00 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok looks like react-intl decided this was something people don't need, but there's still a way to get what we want. React's scarily named dangerouslySetInnerHTML to the rescue 😆 In this case it's safe as we fully control the content, there's no user data involved, we can consider the HTML content sanitised.

image

invalidText={
  <span
    dangerouslySetInnerHTML /* eslint-disable-line react/no-danger */={{
      __html: intl.formatMessage(
        {
          id: 'dashboard.createPipelineRun.labels.invalidText',
          defaultMessage:
            'Labels must follow the {0}kubernetes labels syntax{1}.'
        },
        [
          `<a
              href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set"
              target="_blank"
              rel="noopener noreferrer"
            >`,
          '</a>'
        ]
      )
    }}
  />
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Awesome, thanks Alan! I just made the change.

Comment thread src/nls/messages_en.json Outdated
"dashboard.errorBoundary.pageError": "Error loading page",
"dashboard.header.logOut": "Log out",
"dashboard.keyValueList.addButton.ariaLabel": "Add Button. Adds {legendText} entry.",
"dashboard.keyValueList.deleteButton.ariaLabel": "Delete Button#{index}. Deletes entire entry in current text field.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm still struggling a bit with these strings.

'Delete Button#0', will this make sense to a user?
'current text field', how do I know which is the 'current' text field?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, those strings don't really make sense. Since there's already text on the screen for each of these elements, I'm going to remove the aria labels. Is that alright?

@ncskier
ncskier force-pushed the issue323 branch 5 times, most recently from c0f29c4 to 1dc033c Compare December 5, 2019 22:15
Fixes tektoncd#323
This PR turns the Annotations component into a reusable KeyValueList
component. This KeyValueList component is used to manage annotations in
the SecretsModal, and it is used in the CreatePipelineRun modal to
manage labels.

@AlanGreene AlanGreene left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 6, 2019
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlanGreene

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

The pull request process is described here

Details 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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2019
@tekton-robot
tekton-robot merged commit b17e603 into tektoncd:master Dec 6, 2019
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. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to add filtering labels when manually creating PipelineRuns

4 participants