Skip to content

Commit 9edeba9

Browse files
committed
feat(pages-and-resources): remove isEditable prop from forms and related components
1 parent 8474790 commit 9edeba9

7 files changed

Lines changed: 16 additions & 105 deletions

File tree

src/advanced-settings/AdvancedSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const AdvancedSettings = () => {
7272

7373
const isEditable = !isAuthzEnabled
7474
|| isLoadingUserPermissions
75-
|| !!canManageAdvancedSettings;
75+
|| canManageAdvancedSettings;
7676

7777
const updateSettingsButtonState = {
7878
labels: {

src/pages-and-resources/discussions/app-config-form/AppConfigForm.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const AppConfigForm = ({
4242
const navigate = useNavigate();
4343

4444
const { formRef } = useContext(AppConfigFormContext);
45-
const { path: pagesAndResourcesPath, isEditable } = useContext(PagesAndResourcesContext);
45+
const { path: pagesAndResourcesPath } = useContext(PagesAndResourcesContext);
4646
const { appId: routeAppId } = useParams();
4747
const [isLoading, setLoading] = useState(true);
4848
const {
@@ -102,7 +102,6 @@ const AppConfigForm = ({
102102
formRef={formRef}
103103
onSubmit={handleSubmit}
104104
legacy
105-
isEditable={isEditable}
106105
/>
107106
);
108107
} else if (selectedAppId === 'openedx') {
@@ -111,15 +110,13 @@ const AppConfigForm = ({
111110
formRef={formRef}
112111
onSubmit={handleSubmit}
113112
legacy={false}
114-
isEditable={isEditable}
115113
/>
116114
);
117115
} else {
118116
form = (
119117
<LtiConfigForm
120118
formRef={formRef}
121119
onSubmit={handleSubmit}
122-
isEditable={isEditable}
123120
/>
124121
);
125122
}

src/pages-and-resources/discussions/app-config-form/apps/lti/LtiConfigForm.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useModel } from '../../../../../generic/model-store';
1818

1919
ensureConfig(['SITE_NAME', 'SUPPORT_EMAIL'], 'LTI Config Form');
2020

21-
const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
21+
const LtiConfigForm = ({ onSubmit, formRef }) => {
2222
const intl = useIntl();
2323
const dispatch = useDispatch();
2424

@@ -113,7 +113,7 @@ const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
113113
onChange={handleChange}
114114
onBlur={handleBlur}
115115
value={values.consumerKey}
116-
disabled={!isEditable}
116+
117117
/>
118118
{isInvalidConsumerKey && (
119119
<Form.Control.Feedback type="invalid" hasIcon={false}>
@@ -131,7 +131,7 @@ const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
131131
onChange={handleChange}
132132
onBlur={handleBlur}
133133
value={values.consumerSecret}
134-
disabled={!isEditable}
134+
135135
/>
136136
{isInvalidConsumerSecret && (
137137
<Form.Control.Feedback type="invalid" hasIcon={false}>
@@ -145,7 +145,7 @@ const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
145145
onChange={handleChange}
146146
onBlur={handleBlur}
147147
value={values.launchUrl}
148-
disabled={!isEditable}
148+
149149
/>
150150
{isInvalidLaunchUrl && (
151151
<Form.Control.Feedback type="invalid" hasIcon={false}>
@@ -166,7 +166,7 @@ const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
166166
onBlur={handleBlur}
167167
checked={values.piiShareUsername}
168168
label={intl.formatMessage(messages.piiShareUsername)}
169-
disabled={!isEditable}
169+
170170
/>
171171
<Form.Check
172172
type="checkbox"
@@ -175,7 +175,7 @@ const LtiConfigForm = ({ onSubmit, formRef, isEditable = false }) => {
175175
onBlur={handleBlur}
176176
checked={values.piiShareEmail}
177177
label={intl.formatMessage(messages.piiShareEmail)}
178-
disabled={!isEditable}
178+
179179
/>
180180
</Form.Group>
181181
</div>
@@ -194,7 +194,6 @@ LtiConfigForm.propTypes = {
194194
onSubmit: PropTypes.func.isRequired,
195195
// eslint-disable-next-line react/forbid-prop-types
196196
formRef: PropTypes.object.isRequired,
197-
isEditable: PropTypes.bool,
198197
};
199198

200199
export default LtiConfigForm;

src/pages-and-resources/discussions/app-config-form/apps/openedx/OpenedXConfigForm.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const OpenedXConfigForm = ({
2525
onSubmit,
2626
formRef,
2727
legacy,
28-
isEditable = false,
2928
}) => {
3029
const intl = useIntl();
3130
const {
@@ -146,7 +145,6 @@ const OpenedXConfigForm = ({
146145
onBlur={handleBlur}
147146
onChange={handleChange}
148147
values={values}
149-
disabled={!isEditable}
150148
/>
151149
<AppConfigFormDivider thick />
152150
</>
@@ -155,15 +153,14 @@ const OpenedXConfigForm = ({
155153
onBlur={handleBlur}
156154
onChange={handleChange}
157155
values={values}
158-
disabled={!isEditable}
159156
/>
160157
<AppConfigFormDivider thick />
161-
<DiscussionTopics disabled={!isEditable} />
158+
<DiscussionTopics />
162159
<AppConfigFormDivider thick />
163-
<DivisionByGroupFields disabled={!isEditable} />
160+
<DivisionByGroupFields />
164161
<AppConfigFormDivider thick />
165-
<ReportedContentEmailNotifications disabled={!isEditable} />
166-
<DiscussionRestriction disabled={!isEditable} />
162+
<ReportedContentEmailNotifications />
163+
<DiscussionRestriction />
167164
</Form>
168165
</Card>
169166
</OpenedXConfigFormProvider>
@@ -178,7 +175,6 @@ OpenedXConfigForm.propTypes = {
178175
onSubmit: PropTypes.func.isRequired,
179176
// eslint-disable-next-line react/forbid-prop-types
180177
formRef: PropTypes.object.isRequired,
181-
isEditable: PropTypes.bool,
182178
};
183179

184180
export default OpenedXConfigForm;

src/pages-and-resources/discussions/app-config-form/apps/openedx/OpenedXConfigForm.test.jsx

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,14 @@ describe('OpenedXConfigForm', () => {
7777
axiosMock.reset();
7878
});
7979

80-
const createComponent = (onSubmit = jest.fn(), formRef = createRef(), legacy = true, isEditable = false) => {
80+
const createComponent = (onSubmit = jest.fn(), formRef = createRef(), legacy = true) => {
8181
const wrapper = render(
8282
<AppProvider store={store}>
8383
<IntlProvider locale="en">
8484
<OpenedXConfigForm
8585
onSubmit={onSubmit}
8686
formRef={formRef}
8787
legacy={legacy}
88-
isEditable={isEditable}
8988
/>
9089
</IntlProvider>
9190
</AppProvider>,
@@ -116,35 +115,6 @@ describe('OpenedXConfigForm', () => {
116115
expect(queryByText(container, messages.groupInContextSubsectionLabel.defaultMessage)).toBeInTheDocument();
117116
});
118117

119-
test('renders editable form when isEditable=true', async () => {
120-
await mockStore(legacyApiResponse);
121-
createComponent(jest.fn(), createRef(), true, true);
122-
const form = container.querySelector('form');
123-
expect(form).toBeInTheDocument();
124-
});
125-
126-
test('renders form using default isEditable=false when prop is omitted', async () => {
127-
await mockStore(legacyApiResponse);
128-
const formRef = createRef();
129-
// Render directly without isEditable to trigger the default param = false
130-
const wrapper = render(
131-
<AppProvider store={store}>
132-
<IntlProvider locale="en">
133-
<OpenedXConfigForm
134-
onSubmit={jest.fn()}
135-
formRef={formRef}
136-
legacy
137-
/>
138-
</IntlProvider>
139-
</AppProvider>,
140-
);
141-
const form = wrapper.container.querySelector('form');
142-
expect(form).toBeInTheDocument();
143-
// isEditable defaults to false — child controls should be disabled
144-
const divideByCohorts = wrapper.container.querySelector('#divideByCohorts');
145-
expect(divideByCohorts).toBeDisabled();
146-
});
147-
148118
test('calls onSubmit when the formRef is submitted', async () => {
149119
const formRef = createRef();
150120
const handleSubmit = jest.fn();

src/pages-and-resources/discussions/app-config-form/apps/shared/InContextDiscussionFields.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const InContextDiscussionFields = ({
1111
onBlur,
1212
onChange,
1313
values,
14-
disabled = false,
1514
}) => {
1615
const intl = useIntl();
1716
const {
@@ -45,13 +44,12 @@ const InContextDiscussionFields = ({
4544
)
4645
: (
4746
<FormSwitchGroup
48-
onChange={() => !disabled && setShowPopup(true)}
47+
onChange={() => setShowPopup(true)}
4948
onBlur={onBlur}
5049
id="enableGradedUnits"
5150
checked={values.enableGradedUnits}
5251
label={intl.formatMessage(messages.gradedUnitPagesLabel)}
5352
helpText={intl.formatMessage(messages.gradedUnitPagesHelp)}
54-
disabled={disabled}
5553
/>
5654
)}
5755
<AppConfigFormDivider />
@@ -62,7 +60,6 @@ const InContextDiscussionFields = ({
6260
checked={values.groupAtSubsection}
6361
label={intl.formatMessage(messages.groupInContextSubsectionLabel)}
6462
helpText={intl.formatMessage(messages.groupInContextSubsectionHelp)}
65-
disabled={disabled}
6663
/>
6764
</>
6865
);
@@ -75,7 +72,6 @@ InContextDiscussionFields.propTypes = {
7572
enableGradedUnits: PropTypes.bool,
7673
groupAtSubsection: PropTypes.bool,
7774
}).isRequired,
78-
disabled: PropTypes.bool,
7975
};
8076

8177
export default InContextDiscussionFields;

src/pages-and-resources/discussions/app-config-form/apps/shared/InContextDiscussionFields.test.jsx

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const gradedUnitLabel = messages.gradedUnitPagesLabel.defaultMessage;
1010
const defaultProps = {
1111
onBlur: jest.fn(),
1212
onChange: jest.fn(),
13-
setFieldValue: jest.fn(),
1413
values: {
1514
enableGradedUnits: false,
1615
groupAtSubsection: false,
@@ -36,18 +35,6 @@ describe('InContextDiscussionFields', () => {
3635
});
3736

3837
it('renders without crashing', () => {
39-
renderComponent();
40-
// Component renders - check for presence of expected text
41-
expect(screen.getByText(/Visibility of in-context discussions/)).toBeInTheDocument();
42-
});
43-
44-
it('renders with disabled prop', () => {
45-
renderComponent({ disabled: true });
46-
expect(screen.getByText(/Visibility of in-context discussions/)).toBeInTheDocument();
47-
});
48-
49-
it('renders with default disabled (false)', () => {
50-
// Test default param - no disabled prop passed
5138
renderComponent();
5239
expect(screen.getByText(/Visibility of in-context discussions/)).toBeInTheDocument();
5340
});
@@ -59,62 +46,28 @@ describe('InContextDiscussionFields', () => {
5946
expect(screen.getByText(/Visibility of in-context discussions/)).toBeInTheDocument();
6047
});
6148

62-
it('shows confirmation popup when toggling enableGradedUnits when not disabled', () => {
63-
renderComponent({ disabled: false });
64-
// When not disabled, clicking the switch should trigger the onChange which sets showPopup
65-
// The component should still render - we test via the callback behavior
66-
const switchControl = screen.getByLabelText(gradedUnitLabel);
67-
expect(switchControl).not.toBeDisabled();
68-
});
69-
70-
it('does NOT show popup when disabled', () => {
71-
renderComponent({ disabled: true });
72-
// When disabled, clicking should not trigger popup logic
73-
// Verify the switch is disabled
74-
const switchControl = screen.getByLabelText(gradedUnitLabel);
75-
expect(switchControl).toBeDisabled();
76-
});
77-
7849
it('shows confirmation popup and handles confirm', () => {
79-
renderComponent({ disabled: false, setFieldValue: jest.fn() });
80-
// Click the switch to show popup
50+
renderComponent({ setFieldValue: jest.fn() });
8151
const switchControl = screen.getByLabelText(gradedUnitLabel);
8252
fireEvent.click(switchControl);
83-
// Check popup appears with confirm button
8453
expect(screen.getByText(/Confirm/i)).toBeInTheDocument();
85-
// Click confirm
8654
fireEvent.click(screen.getByText(/Confirm/i));
87-
// Popup should close (no longer visible)
8855
});
8956

9057
it('shows popup with cancel labels when enableGradedUnits is already true', () => {
9158
renderComponent({
92-
disabled: false,
9359
values: { enableGradedUnits: true, groupAtSubsection: false },
9460
});
9561
const switchControl = screen.getByLabelText(gradedUnitLabel);
9662
fireEvent.click(switchControl);
97-
// Popup shows cancel-related labels (enableGradedUnits=true branch)
9863
expect(screen.getByText(/Confirm/i)).toBeInTheDocument();
9964
});
10065

10166
it('shows confirmation popup and handles cancel', () => {
102-
renderComponent({ disabled: false, setFieldValue: jest.fn() });
103-
// Click the switch to show popup
67+
renderComponent({ setFieldValue: jest.fn() });
10468
const switchControl = screen.getByLabelText(gradedUnitLabel);
10569
fireEvent.click(switchControl);
106-
// Check popup appears with cancel button
10770
expect(screen.getByText(/Cancel/i)).toBeInTheDocument();
108-
// Click cancel
10971
fireEvent.click(screen.getByText(/Cancel/i));
110-
// Popup should close (no longer visible)
111-
});
112-
113-
it('does not show popup when onChange fires with disabled=true', () => {
114-
renderComponent({ disabled: true });
115-
const switchControl = screen.getByLabelText(gradedUnitLabel);
116-
// fireEvent bypasses browser disabled-input behavior, but the !disabled guard in onChange prevents the popup
117-
fireEvent.click(switchControl);
118-
expect(screen.queryByText(/Confirm/i)).not.toBeInTheDocument();
11972
});
12073
});

0 commit comments

Comments
 (0)