-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 Client API #17583
Add Client API #17583
Conversation
Your PR has finished running tests. |
|
||
import endpoints from './endpoints'; | ||
|
||
export function requestEntitlements(username_or_email) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the param?
import endpoints from './endpoints'; | ||
|
||
export function requestEntitlements(username_or_email) { | ||
console.log('called requestEntitlements api function'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this console
statement necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, no . hadn't pushed that change
); | ||
} | ||
|
||
export function createEntitlement(course_uuid, user, mode, reason, comments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been finding that using objects as method parameters makes things, in some cases, easier to reason / read about when that method is called.
Here's an article that provides some examples.
// might be more readable
createEntitlement({ courseUUID: '098sfgoj5', user: 'baejadley', mode: 'baemode', reason: 'tobebae', comments: 'jaebaebae' });
// than
createEntitlement('098sfgoj5', 'baejadley', 'baemode', 'tobebae', 'jaebaebae' );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it
@@ -0,0 +1,3 @@ | |||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason not to use a named export
?
export {
entitlementList: 'whatever',
inTheFutureSomeOtherEndpoint: 'moar whatever',
};
it's going to cause an eslint error (maybe) if there's only one exported property, but I think it's fine to disable for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed with @cpennington that we support ES6
and CommonJS
import
and export
ing in edx-platform
- I think we should use ES6
modules where we can.
Your PR has finished running tests. |
import 'whatwg-fetch'; // fetch polyfill | ||
import Cookies from 'js-cookie'; | ||
|
||
import endpoints from './endpoints'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be added benefit importing it this way so that you're forced to specify endpoints.entitlementList
later on (and make it abundantly clear that it's some endpoint value) but this file is not so big that importing the value like
import { entitlementList } from './endpoints';
would be hard to decipher.
|
||
import endpoints from './endpoints'; | ||
|
||
export function requestEntitlements({usernameOrEmail}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave it as usernameOrEmail, since thats explicit, userIdentifier makes me think of a uuid.
} | ||
|
||
export function updateEntitlement({email, reason, entitlementUuid, comments}) { | ||
//Only requires an 'email' parameter to construct the url, not actually sent in the body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relevant, my team has discussed modifying the api to not be built in the url pattern.
`${endpoints.entitlementList}/${email}`, { | ||
credentials: 'same-origin', | ||
method: 'put', | ||
headers:{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POST
and PUT
headers seem to be identical - can we DRY here?
@@ -0,0 +1,54 @@ | |||
import 'whatwg-fetch'; // fetch polyfill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably copy/pasted this comment from somewhere, but it seems somewhat unnecessary?
headers: headers, | ||
body:JSON.stringify({ | ||
entitlement_uuid: entitlementUuid, | ||
reason: reason, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate myself for pointing this out but...indentation
credentials: 'same-origin', | ||
method: 'put', | ||
headers: headers, | ||
body:JSON.stringify({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I hate myself for pointing this out but there should be a space before JSON
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,4 @@ | |||
export { | |||
entitlementList: 'whatever', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't want this to actually be whatever
?
Your PR has finished running tests. |
852e5ce
to
4712bad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Some minor code style comments and should be ready to
|
||
import { entitlementList } from './endpoints'; | ||
|
||
const headers = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Style Note: When defining a constant use all caps and underscores for the name (e.g. NAME_OF_CONST). It will clearly identify what in the code is constant and what is variable.
@@ -0,0 +1,3 @@ | |||
export { | |||
entitlementList: '/support/entitlement_list', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a constant at its root as well. You might want to make this all caps as well to match the code style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am researching this within out code style guides. This is the standard I have worked with in the past, but I am not sure where this fits in the edX style guide.
I have always found it to be more clear and helpful in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was modeling this off of studio front end endpoints. I'm not sure SCREAMING_SNAKE_CASE is out standard for constants in front end. @edx/fedx-team do we have a decision/opinion on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with what ever the style guide says :D. I have seen it different depending on the company.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think studio-frontend might have a mistake there. The JS convention is to use the SCREAMING_SNAKE_CASE 🐍 for constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mjloturco and @staubina I think we default to the airbnb/javascript
style guide. Currently, it looks like the rule is that constants should be defined as camelCase.
However, there is this PR that might add SCREAMING_SNAKE_CASE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a couple of other opinions. You can disregard these recommendations. This is more a thing in Python and other languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, guess I'm wrong. I thought our style guide was different. Redux uses SCREAMING_SNAKE_CASE for action name constants so I thought it was the same as that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, leaving it as is.
} | ||
|
||
export function updateEntitlement({email, reason, entitlementUuid, comments}) { | ||
//Email param may be removable when EntitlementSupportListView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a ticket id to this that we are planning to do this work in? It looks like this should be tracked as a Task or story and a TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't decided yet if its something we want to do/adds any value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I make a ticket we can talk about in grooming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets talk about it before grooming. If we believe it is work we should do it is better to have it in a ticket than lost in the code simply in a comment.
'X-CSRFToken': Cookies.get('csrftoken'), | ||
} | ||
|
||
export function requestEntitlements({usernameOrEmail}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be clearer for the usernameOrEmail
/ user
/ email
parameters in the three different functions to all have the one name, since they represent the same piece of information in each of the three requests.
); | ||
} | ||
|
||
export function createEntitlement({courseUuid, user, mode, reason, comments}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: for consistency it might be nice to have the ordering of parameters in the PUT
and POST
methods be fairly the same, i.e {user, reason, courseUuid, mode, comments}
here to mirror below or {entitlementUuid, email, reason, comments}
below to mirror what is here.
Your PR has finished running tests. |
|
||
export function requestEntitlements({username}) { | ||
return fetch( | ||
`${entitlementApi}/?user=${usernameOrEmail}`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
username
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ye
|
||
export function requestEntitlements({username}) { | ||
return fetch( | ||
`${entitlementApi}/?user=${usernameOrEmail}`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently fetch
doesn't come with built-in query parameter support
It's probably overkill, but you could consider using qs
or querystring
'X-CSRFToken': Cookies.get('csrftoken'), | ||
} | ||
|
||
export function requestEntitlements({username}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a step back...if this is in the entitlements/data/api/client.js
file, is the entitlements
part of all of these method names redundant / extraneous?
import { requestEntitlements, createEntitlement } from './entitlements/data/api/client';
import { get, create } from './entitlements/data/api/client';
import {
get as requestEntitlements,
create as createEntitlement,
} from './entitlements/data/api/client';
I get (and appreciate) the added verbosity but I wonder if it's relatively unnecessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed in person, this comment is for history. I've decided to leave this as is for now, In the future additional endpoints may be added to this client, though currently it only interacts with the entitlement api
cdec30f
to
cc4e858
Compare
44ecaa4
to
aef9fb2
Compare
jenkins run all |
aef9fb2
to
946caec
Compare
'X-CSRFToken': Cookies.get('csrftoken'), | ||
} | ||
|
||
export function requestEntitlements({username}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Yeah, gonna be that person again - these exports should be grouped at the end of the file.
Check out the eslint-plugin-import#groups-exports
rule.
The airbnb/javascript
style-guide doesn't explicitly mention this but in airbnb/javascript#1275
one of the maintainer of the style-guide who is also one of the maintainers of eslint-plugin-import
said
As far as positioning, there will soon be a linter rule in eslint-plugin-import that will require that all export statements are grouped together - so I'd recommend grouping them together and putting them at the bottom of the file.
Your PR has finished running tests. |
946caec
to
35a305c
Compare
Your PR has finished running tests. |
); | ||
} | ||
|
||
const updateEntitlement = ({entitlementUuid, unenrolled_run, reason, comments}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right
); | ||
} | ||
|
||
const updateEntitlement = ({entitlementUuid, unenrolledRun, reason, comments}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reason
is unused?
); | ||
} | ||
|
||
const createEntitlement = ({username, courseUuid, mode, reason, comments}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reason
is also unused here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should both be action
and should be included in the support_details
object
Your PR has finished running tests. |
package.json
Outdated
@@ -53,6 +54,7 @@ | |||
"webpack": "2.7.0", | |||
"webpack-bundle-tracker": "0.2.1", | |||
"webpack-merge": "4.1.1", | |||
"whatwg-fetch": "^2.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the pattern is to pin these to an exact version (note the lack of ^
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I just ran a command the linter told me to run. Should I just cut the ^?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your PR has finished running tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,3 @@ | |||
export { | |||
entitlementApi: '/api/entitlements/v1/entitlements', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is causing you linting errors because if only one thing gets exported it wants it to be the default
export
consider moving the constant to client.js
unless additional endpoint values are expected to be added in the near future (which, if I'm remembering correctly, is not the case?).
Learner-3925 Learner-4388
a463286
to
a117f6f
Compare
Your PR has finished running tests. |
EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production on Friday, March 09, 2018. |
EdX Release Notice: This PR has been deployed to the production environment. |
Adds a client api for the entitlement support tool front end to call to interact with entitlement support details endpoint
To be merged into this feature branch when approved
(part of) Learner-3925
Learner-4388