Skip to content
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

Fix errors and warnings in the course/lesson/question editor #7646

Merged
merged 23 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5c33f2c
Remove backwards compatibility check not needed anymore
renatho Jul 29, 2024
e8f123a
Keep Sensei stores in a global variable to avoid registering it multi…
renatho Jul 29, 2024
0737caf
Update stores to avoid multiple registration
renatho Jul 29, 2024
d6d7de7
Add a comment to explain why using a global variable
renatho Jul 29, 2024
c40364b
Update deprecated code on block toggling control
renatho Jul 29, 2024
b140f2f
Update tour store registration to avoid duplicate registrations
renatho Jul 29, 2024
5548965
Fix deprecated dependencies moved from @wordpress/edit-post to @wordp…
renatho Jul 29, 2024
e1b45aa
Fix deprecated component on the edit lesson button
renatho Jul 30, 2024
b9797b6
Fix selectBlock store
renatho Jul 30, 2024
37e3ccf
Avoid temporary Gutenberg warning
renatho Jul 30, 2024
86c638e
Update experimental prop to the new one
renatho Jul 30, 2024
8f2f806
Update removing deprecated method
renatho Jul 30, 2024
9741eac
Use edit link as a toolbar item
renatho Jul 30, 2024
84d589f
Use ToolbarDropdownMenu instead
renatho Jul 30, 2024
cbe3679
Fix question control to use ToolbarItem
renatho Jul 30, 2024
a5d570e
Fix deprecations on the question block toolbar
renatho Jul 31, 2024
7b26d2c
Update approach for using correct version of component
renatho Jul 31, 2024
3fdc54e
Fix indentation
renatho Jul 31, 2024
8bd30ce
Add apiVersion to fix depracation issue
renatho Jul 31, 2024
69a541d
Avoid unnecessary renders
renatho Jul 31, 2024
db0060f
Install rememo until it's available in our supported WP versions
renatho Jul 31, 2024
dd194af
Merge branch 'trunk' into fix/errors-and-warnings
m1r0 Aug 1, 2024
f38ab70
Fix Course Actions block deprecation
renatho Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
*/
import { __ } from '@wordpress/i18n';
import { useEntityProp } from '@wordpress/core-data';
import { PluginPrePublishPanel } from '@wordpress/edit-post';
import { PluginPrePublishPanel as DeprecatedPluginPrePublishPanel } from '@wordpress/edit-post';
import { PluginPrePublishPanel as NewPluginPrePublishPanel } from '@wordpress/editor';
import { ToggleControl } from '@wordpress/components';

/**
* Internal dependencies
*/
import SenseiIcon from '../../icons/logo-tree.svg';

const PluginPrePublishPanel =
NewPluginPrePublishPanel || DeprecatedPluginPrePublishPanel;

