-
Notifications
You must be signed in to change notification settings - Fork 166
feat: settings component for section, subsection and unit #2505
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
Open
ahtesham-quraish
wants to merge
2
commits into
openedx:master
Choose a base branch
from
ahtesham-quraish:ahtesham/#1976
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.
+393
−36
Open
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,3 @@ | ||
| .text-muted-override{ | ||
| color: #DEDBDB !important; | ||
| } |
122 changes: 122 additions & 0 deletions
122
src/library-authoring/containers/SettingsPanel.test.tsx
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,122 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
| import { ContainerType } from '@src/generic/key-utils'; | ||
| import { SettingsPanel } from './SettingsPanel'; | ||
| import messages from './messages'; | ||
|
|
||
| const renderWithIntl = (ui: React.ReactNode) => render( | ||
|
Contributor
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. We usually just use |
||
| <IntlProvider locale="en" messages={{}}> | ||
| {ui} | ||
| </IntlProvider>, | ||
| ); | ||
|
|
||
| describe('SettingsPanel', () => { | ||
| describe('Section container', () => { | ||
| test('renders section default info text', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Section} />); | ||
| expect( | ||
| screen.getByText(messages.settingsSectionDefaultText.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('does not render grading or results visibility', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Section} />); | ||
| expect( | ||
| screen.queryByText(messages.settingsSectionGradingLabel.defaultMessage), | ||
| ).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByText( | ||
| messages.settingsSectionAssessmentResultsVisibilityLabel.defaultMessage, | ||
| ), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders visibility controls', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Section} />); | ||
| expect( | ||
| screen.getByText(messages.settingsSectionVisibilityLabel.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole('button', { | ||
| name: messages.settingsSectionDefaultVisibilityButton.defaultMessage, | ||
| }), | ||
| ).toBeDisabled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Subsection container', () => { | ||
| test('renders subsection default info text', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Subsection} />); | ||
| expect( | ||
| screen.getByText(messages.settingsSubSectionDefaultText.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders grading buttons (disabled)', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Subsection} />); | ||
| expect( | ||
| screen.getByRole('button', { | ||
| name: messages.settingsSectionUpgradeButton.defaultMessage, | ||
| }), | ||
| ).toBeDisabled(); | ||
| expect( | ||
| screen.getByRole('button', { | ||
| name: messages.settingsSectionGradeButton.defaultMessage, | ||
| }), | ||
| ).toBeDisabled(); | ||
| }); | ||
|
|
||
| test('renders visibility + hide content checkbox', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Subsection} />); | ||
| expect( | ||
| screen.getByLabelText( | ||
| messages.settingsSectionHideContentAfterDueDateLabel.defaultMessage, | ||
| ), | ||
| ).toBeDisabled(); | ||
| }); | ||
|
|
||
| test('renders results visibility controls', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Subsection} />); | ||
| expect( | ||
| screen.getByRole('button', { | ||
| name: messages.settingsSectionShowButton.defaultMessage, | ||
| }), | ||
| ).toBeDisabled(); | ||
| expect( | ||
| screen.getByRole('button', { | ||
| name: messages.settingsSectionHideButton.defaultMessage, | ||
| }), | ||
| ).toBeDisabled(); | ||
| expect( | ||
| screen.getByLabelText( | ||
| messages.settingsSectionOnlyShowResultsAfterDueDateLabel.defaultMessage, | ||
| ), | ||
| ).toBeDisabled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Unit container', () => { | ||
| test('renders unit default info text', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Unit} />); | ||
| expect( | ||
| screen.getByText(messages.settingsUnitDefaultText.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders discussion settings', () => { | ||
| renderWithIntl(<SettingsPanel containerType={ContainerType.Unit} />); | ||
| expect( | ||
| screen.getByText(messages.settingsSectionDiscussionLabel.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByLabelText( | ||
| messages.settingsSectionEnableDiscussionLabel.defaultMessage, | ||
| ), | ||
| ).toBeChecked(); | ||
| expect( | ||
| screen.getByText(messages.settingsSectionUnpublishedUnitsLabel.defaultMessage), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
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,133 @@ | ||
| import React, { useState } from 'react'; | ||
| import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
| import { Button, ButtonGroup, Form } from '@openedx/paragon'; | ||
| import { ContainerType } from '@src/generic/key-utils'; | ||
| import messages from './messages'; | ||
|
|
||
| import './SettingsPanel.scss'; | ||
|
|
||
| interface SettingsPanelProps { | ||
| containerType: string; | ||
| } | ||
|
|
||
| export const SettingsPanel: React.FC<SettingsPanelProps> = ({ containerType }) => { | ||
| const [grading] = useState('ungraded'); | ||
| const [visibility] = useState('default'); | ||
| const [resultsVisibility] = useState('show'); | ||
|
|
||
| const disableAll = true; // 👈 set to false to re-enable | ||
|
Contributor
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. What is the purpose of this |
||
|
|
||
| return ( | ||
| <> | ||
| <div className="pb-2 pl-4 pr-4 space-y-4"> | ||
| <p className="text-muted small mb-4"> | ||
| { containerType === ContainerType.Section && ( | ||
| <FormattedMessage {...messages.settingsSectionDefaultText} /> | ||
| )} | ||
| { containerType === ContainerType.Subsection && ( | ||
| <FormattedMessage {...messages.settingsSubSectionDefaultText} /> | ||
| )} | ||
| { containerType === ContainerType.Unit && ( | ||
| <FormattedMessage {...messages.settingsUnitDefaultText} /> | ||
| )} | ||
| </p> | ||
| </div> | ||
| <div className="pb-4 pl-4 pr-4 space-y-4"> | ||
| {containerType === ContainerType.Subsection && ( | ||
| <> | ||
| <h6 className="text-muted small font-weight-bold mb-3"> | ||
| <FormattedMessage {...messages.settingsSectionGradingLabel} /> | ||
| </h6> | ||
| <ButtonGroup className="d-flex w-100 mb-4.5"> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={grading === 'ungraded' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionUpgradeButton} /> | ||
| </Button> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={grading === 'graded' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionGradeButton} /> | ||
| </Button> | ||
| </ButtonGroup> | ||
| </> | ||
| )} | ||
|
|
||
| <h6 className="text-muted small font-weight-bold mt-3 mb-3"> | ||
| <FormattedMessage {...messages.settingsSectionVisibilityLabel} /> | ||
| </h6> | ||
| <ButtonGroup className="d-flex w-100"> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={visibility === 'default' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionDefaultVisibilityButton} /> | ||
| </Button> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={visibility === 'staff' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionStaffOnlyButton} /> | ||
| </Button> | ||
| </ButtonGroup> | ||
| {containerType === ContainerType.Subsection && ( | ||
| <Form.Checkbox className="mt-3 text-muted mb-4.5" disabled> | ||
| <FormattedMessage {...messages.settingsSectionHideContentAfterDueDateLabel} /> | ||
| </Form.Checkbox> | ||
| )} | ||
|
|
||
| {containerType === ContainerType.Subsection && ( | ||
| <> | ||
| <h6 className="text-muted small font-weight-bold mt-1 mb-3"> | ||
| <FormattedMessage {...messages.settingsSectionAssessmentResultsVisibilityLabel} /> | ||
| </h6> | ||
| <ButtonGroup className="d-flex w-100"> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={resultsVisibility === 'show' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionShowButton} /> | ||
| </Button> | ||
| <Button | ||
| className="flex-fill" | ||
| variant={resultsVisibility === 'hide' ? 'dark' : 'outline-secondary'} | ||
| size="sm" | ||
| disabled={disableAll} | ||
| > | ||
| <FormattedMessage {...messages.settingsSectionHideButton} /> | ||
| </Button> | ||
| </ButtonGroup> | ||
| <Form.Checkbox className="mt-3 text-muted mb-4.5" disabled> | ||
| <FormattedMessage {...messages.settingsSectionOnlyShowResultsAfterDueDateLabel} /> | ||
| </Form.Checkbox> | ||
| </> | ||
| )} | ||
| {containerType === ContainerType.Unit && ( | ||
| <> | ||
| <h6 className="text-muted small font-weight-bold mt-3 mb-3"> | ||
| <FormattedMessage {...messages.settingsSectionDiscussionLabel} /> | ||
| </h6> | ||
| <Form.Checkbox className="mt-3 text-muted" disabled checked> | ||
| <FormattedMessage {...messages.settingsSectionEnableDiscussionLabel} /> | ||
| </Form.Checkbox> | ||
| <p className="text-muted small mb-4 text-muted-override"> | ||
| <FormattedMessage {...messages.settingsSectionUnpublishedUnitsLabel} /> | ||
| </p> | ||
| </> | ||
| )} | ||
| </div> | ||
| </> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
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.
Same comment as the other PR: