-
Notifications
You must be signed in to change notification settings - Fork 115
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
ENH Refactor Element and graphql hoc #1176
ENH Refactor Element and graphql hoc #1176
Conversation
baeebb4
to
2804da8
Compare
2804da8
to
1d0d954
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.
Haven't actually tested it yet - will do that after these questions have been addressed in case they result in substantial changes.
useEffect(() => { | ||
if (formHasRendered && doPublishElement) { | ||
publishBlock({ variables: { blockId: props.element.id } }) | ||
.then(() => handleAfterPublish(false)) | ||
.catch(() => handleAfterPublish(true)); | ||
} | ||
}, [formHasRendered, doPublishElement]); |
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 notice the handlePublishBlock
from publishBlockMutation
isn't being used here - should that be removed?
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.
Note that handlePublishBlock
has a refetchQueries
that doesn't seem to be represented 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.
I've just removed the unused code from publishBlockMutation(), so that it's now only the gql
mutation.
handleAfterPublish() calls refetchElementalArea() which is the equivalent of what was happening with the refetchQueries in publishBlockMutation() before
// Ensure that formDirty becomes falsey after publishing | ||
// We need to call at a later render rather than straight away or redux-form may override this | ||
// and set the form state to dirty under certain conditions | ||
// setTimeout is a hackish way to do this, though I'm not sure how else we can do this | ||
// The core issue is that redux-form will detect changes when a form is hydrated for the first | ||
// time under certain conditions, specifically during a behat test when trying to publish a closed | ||
// block when presumably the apollo cache is empty (or something like that). This happens late and | ||
// there are no hooks/callbacks available after this happens the input onchange handlers are fired | ||
Promise.all(refetchElementalArea()) | ||
.then(() => { | ||
setTimeout(() => props.dispatchRemoveFormChanged(), 250); | ||
}); |
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 the kind of thing the refactor is intended to avoid... it feels like we're just trading one bad code smell for another here. Do you have a sense for whether the refactor has overall improved code quality? If it has then I guess I can live with this....
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 still an improvement we're always going to call props.dispatchRemoveFormChanged() after the graphql XHR in refetchElementalArea(), which previously wasn't guaranteed.
1d0d954
to
a8fc6f0
Compare
Seems to work fine in the browser as-is so we're just dealing with code quality at this point. If the refetch queries change I've suggested above doesn't remove the need for the timeout, it may not be worth doing. |
a8fc6f0
to
834d692
Compare
834d692
to
344bc54
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 okay. I still don't like that timeout but it sounds like we have to accept some code smells in order to remove others.
Issue #1164
Notes: