Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

app: add panel to list UPS instances #1255

Merged
merged 9 commits into from
Nov 4, 2017

Conversation

jonathaningram
Copy link
Contributor

@jonathaningram jonathaningram commented Oct 9, 2017

Edit: fixes #1001

This panel appears under the "Services" panel:

image

There's no CRUD for this one so far: just listing out the UPSI that are bound to the app and those that are in the space:

image

It's worth noting that the second section is not "unbound UPSI" - it's showing all UPSI in the space that are not bound to the app. In fact, it might be showing UPSI that are bound to another app. It would be nice to make this a bit better, but we're limited by what the CF API returns (it doesn't tell us if the UPSI is bound). So without doing some transformations ourselves, I found the best way to do this quickly was to just label the second section as "Others in the space".

I imagine it's useful to know the GUID of the UPSI too - for now I've just put it in the title attribute in order to avoid cluttering the UI with GUIDs.

);
}

renderOther() {
Copy link
Contributor

Choose a reason for hiding this comment

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

renderOther is kind of generic.
change renderOther to something like renderUnbound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about renderOthersInSpace? It's not quite "unbound" per:

It's worth noting that the second section is not "unbound UPSI" - it's showing all UPSI in the space that are not bound to the app. In fact, it might be showing UPSI that are bound to another app. It would be nice to make this a bit better, but we're limited by what the CF API returns (it doesn't tell us if the UPSI is bound). So without doing some transformations ourselves, I found the best way to do this quickly was to just label the second section as "Others in the space".

Copy link
Contributor

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

@jonathaningram This looks good.
Could you add some unit tests for the upsi_actions and upsi_panel?

@jonathaningram jonathaningram force-pushed the ji-app-upsi-panel-2 branch 2 times, most recently from 1e5fcd4 to 4cd8b22 Compare October 16, 2017 08:52
@jonathaningram
Copy link
Contributor Author

@jcscottiii ready for review again.

@@ -1,6 +1,6 @@
import AppDispatcher from '../dispatcher';
import { envActionTypes } from '../constants';
import cfApi from '../util/cf_api.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason your removed the .js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jcscottiii yep, we don't need the .js suffix for importing modules. Same reason that the two lines above don't have the suffix, e.g. import AppDispatcher from '../dispatcher';.
Related: we shouldn't need to be naming files with .jsx and subsequently having to specify that prefix when importing those modules either. It's not really that useful. Even the Airbnb guide doesn't use the .jsx suffix for importing: https://github.com/airbnb/javascript/tree/master/react#naming

Also related: we're not following their guideline for naming components. E.g. we are currently using import ReservationCard from './reservation_card.jsx'; and we should be using import ReservationCard from './ReservationCard'; if we follow Airbnb's guide (and what's most commonly used in React projects).

Copy link
Contributor

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

@jonathaningram you don't need to rethrow the error. In Redux, you create a matching error handling action.
Now, if the actions aren't doing appropriate things, that's a different problem.

@jonathaningram
Copy link
Contributor Author

@jonathaningram you don't need to rethrow the error. In Redux, you create a matching error handling action.
Now, if the actions aren't doing appropriate things, that's a different problem.

@jcscottiii see Dan Abramov's comments on this:

  1. No error is shown when use a undefined variable facebook/react#7617 (comment)
  2. https://twitter.com/dan_abramov/status/776891811222675457?lang=en
  3. https://twitter.com/dan_abramov/status/770914221638942720?lang=en

The first one is the best reference, and I'll paste in the most important paragraphs here:

Problem:

image

Even something as simple as an undefined variable gets swallowed using .catch which makes for very hard development workflow.

Solution:

image

I can update the code to not rethrow, but change to using the second argument to .then instead of using .catch. I was only rethrowing because I wanted to show the error and wanted to change the current behaviour as little as possible. This was/is essentially a stepping stone.

Related: that this problem is slightly improved in React 16, so we should look at upgrading in the near future.

jonathaningram and others added 7 commits October 18, 2017 16:14
By .catching these promises (and others that are not yet fixed), this is
actually masking any error that is thrown, not just things that arise
from the promise in question failing. This causes a lot of issues. For
example, the test in app_action.spec.js that is changed in this commit
was not working as intended because the cfAPI.fetchApp call was never
being stubbed - and the .catch handler was masking the fact that the
cfAPI was actually trying to make a real call. Many other errors are
masked because of these .catch handlers which makes development much
harder.
@jcscottiii
Copy link
Contributor

@jonathaningram let's leave it for react 16 (just create an issue about it). since react 16 will kind of take care of those weird cases like undefined variables, i would like to keep the actions handling all other errors.

@jonathaningram
Copy link
Contributor Author

@jcscottiii ok reverted the error handling change. Ready for review.

Copy link
Contributor

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

just a question but LGTM

return Promise.resolve({ items });
};

fetchAllSuccess.exportTest = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

what are these (this line and the other exportTest) needed for?

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'll remove it for now. It's an idea I was toying with.

Rationale: testing JS modules often means you need to export certain things so that the test file can import them to test. Unlike in Go where it can test both exported and unexported members, with JS modules, we're forced to export all the things if we want to test them. However, I don't want callers to use these. E.g. fetchAllSuccess should never be directly called. So I toyed with the idea of setting exportTest = true as an indicator that it shouldn't be used. Of course, to actually enforce it we would need tooling: e.g. maybe eslint can error when it's imported and used. Also even though the bandwidth would be minimal, we could also use a babel plugin to strip them out. I didn't really look for existing solutions to this - I just made this up as I was writing the test.

Anyway, I'll just remove it for now, but it's something that we could revisit later out of interest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK @jcscottiii removed.

@jonathaningram
Copy link
Contributor Author

@jcscottiii let me know if there's anything pending with this? I feel like we're good to go but I may have missed a change request.

@jcscottiii jcscottiii merged commit 95bda81 into cloud-gov:master Nov 4, 2017
@jonathaningram jonathaningram deleted the ji-app-upsi-panel-2 branch November 5, 2017 22:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User provided services do not appear in dashboard
2 participants