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
[Refactor] GroupChoiceModal uses thunk for saving to trellis #1123
Conversation
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.
some comments inline
}, | ||
}, | ||
resource: { | ||
const state = { |
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.
refactoring these test vars out made the other tests shorter and DRYed it up
alert('Unable to save resource') | ||
console.error('unable to save resource') | ||
console.error(err) | ||
}) | ||
props.closeRdfPreview() | ||
props.close() |
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.
keeping these modal close actions here made sense to me, as they are pertinent to the logic of the GroupChoiceModal. In fact, I originally closed them before showing the error message and an integration test failed.
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 is great. Just a few questions/concerns to wrap up.
__tests__/reducers/index.test.js
Outdated
it('adds error to editor state', () => { | ||
const newState = setPublishError(initialState.selectorReducer, { | ||
type: 'RETRIEVE_ERROR', | ||
payload: { resourceTemplateId: 'abc123' }, |
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 would it have a resourceTemplateId
here? Shouldn't the payload just be a string with the 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 was a bit muzzy on this. It can certainly just have the error. Removing reference to non-existent id ...
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 a better way to test these that avoids mocked errors passing?
closeGroupChooser, showRdfPreview, assignBaseURL, showResourceURIMessage, | ||
updateStarted, updateFinished, | ||
} from 'actions/index' | ||
import { publishRDFResource } from 'sinopiaServer' |
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 now, shameless green. (Sandi Metz says hold your nose for 3 occurrences before refactoring) | ||
export const setPublishError = (state, action) => { | ||
const resourceTemplateId = action.payload.resourceTemplateId | ||
const reason = action.payload.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.
Isn't the payload itself the reason? See https://github.com/LD4P/sinopia_editor/pull/1123/files#diff-4e3037116dbc2bc69a473b7ace3d02abR94
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.
So the action is this, as your link shows:
export const publishError = reason => ({
type: 'PUBLISH_ERROR',
payload: reason,
})
But that is some notation foo for
export const publishError = reason => ({
type: 'PUBLISH_ERROR',
payload: { reason: reason }
})
Which I can show empirically by testing diff references in reducer:
const reason = action.payload
results:
while the following passes:
const reason = action.payload?.reason
@jcoyne @jermnelson the changes I just pushed up should address both of your concerns. |
Note that if PR #1111 is merged first, there should be one more update. |
it('adds error with reason to editor state', () => { | ||
const newState = setPublishError(initialState.selectorReducer, { | ||
type: 'PUBLISH_ERROR', | ||
payload: { reason: 'publishing error msg' }, |
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 believe the payload here would be a string.
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.
src/actionCreators/resources.js
Outdated
dispatch(assignBaseURL(resourceUrl)) | ||
dispatch(showResourceURIMessage(resourceUrl)) | ||
// Need to regenerate RDF now that we have baseURL | ||
const updatedRdf = new GraphBuilder(getState().selectorReducer).graph.toCanonical() |
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 is going to be a race condition here between line 59 and line 62. If assignBaseURL hasn't completed in time, it will produce an incorrect MD5. I'd recommend putting the base URL in a local copy of state and pass that to the GraphBuilder.
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.
@justinlittman I hear you ... but this is straight copied from what was in code -- this is a refactor PR. Can we do the fix separately, or maybe merge this and put fix in your PR #1111? 🤞
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.
or maybe you can push a commit up to this branch if it's super easy for you?
0dbdd7d
to
22b8f27
Compare
@jcoyne @justinlittman more changes ... are we done yet? :-) |
e8b3ac6
to
7f0f9b2
Compare
|
||
return publishRDFResource(currentUser, rdf, group).then((result) => { | ||
const resourceUrl = result.response.headers.location | ||
dispatch(assignBaseURL(resourceUrl)) |
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 assignBaseURL
dispatch still appropriate given lines 65-66
Closes #1051
This is a refactor; no functionality change expected.
Please review carefully; I'm pretty sure I got it right but it's my first thunk.
Also wondering if GroupChoiceModal component tests adequately assert the appropriate plumbing methods are called