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 Bindings view in Hooks create page #730

Closed

Conversation

arshadkazmi42
Copy link
Collaborator

Fixes #610

Attaching snapshot of the page after changes

Screen Shot 2019-05-12 at 11 57 10 PM

@arshadkazmi42 arshadkazmi42 requested a review from a team as a code owner May 12, 2019 18:40
</IconButton>
</ListItem>
))}
</List>
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have bindings, we should add a "Schedule" subheader below it and remove the label="Schedule" prop from the TextField component.

Screen Shot 2019-05-13 at 10 09 15 AM

/>
}
/>
</ListItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a lot of duplicated logic with localhost:5080/pulse-messages. I was thinking maybe we could create a PulseBindings component that will take care of creating

Screen Shot 2019-05-13 at 10 12 36 AM

component/HookForm and views/PulseMessages would then use that component and feed the appropriate props. Maybe something like:

<PulseBindings bindings={...} onBindingAdd={this.handleBindingAdd} onBindingRemove={this.handleBindingRemove} ... />

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I was thinking the same, I was thinking of using existing PulseMessages but that does not seem to help.
I didn't think of creating a new component.
This sounds good. Let me work on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks @arshadkazmi42.

@helfi92 helfi92 self-requested a review May 13, 2019 21:21
Copy link
Contributor

@helfi92 helfi92 left a comment

Choose a reason for hiding this comment

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

Looks really good overall :)

<ListSubheader className={classes.subheader}>
Bindings
</ListSubheader>
}>
Copy link
Contributor

Choose a reason for hiding this comment

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

"Bindings" and "Schedule" don't seem to have the same styling. "Bindings" seems to be smaller. Maybe we can avoid putting the title inside the component and just have it defined in the hook form view.

Screen Shot 2019-05-15 at 4 38 52 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually issue was with adding the bidings inside, subheader class was missing from PulseBinding component, due to that is was not rendering with correct styles.

I have added subheader style in the component and now it looks fine.

Screen Shot 2019-05-16 at 10 02 05 PM

<List
className={classes.inputList}
subheader={
<ListSubheader className={classes.subheader}>
Copy link
Contributor

Choose a reason for hiding this comment

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

subheader doesn't seem to be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was related to the above comment.

onBindingAdd,
onBindingRemove,
onChange,
} = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add static propTypes. We can also add static defaultProps if certain props are not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel all the props are required for this.
I have written static propTypes something like this.

static propTypes = {
    pulseExchange: string.isRequired,
    pattern: string.isRequired,
    bindings: arrayOf(object).isRequired,
    onBindingAdd: func.isRequired,
    onBindingRemove: func.isRequired,
    onChange: func.isRequired,
  };

Also, I am not sure if we would not need static defaultProps in this.

Let me know if there is anything missing

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good.

Copy link
Contributor

@helfi92 helfi92 left a comment

Choose a reason for hiding this comment

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

STR:

  1. Navigate to http://localhost:5080/hooks/garbage/abc456 and login
  2. Add a dummy binding and click on "+"

Actual: The save button is not clickable. The form is not aware of the binding.
Expected: The save button becomes clickable. Clicking on the save icon and then refreshing the page should show the saved binding.

@arshadkazmi42
Copy link
Collaborator Author

@helfi92
I have made changes to pass bindings with payload, I don't have backend setup will you be able to verify it?
Or can you direct me to backend setup guide

@helfi92
Copy link
Contributor

helfi92 commented May 21, 2019

I have made changes to pass bindings with payload, I don't have backend setup will you be able to verify it?
Or can you direct me to backend setup guide

Sure thing. You can look at:

Let me know if you have any questions.

@arshadkazmi42
Copy link
Collaborator Author

@helfi92 I got the backend setup.
I guess bindngs needs to be passed using the graphql mutation

mutation UpdateHook($hookGroupId: ID!, $hookId: ID!, $payload: HookInput!) {
  updateHook(hookGroupId: $hookGroupId, hookId: $hookId, payload: $payload) {
    hookId
  }
}

I am not sure what is the key I have to use to pass binding.
Can you help me out with this, how binding needs to be passed in this

@helfi92
Copy link
Contributor

helfi92 commented May 22, 2019

Good question! I think the bindings is part of the payload. The data structure for a hook is defined in https://github.com/taskcluster/taskcluster/blob/87facc8e7fc4580440bf730e2a0f5e080aba3154/services/hooks/schemas/v1/hook-definition.yml. You will probably just need to do:

diff --git a/services/web-server/src/graphql/Hooks.graphql b/services/web-server/src/graphql/Hooks.graphql
index 92f378b8a..808cd6f52 100644
--- a/services/web-server/src/graphql/Hooks.graphql
+++ b/services/web-server/src/graphql/Hooks.graphql
@@ -72,11 +72,17 @@ type DeleteHook {
   hookId: ID
 }
 
+type HookBinding {
+  exchange: String!
+  routingKeyPattern: String!
+}
+
 input HookInput {
   metadata: HookMetadataInput!
   schedule: [String]
   expires: String
   deadline: String
+  bindings: [HookBinding]
   task: JSON!
   triggerSchema: JSON
 }

Hope that helps.

@@ -72,11 +72,17 @@ type DeleteHook {
hookId: ID
}

input HookBinding {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work for you? I think it should be type, not input.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On adding type web-server was throwing error and changing it to type was suggested. So I changed it to input

Copy link
Contributor

Choose a reason for hiding this comment

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

You are correct. My mistake :)

@helfi92 helfi92 self-requested a review May 23, 2019 17:46
@@ -182,7 +183,7 @@ export default class HookForm extends Component {
state = {
hook: null,
hookLastFires: null,
pattern: '#',
routingKeyPattern: '#',
Copy link
Contributor

Choose a reason for hiding this comment

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

The server expects this property name to be pattern. I don't think this will work atm.

Copy link
Contributor

Choose a reason for hiding this comment

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

It turns out the hook service expects it to be routingKeyPattern. Sorry for that. Now that you have the server setup, are you able to add a hook to http://localhost:5080/hooks/garbage/abc456 and see if it saves successfully?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When trying to save i was getting 401 Authentication failed.
I thought it needs some level of access to save it. So couldn't validate it

Copy link
Contributor

Choose a reason for hiding this comment

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

How were you signing in? I can provide you with the required level of access.

Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to use the manual siginin ./taskcluster signin --name taskcluster-web-server. The taskcluster binary can be downloaded from https://github.com/taskcluster/taskcluster-cli#installation. The taskcluster signin command will open a browser where you will be able to login then upon logging in, the binary will output the credentials in the terminal. Those credentials is what you need to login.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am doing this, in browser I used auth0 login and used those credentials to login in UI

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the exact error you are seeing when you try to create/update a hook?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you get the same error when creating/updating a hook via https://tools.taskcluster.net/?

@helfi92 helfi92 self-requested a review May 24, 2019 12:52
@arshadkazmi42
Copy link
Collaborator Author

What is the exact error you are seeing when you try to create/update a hook?

Screen Shot 2019-05-24 at 7 55 36 PM

@arshadkazmi42
Copy link
Collaborator Author

Looks like I was using old clientID. This is the error I am getting after using fresh clientID

Screen Shot 2019-05-24 at 7 58 12 PM

@arshadkazmi42
Copy link
Collaborator Author

Do you get the same error when creating/updating a hook via https://tools.taskcluster.net/?

This is the error I am getting on this website create

Screen Shot 2019-05-24 at 8 00 57 PM

@helfi92
Copy link
Contributor

helfi92 commented May 24, 2019

That looks better. The error is about insufficient scopes. What are you missing for editing http://localhost:5080/hooks/garbage/arshad? Can you post a screenshot of the error you are seeing in the UI?

@arshadkazmi42
Copy link
Collaborator Author

That looks better. The error is about insufficient scopes. What are you missing for editing http://localhost:5080/hooks/garbage/arshad? Can you post a screenshot of the error you are seeing in the UI?

Screen Shot 2019-05-24 at 8 04 16 PM

@helfi92
Copy link
Contributor

helfi92 commented May 24, 2019

OK, can you try again. I've given you permissions to play with the garbage/arshad hook.

@arshadkazmi42
Copy link
Collaborator Author

Got it working now. Its saving.
But not getting the saved bindings back in response, I think select graphql query needs to be changed. Can you tell me where exactly is the select query for bindngs?

@@ -72,11 +72,17 @@ type DeleteHook {
hookId: ID
}

input HookBinding {
exchange: String!
pattern: String!
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this property needs to be renamed to be in line with what the hook client expects.

Copy link
Contributor

Choose a reason for hiding this comment

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

The actual mutations are happening in services/web-server/src/resolvers/hooks.js.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this property needs to be renamed to be in line with what the hook client expects.

I have updated this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me checkin my latest changes

Copy link
Contributor

Choose a reason for hiding this comment

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

After saving, reloading the page should display the existent bindings that were saved earlier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On page load this query is getting fired

"query Hook($hookGroupId: ID!, $hookId: ID!) {
  hook(hookGroupId: $hookGroupId, hookId: $hookId) {
    hookGroupId
    hookId
    schedule
    metadata {
      name
      description
      owner
      emailOnError
      __typename
    }
    status {
      nextScheduledDate
      lastFire {
        ... on HookSuccessfulFire {
          time
          taskId
          __typename
        }
        ... on HookFailedFire {
          time
          error
          __typename
        }
        ... on NoFire {
          result
          __typename
        }
        __typename
      }
      __typename
    }
    triggerSchema
    task
    __typename
  }
  hookLastFires(hookGroupId: $hookGroupId, hookId: $hookId) {
    taskId
    firedBy
    taskCreateTime
    result
    error
    __typename
  }
}
"

And I don't see bindings field getting queried in this.
I tried adding bindings in this query but its giving 404 after adding bindings in the above query

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you would need to add it in web-server:

diff --cc ui/src/views/PulseMessages/index.jsx
index 85010860d,4371e89d6..000000000
--- a/ui/src/views/PulseMessages/index.jsx
+++ b/ui/src/views/PulseMessages/index.jsx
diff --git a/services/web-server/src/graphql/Hooks.graphql b/services/web-server/src/graphql/Hooks.graphql
index 1c59765f3..040ca0f52 100644
--- a/services/web-server/src/graphql/Hooks.graphql
+++ b/services/web-server/src/graphql/Hooks.graphql
@@ -51,6 +51,7 @@ type HookStatus {
 type Hook {
   hookGroupId: ID!
   hookId: ID!
+  bindings: [HookBinding]
   metadata: HookMetadata!
   schedule: [String]!
   task: JSON!
@@ -72,7 +73,12 @@ type DeleteHook {
   hookId: ID
 }
 
-input HookBinding {
+type HookBinding {
+  exchange: String!
+  routingKeyPattern: String!
+}
+
+input HookBindingInput {
   exchange: String!
   routingKeyPattern: String!
 }
@@ -82,7 +88,7 @@ input HookInput {
   schedule: [String]
   expires: String
   deadline: String
-  bindings: [HookBinding]
+  bindings: [HookBindingInput]
   task: JSON!
   triggerSchema: JSON
 }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am getting insufficient scopes error again

{"errors":[{"message":"Client ID mozilla-auth0/oauth2|firefoxaccounts|967134a2ed244f61b75935fc10b9119c|arshadkazmi42@gmail.com/taskcluster-web-server does not have sufficient scopes and is missing the following scopes:\n\n```\n{\n  \"AllOf\": [\n    \"hooks:modify-hook:garbage/arshad\",\n    \"assume:hook-id:garbage/arshad\"\n  ]\n}\n```\n\n

can you add access for this client id to add bindings? Or can you let me know how can I do this, if my client id changes

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@helfi92 helfi92 self-requested a review May 24, 2019 17:51
@@ -50,6 +50,7 @@ import DeleteIcon from 'mdi-react/DeleteIcon';
}))
export default class PulseBindings extends Component {
static propTypes = {
patternName: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a patternName prop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in PulseMessages component, for bindings pattern key is used so I am passing patternName as input to component, if there is no name passed it will default it to pattern.
As on addBinding function call, uses this name as key and same key is used while rendering

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@helfi92 Can you also look at this comment, I don't want this to get lost in our discussions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was planning to look at this once the rebase is done. Right now there's some merge conflict in this file so I didn't bother looking at it. I plan on looking at it after the rebase :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool. I am rebasing it now, will push fresh commits in sometime

Copy link
Contributor

@helfi92 helfi92 left a comment

Choose a reason for hiding this comment

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

Seems like there's a small regression. Added some comments. When you get a chance, could you perform a rebase, please. Sorry for not reviewing this on Friday, I had to leave early.

@@ -387,6 +391,8 @@ export default class HookForm extends Component {
hook.hookId &&
hook.metadata.name &&
hook.metadata.owner &&
hook.bindings &&
hook.bindings.length > 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

STR:

  1. Add 1 binding only
  2. Save the page
  3. Refresh the page
  4. Delete the binding
  5. Try to save

Expected: The save button is clickable
Actual: The save button is not clickable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@helfi92 Can you configure this client id
mozilla-auth0/oauth2|firefoxaccounts|967134a2ed244f61b75935fc10b9119c|arshadkazmi42@gmail.com/taskcluster-web-server

I have refreshed my token

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks

marginTop: 80,
},
deleteIcon: {
marginRight: -15,
Copy link
Contributor

Choose a reason for hiding this comment

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

marginRight: -theme.spacing.double,

marginRight: -15,
[theme.breakpoints.down('sm')]: {
marginRight: -14,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove L31-33.

@arshadkazmi42 arshadkazmi42 requested a review from a team as a code owner June 4, 2019 15:55
@arshadkazmi42
Copy link
Collaborator Author

arshadkazmi42 commented Jun 4, 2019

@helfi92 I think I broke something in rebase, its showing up 323 files change

Is there some way to revert this? Or I need to open a new PR?
I did the following

1. git fetch upstream
2. git rebase upstream/master (did this on bindings-hook-view branch)

@arshadkazmi42
Copy link
Collaborator Author

arshadkazmi42 commented Jun 4, 2019

@helfi92 I think I broke something in rebase, its showing up 323 files change

Is there some way to revert this? Or I need to open a new PR?
I did the following

1. git fetch upstream
2. git rebase upstream/master (did this on bindings-hook-view branch)

I managed to roll back the rebase.

Do I have to do git merge master ? on my bindings-hook-view branch?

@helfi92
Copy link
Contributor

helfi92 commented Jun 4, 2019

@helfi92 I think I broke something in rebase, its showing up 323 files change

Sometimes git reflog can help but not always. You can read on it in your free time :)

Do I have to do git merge master ? on my bindings-hook-view branch?

I don't think you need to git merge. git rebase should do it (i think). I usually just do

# rebase current branch on upstream master
git pull upstream master --rebase

Once the rebase is done, you can git push origin bindings-hook-view --force.

@arshadkazmi42
Copy link
Collaborator Author

I have done this

# rebase current branch on upstream master
git pull upstream master --rebase

Once the rebase is done, you can git push origin bindings-hook-view --force.

@helfi92
Copy link
Contributor

helfi92 commented Jun 5, 2019

@arshadkazmi42 I think a merge commit was done. I am seeing other commits on this branch. Any chance you could open a separate PR instead with the change, please?

@arshadkazmi42
Copy link
Collaborator Author

@arshadkazmi42 I think a merge commit was done. I am seeing other commits on this branch. Any chance you could open a separate PR instead with the change, please?

Sure. will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UI] Add capacity to edit bindings in hooks view
5 participants