-
Notifications
You must be signed in to change notification settings - Fork 0
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
website publish without metadata #1
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.
The general approach seems good to me.
I have a few questions and suggestions. I didn't get the time to run the code myself. I'll do that tomorrow and get back to you if I find something new.
@@ -123,7 +123,7 @@ const PublishingOption: React.FC<PublishingOptionProps> = (props) => { | |||
)} | |||
<PublishForm | |||
onSubmit={handlePublish} | |||
disabled={!publishingInfo.hasUnpublishedChanges} | |||
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")} |
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.
Would it be better to use the PublishingEnv
enum from static/js/constants.ts
?
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")} | |
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv===PublishingEnv.Production)} |
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, seems more clean
@@ -123,7 +123,7 @@ const PublishingOption: React.FC<PublishingOptionProps> = (props) => { | |||
)} | |||
<PublishForm | |||
onSubmit={handlePublish} | |||
disabled={!publishingInfo.hasUnpublishedChanges} | |||
disabled={!publishingInfo.hasUnpublishedChanges || (!website.has_site_metadata && publishingEnv==="production")} |
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 condition is rather long, maybe we could refactor it into a separate variable?
This is just a suggestion. It is up to your discretion.
const isPublishDisabled = (
!publishingInfo.hasUnpublishedChanges
|| !website.has_site_metadata && publishingEnv==="production"
)
websites/serializers.py
Outdated
@@ -263,6 +257,10 @@ def get_draft_url(self, instance): | |||
"""Get the draft url for the site""" | |||
return instance.get_full_url(version=VERSION_DRAFT) | |||
|
|||
def get_has_site_metadata(self, instance): | |||
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") | |||
return True if (site_metadata and site_metadata.metadata) else False |
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.
Your code is correct. In my opinion, we can make it easier to read too.
return True if (site_metadata and site_metadata.metadata) else False | |
return bool(site_metadata and site_metadata.metadata) |
websites/serializers.py
Outdated
def get_has_site_metadata(self, instance): | ||
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") | ||
return True if (site_metadata and site_metadata.metadata) else False |
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 think we need to add this in WebsiteStatusSerializer
.
I'm not sure if it is required in WebsiteDetailSerializer
. If it is required in both serializers then I think it would be best to create a mixin, like WebsiteHasMetadataSerializer
.
// Updating website's has_site_metadata to true | ||
store.dispatch(updateEntities({websiteDetails : (prevValue)=>{ | ||
const updatedSite = {...prevValue[site.name], has_site_metadata:true} | ||
let newVal = prevValue; | ||
newVal[site.name] = updatedSite; | ||
return newVal}})) | ||
} |
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 required?
I thought the following code was enough to fetch new data from the backend.
store.dispatch(requestAsync(websiteStatusRequest(site.name)))
Also, since this piece of code sets has_site_metadata: true
for any form submission, I think saving a page will enable the button even when the metadata is not present.
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, I didn't go through the working of WebsiteStatus requests in the code. Will update it soon.
57c1c1f
to
880a7ac
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.
Functionally this is good. I do have some suggestions on refactoring some code. And it would be awesome to format this code using our configured formatters.
@@ -6,6 +6,7 @@ import { requestAsync } from "redux-query" | |||
|
|||
import SiteContentForm from "./forms/SiteContentForm" | |||
import { useWebsite } from "../context/Website" | |||
import { updateEntities } from 'redux-query'; |
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 import being used?
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, removing it
websites/serializers.py
Outdated
has_site_metadata = serializers.SerializerMethodField(read_only=True) | ||
|
||
"""Serializer for website status fields""" | ||
|
||
def get_has_site_metadata(self, instance): | ||
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") | ||
return bool(site_metadata and site_metadata[0].metadata) | ||
|
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.
We're repeating this logic twice.
Maybe we should create a Mixin called WebsiteStatusMixin
. Let me know if you need help with this.
841d148
to
d177b90
Compare
d177b90
to
b5e9fa4
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 good. Just a minor suggestion.
websites/serializers.py
Outdated
class WebsiteHasMetadataMixin(serializers.Serializer): | ||
has_site_metadata = serializers.SerializerMethodField(read_only=True) |
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 always a good idea to add doc strings.
class WebsiteHasMetadataMixin(serializers.Serializer): | |
has_site_metadata = serializers.SerializerMethodField(read_only=True) | |
class WebsiteHasMetadataMixin(serializers.Serializer): | |
"""Adds has_site_metadata custom serializer field.""" | |
has_site_metadata = serializers.SerializerMethodField(read_only=True) |
websites/serializers.py
Outdated
def get_has_site_metadata(self, instance): | ||
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") |
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.
def get_has_site_metadata(self, instance): | |
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") | |
def get_has_site_metadata(self, instance): | |
"""Get whether or not the site has metadata.""" | |
site_metadata = instance.websitecontent_set.filter(type="sitemetadata") |
websites/serializers.py
Outdated
"""Serializer for website status fields""" | ||
|
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.
Was there a reason for removing this docstring?
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, removed by mistake
What are the relevant tickets?
Fixes # 1996
Description (What does it do?)
You can add content to a course and publish it in staging without ever visiting the Metadata section. Production, however will require metadata to be set.
Screenshots (if appropriate):
How can this be tested?
Additional Context
The
course-v2/layouts/partials/course_banner.html
file was changed in theocw-hugo-themes
repository. You can view the changes here