Skip to content

Commit

Permalink
refactor: change isCreateBlock for shouldCreateBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Jan 29, 2025
1 parent 82e5d80 commit f350757
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ INVITE_STUDENTS_EMAIL_TO="someone@domain.com"
ENABLE_HOME_PAGE_COURSE_API_V2=true
ENABLE_CHECKLIST_QUALITY=true
ENABLE_GRADING_METHOD_IN_PROBLEMS=false
# "other" is used to test the workflow for creating blocks that aren't supported by the built-in editors
LIBRARY_SUPPORTED_BLOCKS="problem,video,html,other"
4 changes: 2 additions & 2 deletions src/editors/containers/EditorContainer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export const handleSaveClicked = ({
// eslint-disable-next-line react-hooks/rules-of-hooks
const returnUrl = useSelector(selectors.app.returnUrl);
// eslint-disable-next-line react-hooks/rules-of-hooks
const isCreateBlock = useSelector(selectors.app.isCreateBlock);
const createBlockOnSave = useSelector(selectors.app.shouldCreateBlock);
const destination = returnFunction ? '' : returnUrl;
// eslint-disable-next-line react-hooks/rules-of-hooks
const analytics = useSelector(selectors.app.analytics);
if (isCreateBlock) {
if (createBlockOnSave) {
return () => createBlock({
analytics,
content: getContent({ dispatch }),
Expand Down
6 changes: 3 additions & 3 deletions src/editors/containers/ProblemEditor/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jest.mock('../../data/redux', () => ({
selectors: {
app: {
blockValue: jest.fn(state => ({ blockValue: state })),
isCreateBlock: jest.fn(state => ({ isCreateBlock: state })),
shouldCreateBlock: jest.fn(state => ({ shouldCreateBlock: state })),
},
problem: {
problemType: jest.fn(state => ({ problemType: state })),
Expand Down Expand Up @@ -106,15 +106,15 @@ describe('ProblemEditor', () => {
expect(
mapStateToProps(testState).blockFinished,
).toEqual(
selectors.app.isCreateBlock(testState)
selectors.app.shouldCreateBlock(testState)
|| selectors.requests.isFinished(testState, { requestKey: RequestKeys.fetchBlock }),
);
});
test('advancedSettingsFinished from requests.isFinished', () => {
expect(
mapStateToProps(testState).advancedSettingsFinished,
).toEqual(
selectors.app.isCreateBlock(testState)
selectors.app.shouldCreateBlock(testState)
|| selectors.requests.isFinished(testState, { requestKey: RequestKeys.fetchAdvancedSettings }),
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/editors/containers/ProblemEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ const ProblemEditor: React.FC<Props> = ({
};

export const mapStateToProps = (state) => ({
blockFinished: selectors.app.isCreateBlock(state)
blockFinished: selectors.app.shouldCreateBlock(state)
|| selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }),
blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }),
problemType: selectors.problem.problemType(state),
blockValue: selectors.app.blockValue(state),
advancedSettingsFinished: selectors.app.isCreateBlock(state)
advancedSettingsFinished: selectors.app.shouldCreateBlock(state)
|| selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchAdvancedSettings }),
});

Expand Down
2 changes: 1 addition & 1 deletion src/editors/containers/TextEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const mapStateToProps = (state) => ({
blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }),
blockId: selectors.app.blockId(state),
showRawEditor: selectors.app.showRawEditor(state),
blockFinished: selectors.app.isCreateBlock(state)
blockFinished: selectors.app.shouldCreateBlock(state)
|| selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }),
learningContextId: selectors.app.learningContextId(state),
images: selectors.app.images(state),
Expand Down
4 changes: 2 additions & 2 deletions src/editors/containers/TextEditor/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jest.mock('../../data/redux', () => ({
selectors: {
app: {
blockValue: jest.fn(state => ({ blockValue: state })),
isCreateBlock: jest.fn(state => ({ isCreateBlock: state })),
shouldCreateBlock: jest.fn(state => ({ shouldCreateBlock: state })),
lmsEndpointUrl: jest.fn(state => ({ lmsEndpointUrl: state })),
studioEndpointUrl: jest.fn(state => ({ studioEndpointUrl: state })),
showRawEditor: jest.fn(state => ({ showRawEditor: state })),
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('TextEditor', () => {
test('blockFinished from requests.isFinished', () => {
expect(
mapStateToProps(testState).blockFinished,
).toEqual(selectors.app.isCreateBlock(testState)
).toEqual(selectors.app.shouldCreateBlock(testState)
|| selectors.requests.isFinished(testState, { requestKey: RequestKeys.fetchBlock }));
});
test('learningContextId from app.learningContextId', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/editors/containers/VideoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const VideoEditor: React.FC<EditorComponent> = ({
(state) => selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchStudioView }),
);
const isLibrary = useSelector(selectors.app.isLibrary) as boolean;
const isCreateBlock = useSelector(selectors.app.isCreateBlock) as boolean;
const isCreateWorkflow = useSelector(selectors.app.shouldCreateBlock) as boolean;
const {
error,
validateEntry,
Expand All @@ -37,7 +37,7 @@ const VideoEditor: React.FC<EditorComponent> = ({
returnFunction={returnFunction}
validateEntry={validateEntry}
>
{(isCreateBlock || studioViewFinished) ? (
{(isCreateWorkflow || studioViewFinished) ? (
<div className="video-editor">
<VideoEditorModal {...{ isLibrary }} />
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/editors/data/redux/app/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('app selectors unit tests', () => {
simpleSelectors.unitUrl,
simpleSelectors.blockValue,
selectors.isLibrary,
selectors.isCreateBlock,
selectors.shouldCreateBlock,
]);
});
describe('for library blocks', () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('app selectors unit tests', () => {
});
});
describe('component creation workflow', () => {
it('returns true if is isCreateBlock is truthy', () => {
it('returns true if is shouldCreateBlock is truthy', () => {
const { resultFunc: cb } = selectors.isInitialized;

[
Expand Down Expand Up @@ -195,9 +195,9 @@ describe('app selectors unit tests', () => {
});
});
});
describe('isCreateBlock', () => {
describe('shouldCreateBlock', () => {
it('should return false if the editor is initialized with a blockId', () => {
expect(selectors.isCreateBlock.resultFunc('block-v1:', 'text')).toEqual(false);
expect(selectors.shouldCreateBlock.resultFunc('block-v1:', 'text')).toEqual(false);
});
});
});
10 changes: 5 additions & 5 deletions src/editors/data/redux/app/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const isLibrary = createSelector(
},
);

export const isCreateBlock = createSelector(
export const shouldCreateBlock = createSelector(
[simpleSelectors.blockId,
simpleSelectors.blockType,
],
Expand All @@ -71,10 +71,10 @@ export const isInitialized = createSelector(
simpleSelectors.unitUrl,
simpleSelectors.blockValue,
isLibrary,
isCreateBlock,
shouldCreateBlock,
],
(unitUrl, blockValue, isLibraryBlock, isCreateEditor) => {
if (isCreateEditor) {
(unitUrl, blockValue, isLibraryBlock, initCreateWorkflow) => {
if (initCreateWorkflow) {
return true;
}

Expand Down Expand Up @@ -122,5 +122,5 @@ export default {
displayTitle,
analytics,
isLibrary,
isCreateBlock,
shouldCreateBlock,
};
2 changes: 1 addition & 1 deletion src/editors/data/redux/thunkActions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const createBlock = (content, returnToUnit) => (dispatch, getState) => {
};

export const uploadAsset = ({ file, setSelection }) => (dispatch, getState) => {
if (selectors.isCreateBlock(getState())) {
if (selectors.shouldCreateBlock(getState())) {
const tempFileURL = URL.createObjectURL(file);
const tempImage = {
displayName: file.name,
Expand Down
2 changes: 1 addition & 1 deletion src/editors/data/redux/thunkActions/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('app thunkActions', () => {
error,
}));
});
test.only('should call batchUploadAssets if the block has images', () => {
test('should call batchUploadAssets if the block has images', () => {
mockImageData.map(image => ({ ...image, file: 'file' }));
getState.mockReturnValueOnce({ app: { blockId: '', images: mockImageData } });
const data = { id: 'block-id' };
Expand Down

0 comments on commit f350757

Please sign in to comment.