-
Notifications
You must be signed in to change notification settings - Fork 357
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
http helpers for react, API to new js #3662
Conversation
please also see https://github.com/priley86/miq_v2v_ui_plugin/blob/master/app/javascript/common/API.js - ideally it should all be combined? my main concern is around mocking the api calls, /cc @priley86 |
This pull request is not mergeable. Please rebase and repush. |
Yes, the API.js file should not even exist in v2v, ideally v2v should be doing |
V2V has skin in this game, bumping for a lil 🏩 😻 |
Looks like this works now, so just bear with me please @AllenBW while I clean this up and create some nice commits :). |
the following (public) methods are provided for API (this did not change, just mentioning)
the following methods are provded for http - these are only meant for JSON access points:
EDIT: added options to http methods |
☝️ the difference being support for options, vs not? |
@AllenBW not really, it's just we have no options to support there yet - it does not make sense to do EDIT: (The imporant difference is that EDIT2: and the http option support may make some sense for |
…ckend the error modal code needs to be able to tell whether the error comes from a $http request or from an API request, and uses the `source` field for that (`API` vs `$http`) to unify http & API access accross the codebase, including react code, we also need a non-angular http access code this new code will be using the fetch API, the same as our API code - which means we'd have 3 source values, two of which share parts of the implementation so .. splitting this into `source = 'fetch' | '$http'` and `backendName = <human string>`
just a straight move, with the bare minimum changes leaving the angular bits in the old code for now, because of potential ordering issues
…from API where needed
should not actually change anything, just make sure var is not used, globals are properly "imported", etc.
…on around them the idea is that miqFetch can become the common implementation, being able to handle logouts, errors, and tokens for both rails http access and rest api
…r the hood the interface is very simple right now, http.get(url) and http.post(url, data) both the functions return a Promise, both handle logouts and errors
the idea behind vanillaJsAPI was that since we did angular first, using the angular service was preferred, thus a short name was needed they still have to have different names so that we can catch the non-angular version being used in angular code but since the codebase is moving towards vanilla JS / React code first, it makes sense for that version to get the short name - API the angular version will be called $API from now, but any code using API will keep working until we update it all to the new state (a second PR will change API to $API in existing angular code and remove the old names completely once there are no users)
modelled after $http transformResponse, this can be a custom function to change the response in any way needed this will only be applied to success responses, not on error
Added
|
not strictly useful right now, but since the same set of options is supported between the API and http code, it makes sense to make it possible to use some some day
because jest tests don't load any packs first, we need to set `window.vanillaJsAPI` before using it now
Checked commits https://github.com/himdel/manageiq-ui-classic/compare/91793f5613018cacffb2074dfeda93942b3ea170~...8edc838bd9ffea54d1241fb588c872c5620b6356 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
soooooooo we now have a blocker that could use this pr merged 😢 https://bugzilla.redhat.com/show_bug.cgi?id=1573547 |
BEST MORNING NEWS EVA <3 📰 👍 |
;-) |
Backported to Gaprindashvili via #4005 |
Fixes #3658
This moves our API code from
miq_api.js
toapp/javascript
, converts it a more modern style, and splits the implementation into API-specific parts (http_api/api.js
) and the common code (http_api/fetch.js
- amiqFetch
wrapper around the fetch API), making it possible to use that common code to implement a simple http library (http_api/http.js
) for accessing rails controllers with the same interface.This PR keeps all the existing names for the API code for backward compatibility (will remove in a separate PR, once all the code is converted), but changes the preferred default:
window.API
is the API access code for any plain js / react code(
window.vanillaJsAPI
is a deprecated name for the same)$API
is the angular service to acccess the API(
API
is a deprecated name for the same)window.http
is the http access code for any plain js / react code(until now, the only ways were angular
$http
ormiqJqueryRequest
)$http
is the standard angular service, configured to be usable for miq pruposes(no changes there)
All of these methods should behave the same way:
skipLoginRedirect
option is used)skipErrors
option is used)(So as not to overload codeclimate, this also fixes the eslint config to respect the root options - the airbnb config is still used, it just respects everything set in the root .eslintrc as well.)(Please ignore codeclimate for the API code, this will be fixed in #3929.)