/**
* Course pre-publish panel.
*/
Expand Down
4 changes: 3 additions & 1 deletion assets/admin/editor-wizard/patterns-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ const PatternsList = ( { onChoose } ) => {
>
<div className="sensei-patterns-list__item-preview">
<BlockPreview
__experimentalPadding={ 30 }
additionalStyles={ [
{ css: 'body { padding: 30px; }' },
] }
blocks={ blocks
.filter( withoutLessonActions )
.map( withBlockExample ) }
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/tour/course-tour/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function focusOnCourseOutlineBlock() {
if ( ! courseOutlineBlock ) {
return;
}
dispatch( editorStore ).selectBlock( courseOutlineBlock.clientId );
dispatch( blockEditorStore ).selectBlock( courseOutlineBlock.clientId );
}

async function ensureLessonBlocksIsInEditor() {
Expand Down
17 changes: 8 additions & 9 deletions assets/admin/tour/data/store.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* WordPress dependencies
*/
import { createReduxStore, register } from '@wordpress/data';
/**
* Internal dependencies
*/
import { createReducerFromActionMap } from '../../../shared/data/store-helpers';
import { controls } from '@wordpress/data-controls';
import apiFetch from '@wordpress/api-fetch';

export const SENSEI_TOUR_STORE = 'sensei/tour';
/**
* Internal dependencies
*/
import {
createReducerFromActionMap,
createStore,
} from '../../../shared/data/store-helpers';

export const DEFAULT_STATE = {
showTour: true,
Expand Down Expand Up @@ -80,11 +81,9 @@ export const reducers = {
DEFAULT: ( action, state ) => state,
};

export const store = createReduxStore( SENSEI_TOUR_STORE, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The store import is not used anywhere.

export const SENSEI_TOUR_STORE = createStore( 'sensei/tour', {
donnapep marked this conversation as resolved.
Show resolved Hide resolved
reducer: createReducerFromActionMap( reducers, DEFAULT_STATE ),
actions,
selectors,
controls,
} );

register( store );
7 changes: 3 additions & 4 deletions assets/admin/tour/lesson-tour/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ExternalLink } from '@wordpress/components';
import { select, dispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as editPostStore } from '@wordpress/edit-post';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -59,23 +58,23 @@ export const focusOnQuizBlock = () => {
if ( ! quizBlock ) {
return;
}
dispatch( editorStore ).selectBlock( quizBlock.clientId );
dispatch( blockEditorStore ).selectBlock( quizBlock.clientId );
};

export const focusOnQuestionBlock = () => {
const questionBlock = getFirstQuestionBlock();
if ( ! questionBlock ) {
return;
}
dispatch( editorStore ).selectBlock( questionBlock.clientId );
dispatch( blockEditorStore ).selectBlock( questionBlock.clientId );
};

export const focusOnBooleanQuestionBlock = () => {
const questionBlock = getFirstBooleanQuestionBlock();
if ( ! questionBlock ) {
return;
}
dispatch( editorStore ).selectBlock( questionBlock.clientId );
dispatch( blockEditorStore ).selectBlock( questionBlock.clientId );
};

export const ensureBooleanQuestionIsInEditor = () => {
Expand Down
6 changes: 3 additions & 3 deletions assets/blocks/course-actions-block/course-status-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { Toolbar } from '@wordpress/components';
import { ToolbarGroup } from '@wordpress/components';
import { useContext } from '@wordpress/element';

/**
Expand Down Expand Up @@ -41,14 +41,14 @@ const CourseStatusToolbar = ( {
: setCourseStatus;

return (
<Toolbar>
<ToolbarGroup>
<ToolbarDropdown
options={ CourseStatusOptions }
optionsLabel="Course Status"
value={ courseStatusValue }
onChange={ setCourseStatusCallback }
/>
</Toolbar>
</ToolbarGroup>
);
};

Expand Down
37 changes: 27 additions & 10 deletions assets/blocks/course-outline/lesson-block/lesson-edit-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* WordPress dependencies
*/
import { Button, Spinner, Toolbar, ToolbarItem } from '@wordpress/components';
import {
Button,
Spinner,
ToolbarGroup,
ToolbarItem,
} from '@wordpress/components';
import { forwardRef } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';
import { store as editorStore } from '@wordpress/editor';
Expand All @@ -19,14 +25,19 @@ const getLessonURL = ( lessonId ) => `post.php?post=${ lessonId }&action=edit`;
*
* @param {Object} props Component props.
* @param {number} props.lessonId The lesson ID.
* @param {Object} forwardedRef The forwarded ref.
*/
export const EditLessonLink = ( { lessonId } ) => (
<a
href={ getLessonURL( lessonId ) }
className="wp-block-sensei-lms-course-outline-lesson__edit"
>
{ __( 'Edit lesson', 'sensei-lms' ) }
</a>
export const EditLessonLink = forwardRef(
( { lessonId, ...props }, forwardedRef ) => (
<a
ref={ forwardedRef }
href={ getLessonURL( lessonId ) }
className="wp-block-sensei-lms-course-outline-lesson__edit"
{ ...props }
>
{ __( 'Edit lesson', 'sensei-lms' ) }
</a>
)
);

/**
Expand Down Expand Up @@ -70,12 +81,18 @@ const LessonEditToolbar = ( { lessonId, lessonTitle } ) => {

let toolbarItem = savePostLink;
if ( lessonId ) {
toolbarItem = <EditLessonLink lessonId={ lessonId } />;
toolbarItem = (
<ToolbarItem as={ EditLessonLink } lessonId={ lessonId } />
);
} else if ( isSavingPost || isSavingStructure || isSavingMetaBoxes ) {
toolbarItem = savingPostIndicator;
}

return <Toolbar className="components-button">{ toolbarItem }</Toolbar>;
return (
<ToolbarGroup className="components-button">
{ toolbarItem }
</ToolbarGroup>
);
};

export default LessonEditToolbar;
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const LessonSettings = ( {
) }
<PanelBody title={ __( 'Typography', 'sensei-lms' ) }>
<FontSizePicker
__nextHasNoMarginBottom // Can be removed when we support WP 6.5+
fontSizes={ fontSizes }
value={ fontSize }
onChange={ ( value ) => {
Expand Down
11 changes: 6 additions & 5 deletions assets/blocks/course-outline/status-preview/status-store.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/**
* WordPress dependencies
*/
import { select as selectData, registerStore } from '@wordpress/data';
import { select as selectData } from '@wordpress/data';

/**
* Internal dependencies
*/
import { Status } from './index';
import { select, controls } from '@wordpress/data-controls';
import { createReducerFromActionMap } from '../../../shared/data/store-helpers';
import {
createStore,
createReducerFromActionMap,
} from '../../../shared/data/store-helpers';

const DEFAULT_STATE = {
completedLessons: [],
Expand Down Expand Up @@ -311,9 +314,7 @@ const reducers = {
DEFAULT: ( action, state ) => state,
};

export const COURSE_STATUS_STORE = 'sensei/course-status';

registerStore( COURSE_STATUS_STORE, {
export const COURSE_STATUS_STORE = createStore( 'sensei/course-status', {
reducer: createReducerFromActionMap( reducers, DEFAULT_STATE ),
actions,
selectors,
Expand Down
1 change: 1 addition & 0 deletions assets/blocks/course-progress-block/block.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiVersion": 2,
"name": "sensei-lms/course-progress",
"title": "Course Progress",
"description": "Display the user's progress in the course. This block is only displayed if the user is enrolled.",
Expand Down
91 changes: 41 additions & 50 deletions assets/blocks/editor-components/toolbar-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import {
Button,
Dropdown,
MenuGroup,
MenuItem,
NavigableMenu,
ToolbarDropdownMenu,
} from '@wordpress/components';
import { check } from '@wordpress/icons';

Expand Down Expand Up @@ -48,10 +46,10 @@ const ToolbarDropdown = ( {
const selectedOption = options.find( ( option ) => value === option.value );

return (
<Dropdown
<ToolbarDropdownMenu
className="sensei-toolbar-dropdown"
popoverProps={ {
isAlternate: true,
variant: 'toolbar',
position: 'bottom right left',
focusOnMount: true,
...popoverProps,
Expand All @@ -60,52 +58,45 @@ const ToolbarDropdown = ( {
'sensei-toolbar-dropdown__popover'
),
} }
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
onClick={ onToggle }
icon={ icon }
aria-expanded={ isOpen }
aria-haspopup="true"
{ ...toggleProps }
children={
toggleProps?.children
? toggleProps.children( selectedOption )
: selectedOption?.label
}
/>
) }
renderContent={ ( { onClose } ) => (
<NavigableMenu role="menu" stopNavigationEvents>
<MenuGroup label={ optionsLabel }>
{ options.map( ( option ) => {
const isSelected =
option.value === selectedOption?.value;
const menuItemProps = getMenuItemProps?.( option );
return (
<MenuItem
key={ option.value }
role="menuitemradio"
isSelected={ isSelected }
icon={ isSelected ? check : null }
className={ classnames(
'sensei-toolbar-dropdown__option',
{ 'is-selected': isSelected },
menuItemProps?.className
) }
onClick={ () => {
onChange( option.value );
onClose();
} }
children={ option.label }
{ ...menuItemProps }
/>
);
} ) }
</MenuGroup>
</NavigableMenu>
) }
label={ optionsLabel }
icon={ icon ?? null }
text={
toggleProps?.children
? toggleProps.children( selectedOption )
: selectedOption?.label
}
{ ...props }
/>
>
{ ( { onClose } ) => (
<MenuGroup label={ optionsLabel }>
{ options.map( ( option ) => {
const isSelected =
option.value === selectedOption?.value;
const menuItemProps = getMenuItemProps?.( option );

return (
<MenuItem
key={ option.value }
role="menuitemradio"
isSelected={ isSelected }
icon={ isSelected ? check : null }
className={ classnames(
'sensei-toolbar-dropdown__option',
{ 'is-selected': isSelected },
menuItemProps?.className
) }
onClick={ () => {
onChange( option.value );
onClose();
} }
children={ option.label }
{ ...menuItemProps }
/>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
);
};

Expand Down
4 changes: 2 additions & 2 deletions assets/blocks/featured-video/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "sensei-lms/featured-video",
"title": "Featured Video",
"description": "Add a featured video to your lesson to highlight the video and make use of our video templates.",
"icon": "format-video",
"icon": "format-video",
"category": "sensei-lms",
"textdomain": "sensei-lms",
"supports": {
"multiple": false
"multiple": false
}
}
Loading
Loading