Skip to content

Conversation

dpordomingo
Copy link
Contributor

@dpordomingo dpordomingo commented Feb 1, 2018

List of changes:

  • c029aba Make Assignment.Answer nullable
  • 901345b Fix push FilePair api url
  • b603e55 Use backend instead of mocks in front
  • 371c146 Implement the answering from UI

Other minor changes:

  • f2a0535 Emit valid diffs
  • 0755005 Use answers as defined by the Backend

src/api/index.js Outdated
const token = TokenService.get();

if (options.body) {
options.body = JSON.stringify(options.body)
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

???

Copy link
Contributor

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

);
};

const pushAnswer = (experimentId, assignmentId, answer) => (dispatch, getState) => {
Copy link
Contributor

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 });
Copy link
Contributor

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

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 copied it from other places

dispatch(addErrors(e));

dispatch(addErrors(e));

Did I miss something? Any dispatch maybe?

Copy link
Contributor

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:

  1. middleware see the change and call selectAssigment action
  2. selectAssigment sets assignmentId and calls loadFilePairIfNeeded action
  3. If there are no files in cache, it calls API and returns promise
  4. When promise is resolved it sets file content to store or if promise is rejected it sets error
  5. User choose are those files similar or different. When user clicks button it calls mark action.
  6. mark action sets answer to store

next your changes that work wrong

  1. You call pushAnswer action, it returns promise and sets error
  2. 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?

  1. User will see next assignment and start deciding answer for the next assignment
  2. 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:

  1. Click button
  2. Next assignment loader
  3. Some weird flash
  4. Next assignment, but the previous answer wasn't saved on server

@smacker
Copy link
Contributor

smacker commented Feb 1, 2018

error handling is missed also. Take a look here: smacker@7340215#diff-284817f1b6aad47c0ac6d61bd72f474c

@dpordomingo
Copy link
Contributor Author

dpordomingo commented Feb 2, 2018

@smacker feedback addressed by 29121ae

about error handling from #56 (comment)
I didn't want to do more things than required. I just added what it was needed to connect with the backend API regardless previous state (that didn't handle errors).
I think it should be better do it in a separated PR as a global thing, shouldn't be?

@smacker
Copy link
Contributor

smacker commented Feb 2, 2018

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.

@bzz
Copy link
Contributor

bzz commented Feb 6, 2018

@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.

@dpordomingo
Copy link
Contributor Author

dpordomingo commented Feb 6, 2018

@bzz CI success, but this is still pending #56 (comment).

@smacker do you think it should be fixed before merging?
If possible, I'd merge and continue working in that (that way, @carlosms could rebase its work from #52 on top of this one, and test its implementation with a real working site)
If you think we can merge without #56 (comment) tell me, and I'll create an issue, rebase, merge, and continue working in that request.

@carlosms carlosms mentioned this pull request Feb 6, 2018
2 tasks
@smacker
Copy link
Contributor

smacker commented Feb 7, 2018

@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.

@bzz bzz mentioned this pull request Feb 8, 2018
8 tasks
Added during review stage
- Simplify export as suggested by @smacker
- Add 'Content-type' and rename putAnswer func as requested by @smacker
@dpordomingo
Copy link
Contributor Author

dpordomingo commented Feb 8, 2018

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 master:

  • c16121f Add default internal db to the .gitignore as agreed with @carlosms
  • 737db98 Implement Scanner and Valuer for model.Role as explained irl to @carlosms and @smacker
  • 71b2e65 Return 404 error when no assignments available to be labeled


// Value returns the string value of the Role
func (r Role) Value() (driver.Value, error) {
// TODO: role validation (@dpordomingo)
Copy link
Contributor

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


var bv driver.Value
var err error
if bv, err = driver.String.ConvertValue(value); err == nil {
Copy link
Contributor

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?

assignments, err := repo.GetAll(userID, experimentID)
if err == repository.ErrNoAssignmentsInitialized {
if assignments, err = repo.Initialize(userID, experimentID); err != nil {
if err == repository.ErrNoPairsAvailable {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor

@smacker smacker left a 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.

@dpordomingo
Copy link
Contributor Author

@bzz @smacker Your suggestions were addressed by 2623b4f
I didn't change the response to an unexistent collection of assignments because since the collection does not exist, it makes sense the 404 (it is not an empty collection, but a collection that does not exist)
I think that further discussions should be addressed aside.

@dpordomingo
Copy link
Contributor Author

dpordomingo commented Feb 9, 2018

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 ErrNoPairsAvailable error 65c4e0a.
The amount of code removed is not relevant at all, and now the frontend also needs changes, but it can be done in a separated PR:

When the user has no assignments to fill, instead of rising a reasonable error, he obtains a "success for filling NaN% experiments, with no possibility to move to any other window.

image
issue: #82

Copy link
Contributor

@smacker smacker left a 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!!!!

@dpordomingo dpordomingo requested a review from bzz February 9, 2018 16:35
Copy link
Contributor

@bzz bzz left a comment

Choose a reason for hiding this comment

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

LGTM

Awesome ✨ !

@bzz bzz merged commit 0b0b404 into src-d:master Feb 9, 2018
@dpordomingo
Copy link
Contributor Author

😢 I wanted to rebase and reorder de history...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants