Skip to content
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

Merged
merged 10 commits into from Aug 2, 2019

Conversation

ndushay
Copy link
Contributor

@ndushay ndushay commented Aug 1, 2019

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

@ndushay ndushay added this to Needs Review in Sinopia Work-Cycle One via automation Aug 1, 2019
Copy link
Contributor Author

@ndushay ndushay left a comment

Choose a reason for hiding this comment

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

some comments inline

src/components/editor/GroupChoiceModal.jsx Show resolved Hide resolved
},
},
resource: {
const state = {
Copy link
Contributor Author

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

__tests__/components/editor/GroupChoiceModal.test.js Outdated Show resolved Hide resolved
alert('Unable to save resource')
console.error('unable to save resource')
console.error(err)
})
props.closeRdfPreview()
props.close()
Copy link
Contributor Author

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.

src/components/editor/GroupChoiceModal.jsx Outdated Show resolved Hide resolved
Copy link
Contributor

@jcoyne jcoyne left a 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 Show resolved Hide resolved
__tests__/reducers/index.test.js Outdated Show resolved Hide resolved
it('adds error to editor state', () => {
const newState = setPublishError(initialState.selectorReducer, {
type: 'RETRIEVE_ERROR',
payload: { resourceTemplateId: 'abc123' },
Copy link
Contributor

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?

Copy link
Contributor Author

@ndushay ndushay Aug 1, 2019

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

Copy link
Contributor Author

@ndushay ndushay Aug 1, 2019

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?

__tests__/reducers/index.test.js Outdated Show resolved Hide resolved
closeGroupChooser, showRdfPreview, assignBaseURL, showResourceURIMessage,
updateStarted, updateFinished,
} from 'actions/index'
import { publishRDFResource } from 'sinopiaServer'
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

src/components/editor/GroupChoiceModal.jsx Outdated Show resolved Hide resolved
// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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:

image

while the following passes:

const reason = action.payload?.reason

src/reducers/index.js Outdated Show resolved Hide resolved
@ndushay
Copy link
Contributor Author

ndushay commented Aug 1, 2019

@jcoyne @jermnelson the changes I just pushed up should address both of your concerns.

@ndushay
Copy link
Contributor Author

ndushay commented Aug 1, 2019

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' },
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hrmm. I changed it and got this:

image

I tried to make it a string before (see comment train above). What am I missing?

__tests__/reducers/index.test.js Outdated Show resolved Hide resolved
src/components/editor/GroupChoiceModal.jsx Outdated Show resolved Hide resolved
src/components/editor/GroupChoiceModal.jsx Outdated Show resolved Hide resolved
src/components/editor/GroupChoiceModal.jsx Outdated Show resolved Hide resolved
src/components/editor/GroupChoiceModal.jsx Show resolved Hide resolved
src/reducers/index.js Outdated Show resolved Hide resolved
src/reducers/index.js Outdated Show resolved Hide resolved
src/reducers/index.js Outdated Show resolved Hide resolved
src/reducers/index.js Outdated Show resolved Hide resolved
dispatch(assignBaseURL(resourceUrl))
dispatch(showResourceURIMessage(resourceUrl))
// Need to regenerate RDF now that we have baseURL
const updatedRdf = new GraphBuilder(getState().selectorReducer).graph.toCanonical()
Copy link
Contributor

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.

Copy link
Contributor Author

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? 🤞

Copy link
Contributor Author

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?

@ndushay ndushay changed the title GroupChoiceModal uses thunk for saving to trellis [Refactor] GroupChoiceModal uses thunk for saving to trellis Aug 1, 2019
@ndushay
Copy link
Contributor Author

ndushay commented Aug 1, 2019

@jcoyne @justinlittman more changes ... are we done yet? :-)

@jcoyne jcoyne merged commit 38c481f into master Aug 2, 2019
Sinopia Work-Cycle One automation moved this from Needs Review to Done Aug 2, 2019
@jcoyne jcoyne deleted the group-choice-thunk branch August 2, 2019 13:00

return publishRDFResource(currentUser, rdf, group).then((result) => {
const resourceUrl = result.response.headers.location
dispatch(assignBaseURL(resourceUrl))
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Move saving out of GroupChoiceModal into thunk
4 participants