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

Use install properties to check if triggers is installed #1370

Merged
merged 1 commit into from
May 18, 2020

Conversation

eddycharly
Copy link
Member

Changes

This PR changes the way we detect if triggers is installed.
It uses the getInstallProperties api instead of trying to access the CRD.

/cc @a-roberts @AlanGreene

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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 12, 2020
@eddycharly eddycharly force-pushed the triggers-installed branch from e3b31d6 to fdadae6 Compare May 12, 2020 15:53
@tekton-robot tekton-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 12, 2020
@eddycharly eddycharly force-pushed the triggers-installed branch from fdadae6 to f6c91f5 Compare May 12, 2020 16:01
Copy link
Member

@AlanGreene AlanGreene left a comment

Choose a reason for hiding this comment

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

The install properties are already available in the redux store (fetched in App.js) so there should be no need to request them again here.

We could just add an isTriggersInstalled (or similar) selector in https://github.com/tektoncd/dashboard/blob/master/src/reducers/properties.js and use that in the SideNav.

@eddycharly
Copy link
Member Author

The install properties are already available in the redux store (fetched in App.js) so there should be no need to request them again here.

Sorry, i didn't know that, I just borrowed the code from the About page.

Time to learn about reducers i guess 😂

@eddycharly eddycharly force-pushed the triggers-installed branch from f6c91f5 to e29193b Compare May 12, 2020 16:18
@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 12, 2020
@eddycharly eddycharly force-pushed the triggers-installed branch from e29193b to 4d772a4 Compare May 12, 2020 16:19
@eddycharly eddycharly requested a review from AlanGreene May 12, 2020 16:20
@eddycharly eddycharly force-pushed the triggers-installed branch 5 times, most recently from 648d21a to 4fbeded Compare May 12, 2020 17:37
@eddycharly
Copy link
Member Author

/test tekton-dashboard-unit-tests

@eddycharly eddycharly force-pushed the triggers-installed branch from 4fbeded to 21e5706 Compare May 12, 2020 19:22
@eddycharly
Copy link
Member Author

I don't understand why tests are failing, any help on this would be nice ! 🙏

@AlanGreene
Copy link
Member

Taking a look

@AlanGreene
Copy link
Member

AlanGreene commented May 12, 2020

OK so in the SideNav test you're mocking both isReadOnly and isTriggersInstalled, these will apply to all tests in the file.

If you want to override the behaviour for a specific test (e.g. the 'SideNav renders with triggers' test below), you can do this:

beforeEach(() => {
  jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => true);
  jest.spyOn(selectors, 'isTriggersInstalled').mockImplementation(() => false);
});

...

it('SideNav renders with triggers', async () => {
  selectors.isTriggersInstalled.mockImplementation(() => true);

Calling jest.spyOn on an existing spy to update its behaviour may work in some scenarios, but it's generally safer to do it as <existingSpy>.mockImplementation(...) instead.

I'm not sure why the error message wasn't helpful this time, they're usually much better...

@eddycharly
Copy link
Member Author

Thank you, I will test this tomorrow !

@eddycharly
Copy link
Member Author

No luck.

Test SideNav selects namespace based on URL for example raises the error TypeError: Cannot read property 'props' of undefined

I might be doing something wrong but dunno what :(

@AlanGreene
Copy link
Member

Strange, I'll take another look at this later today and see what I can come up with.

@AlanGreene
Copy link
Member

There's something strange going on with the SideNavMenu component in Carbon. I've reached out to the devs to see if it's a bug or if perhaps we're using the component in an unexpected way and there's something else we can do to resolve / work around this.

In the meantime, adding defaultProps on the SideNav component does the trick:

diff --git a/src/containers/SideNav/SideNav.js b/src/containers/SideNav/SideNav.js
index c435667..3f71868 100644
--- a/src/containers/SideNav/SideNav.js
+++ b/src/containers/SideNav/SideNav.js
@@ -338,6 +338,10 @@ class SideNav extends Component {
   }
 }
 
+SideNav.defaultProps = {
+  isTriggersInstalled: false
+};
+
 /* istanbul ignore next */
 const mapStateToProps = state => ({
   extensions: getExtensions(state),
diff --git a/src/containers/SideNav/SideNav.test.js b/src/containers/SideNav/SideNav.test.js
index e056716..ed33d34 100644
--- a/src/containers/SideNav/SideNav.test.js
+++ b/src/containers/SideNav/SideNav.test.js
@@ -62,7 +62,8 @@ it('SideNav renders with extensions', () => {
 });
 
 it('SideNav renders with triggers', async () => {
-  jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => false);
+  selectors.isReadOnly.mockImplementation(() => false);
+  selectors.isTriggersInstalled.mockImplementation(() => true);
 
   const middleware = [thunk];
   const mockStore = configureStore(middleware);
@@ -586,7 +587,7 @@ it('SideNav updates namespace in URL', async () => {
 });
 
 it('SideNav renders import in not read-only mode', async () => {
-  jest.spyOn(selectors, 'isReadOnly').mockImplementation(() => false);
+  selectors.isReadOnly.mockImplementation(() => false);
 
   const middleware = [thunk];
   const mockStore = configureStore(middleware);

image

@eddycharly eddycharly force-pushed the triggers-installed branch from 21e5706 to f57db9e Compare May 13, 2020 21:10
@eddycharly eddycharly force-pushed the triggers-installed branch from f57db9e to 92d6646 Compare May 13, 2020 21:15
@eddycharly
Copy link
Member Author

Thank you so much ! 😅

@eddycharly
Copy link
Member Author

@a-roberts @AlanGreene i think this one should be pretty safe to merge also

Copy link
Member

@a-roberts a-roberts left a comment

Choose a reason for hiding this comment

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

Yeah, so the jist of it being

export function isTriggersInstalled(state) {
  return (state.TriggersNamespace && state.TriggersVersion) || false;
}

I see, nice compact way of doing it, those detection mechanisms are already good on OpenShift so let's get it in unless @AlanGreene has any objections (holding the lgtm)

@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-roberts

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 18, 2020
@AlanGreene
Copy link
Member

Yeah looks good to me, tested it out locally and working nicely. I need to think a bit about how it affects #1388 (the client app approach I demoed today) but won't hold it up for that since it's still very much experimental and there are ways around it.

/lgtm
/meow

@tekton-robot
Copy link
Contributor

@AlanGreene: cat image

In response to this:

Yeah looks good to me, tested it out locally and working nicely. I need to think a bit about how it affects #1388 (the client app approach I demoed today) but won't hold it up for that since it's still very much experimental and there are ways around it.

/lgtm
/meow

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.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 18, 2020
@tekton-robot tekton-robot merged commit 76b33c1 into tektoncd:master May 18, 2020
@eddycharly eddycharly deleted the triggers-installed branch May 18, 2020 16:48
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants