-
Notifications
You must be signed in to change notification settings - Fork 133
feat: Unit settings in libraries #1912
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
Draft
ChrisChV
wants to merge
2
commits into
openedx:master
Choose a base branch
from
open-craft:chris/FAL-4071-unit-settings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Button, | ||
ButtonGroup, | ||
Container, | ||
Stack, | ||
Form, | ||
} from '@openedx/paragon'; | ||
import messages from './messages'; | ||
import { useLibraryContext } from '../common/context/LibraryContext'; | ||
import { useContainer, useUpdateContainer } from '../data/apiHooks'; | ||
import Loading from '../../generic/Loading'; | ||
import { ToastContext } from '../../generic/toast-context'; | ||
|
||
const UnitSettings = () => { | ||
const intl = useIntl(); | ||
|
||
const { | ||
unitId, | ||
readOnly, | ||
} = useLibraryContext(); | ||
|
||
// istanbul ignore if: this should never happen | ||
if (!unitId) { | ||
throw new Error('unitId is required'); | ||
} | ||
|
||
const [isCheckedDiscussion, setCheckedDiscussion] = useState(false); | ||
const [isHideForLearners, setHideForLearners] = useState(false); | ||
const { data: container } = useContainer(unitId); | ||
const updateMutation = useUpdateContainer(unitId); | ||
const { showToast } = useContext(ToastContext); | ||
|
||
useEffect(() => { | ||
if (!container) { | ||
return; | ||
} | ||
setCheckedDiscussion(container.enableDiscussion); | ||
setHideForLearners(container.hideFromLearners); | ||
}, [container]); | ||
|
||
const onClickDiscussionCheck = useCallback((event) => { | ||
const value: boolean = event.target.checked; | ||
setCheckedDiscussion(value); | ||
updateMutation.mutateAsync({ | ||
metadata: { | ||
enableDiscussion: value, | ||
}, | ||
}).then(() => { | ||
showToast(intl.formatMessage(messages.updateContainerSuccessMsg)); | ||
}).catch(() => { | ||
showToast(intl.formatMessage(messages.updateContainerErrorMsg)); | ||
setCheckedDiscussion(!value); | ||
}); | ||
}, []); | ||
|
||
const onHandleVisibility = useCallback((value: boolean) => { | ||
if (container?.hideFromLearners === value) { | ||
return; | ||
} | ||
|
||
setHideForLearners(value); | ||
updateMutation.mutateAsync({ | ||
metadata: { | ||
hideFromLearners: value, | ||
}, | ||
}).then(() => { | ||
showToast(intl.formatMessage(messages.updateContainerSuccessMsg)); | ||
}).catch(() => { | ||
showToast(intl.formatMessage(messages.updateContainerErrorMsg)); | ||
setHideForLearners(!value); | ||
}); | ||
}, [container]); | ||
|
||
if (!container) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<Stack> | ||
<Container> | ||
<h3 className="h5 mb-3"> | ||
<FormattedMessage {...messages.unitVisibilityTitle} /> | ||
</h3> | ||
<ButtonGroup toggle> | ||
<Button | ||
variant={isHideForLearners ? 'outline-primary' : 'primary'} | ||
disabled={readOnly} | ||
onClick={() => onHandleVisibility(false)} | ||
> | ||
<FormattedMessage {...messages.unitVisibilityStudentLabel} /> | ||
</Button> | ||
<Button | ||
variant={isHideForLearners ? 'primary' : 'outline-primary'} | ||
disabled={readOnly} | ||
onClick={() => onHandleVisibility(true)} | ||
> | ||
<FormattedMessage {...messages.unitVisibilityStaffLabel} /> | ||
</Button> | ||
</ButtonGroup> | ||
</Container> | ||
<hr className="w-100" /> | ||
<Container> | ||
<h3 className="h5 mb-3"> | ||
<FormattedMessage {...messages.unitDiscussionTitle} /> | ||
</h3> | ||
<Form.Checkbox | ||
checked={isCheckedDiscussion} | ||
description={intl.formatMessage(messages.unitEnableDiscussionDescription)} | ||
disabled={readOnly} | ||
onChange={onClickDiscussionCheck} | ||
> | ||
<FormattedMessage {...messages.unitEnableDiscussionLabel} /> | ||
</Form.Checkbox> | ||
</Container> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default UnitSettings; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -56,6 +56,36 @@ const messages = defineMessages({ | |||||
defaultMessage: 'Failed to update container.', | ||||||
description: 'Message displayed when container update fails', | ||||||
}, | ||||||
unitVisibilityTitle: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.visibility.title', | ||||||
defaultMessage: 'Unit Visibility', | ||||||
description: 'Title of the Unit Visibility section on Unit Settings', | ||||||
}, | ||||||
unitDiscussionTitle: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.discussion.title', | ||||||
defaultMessage: 'Discussion', | ||||||
description: 'Title of the Discussion section on Unit Settings', | ||||||
}, | ||||||
unitVisibilityStudentLabel: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.visibility.student', | ||||||
defaultMessage: 'Student Visible', | ||||||
description: 'Label of the button for set the unit as student visible on unit settins.', | ||||||
}, | ||||||
unitVisibilityStaffLabel: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.visibility.staff', | ||||||
defaultMessage: 'Staff Only', | ||||||
description: 'Label of the button for set the unit as staff only visible on unit settins.', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
unitEnableDiscussionLabel: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.discussion.enable.label', | ||||||
defaultMessage: 'Enable discussion', | ||||||
description: 'Label of the check to enable discussion on units settings.', | ||||||
}, | ||||||
unitEnableDiscussionDescription: { | ||||||
id: 'course-authoring.library-authoring.unit.settings.discussion.enable.description', | ||||||
defaultMessage: 'Topics for unpublished units will not be created', | ||||||
description: 'Description of the check to enable discussion on units settings.', | ||||||
}, | ||||||
}); | ||||||
|
||||||
export default messages; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
typo