-
Notifications
You must be signed in to change notification settings - Fork 26
Connect the frontend UI with the backend API #56
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
Conversation
fb1da3b
to
371c146
Compare
src/api/index.js
Outdated
const token = TokenService.get(); | ||
|
||
if (options.body) { | ||
options.body = JSON.stringify(options.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.
content-type is missed
src/api/index.js
Outdated
}; | ||
} | ||
|
||
// eslint-disable-next-line |
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.
no need for it anymore
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 added it because there were mocks.
Now we can safely remove it.
Please take a look how I did it when connected API to UI:
smacker@7340215#diff-284817f1b6aad47c0ac6d61bd72f474c
src/state/experiment.js
Outdated
); | ||
}; | ||
|
||
const pushAnswer = (experimentId, assignmentId, answer) => (dispatch, getState) => { |
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's not push, it's put or update :)
} | ||
return api.putAnswer(experimentId, assignmentId, answerPayload).catch(e => { | ||
dispatch(addErrors(e)); | ||
dispatch({ type: LOAD_ERROR, error: e }); |
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 will be super weird behavior and also race condition is possible
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 copied it from other places
code-annotation/src/state/experiment.js
Line 136 in b2e1db2
dispatch(addErrors(e)); |
code-annotation/src/state/experiment.js
Line 179 in b2e1db2
dispatch(addErrors(e)); |
Did I miss something? Any
dispatch
maybe?
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.
Yes, you are missing the logic. Of messed up with how async promises work.
Let me explain the whole flow:
A user opens page /exp/1/1
, what happens next:
- middleware see the change and call
selectAssigment
action selectAssigment
setsassignmentId
and callsloadFilePairIfNeeded
action- If there are no files in cache, it calls API and returns promise
- When promise is resolved it sets file content to store or if promise is rejected it sets error
- User choose are those files similar or different. When user clicks button it calls
mark
action. mark
action sets answer to store
next your changes that work wrong
- You call
pushAnswer
action, it returns promise and sets error - at the same time (next tick) it calls
nextAssigment
which starts changes url and everything starts over.
It's very possible that next assignment will be loaded and shown to user before PUT
api call has finished. What would happen in such case?
- User will see next assignment and start deciding answer for the next assignment
- Then he will get error at very random time
right now we don't reset errors anywhere but if we do later it will be even worst.
Because you don't wait for the promise, another promise can remove your error.
It will look like this for user:
- Click button
- Next assignment loader
- Some weird flash
- Next assignment, but the previous answer wasn't saved on server
error handling is missed also. Take a look here: smacker@7340215#diff-284817f1b6aad47c0ac6d61bd72f474c |
@smacker feedback addressed by 29121ae about error handling from #56 (comment) |
5ba4cdc
to
29121ae
Compare
In my opinion correct api handler is part of connection issue. You connect not only successful case but unsuccessful too. But if you prefer to do it in another PR it’s fine. |
29121ae
to
b3df05c
Compare
@dpordomingo could you please help me to understand, what is the status of this PR? There seems to be a CI failure and some feedback may still need to be addressed. |
b3df05c
to
e23350a
Compare
@bzz CI success, but this is still pending #56 (comment). @smacker do you think it should be fixed before merging? |
@dpordomingo current code doesn't work correctly. It's not just missed feature it's a bug. To fix it just change: dispatch(pushAnswer(experimentId, assignmentId, answer));
return dispatch(nextAssigment()); return dispatch(pushAnswer(experimentId, assignmentId, answer)).then(() => {
return dispatch(nextAssigment());
}); there can be a smarter solution, but this works and good enough to allow PR get merged. |
1e32a95
to
f58ec52
Compare
Many thanks @smacker for the hint you offered by #56 (comment) ; I added it here: d2522bd I also had to fix things after rebasing agains current |
f58ec52
to
71b2e65
Compare
server/model/models.go
Outdated
|
||
// Value returns the string value of the Role | ||
func (r Role) Value() (driver.Value, error) { | ||
// TODO: role validation (@dpordomingo) |
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.
Usual way of formatting todos is
//TODO(dpordomingo): role validation
server/model/models.go
Outdated
|
||
var bv driver.Value | ||
var err error | ||
if bv, err = driver.String.ConvertValue(value); err == nil { |
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.
why so complicated? https://play.golang.org/p/3ynyW8ZGKJ5 covers everything we need, no?
server/handler/assignments.go
Outdated
assignments, err := repo.GetAll(userID, experimentID) | ||
if err == repository.ErrNoAssignmentsInitialized { | ||
if assignments, err = repo.Initialize(userID, experimentID); err != nil { | ||
if err == repository.ErrNoPairsAvailable { |
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's incorrect if we are following REST. List APIs should return an empty list when nothing is found, but a request is correct. There is no special rule for it because actually spec for REST doesn't exist. But if you look at any REST API (github for example) you will notice it works like 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.
404 error for endpoint /api/:id/list
means there is no such API or id isn't found. Not empty 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.
/api/experiments/{experimentId}/assignments
is requesting for the assignments of a given experiment, so this 404 Not Found
means that the collection does not exist at all. It is not an "empty" case.
About the status code: 404 Not Found
it's defined as
The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
what matches our case: if in the future are loaded file-pairs, the endpoint will return data.
src/api/index.js
Outdated
); | ||
} | ||
|
||
// eslint-disable-next-line |
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.
as I mentioned before we don't need to disable eslint anymore.
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.
please don't break common REST conventions.
@bzz @smacker Your suggestions were addressed by 2623b4f |
I don't think it worths that amount of discussions for something already done, that is consistent with REST and HTTP status codes and fits our necessities. Anyhow we need to go prod as soon as possible and it's better to move on, so I dropped the When the user has no assignments to fill, instead of rising a reasonable error, he obtains a "success for filling
|
cf13268
to
65c4e0a
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.
Looks great now! Let's merge!!!!
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.
LGTM
Awesome ✨ !
😢 I wanted to rebase and reorder de history... |
List of changes:
Other minor changes: