@@ -2,13 +2,18 @@ import bindAll from 'lodash.bindall';
22import PropTypes from 'prop-types' ;
33import React from 'react' ;
44import VM from 'scratch-vm' ;
5- import { defineMessages , injectIntl , intlShape } from 'react-intl' ;
5+ import { connect } from 'react-redux' ;
6+ import { defineMessages , injectIntl , intlShape , FormattedMessage } from 'react-intl' ;
67
78import extensionLibraryContent from '../lib/libraries/extensions/index.jsx' ;
89
910import LibraryComponent from '../components/library/library.jsx' ;
1011import extensionIcon from '../components/action-menu/icon--sprite.svg' ;
1112
13+ import { toggleShowAllExtensions } from '../reducers/extension-filter' ;
14+
15+ import styles from './extension-library.css' ;
16+
1217const messages = defineMessages ( {
1318 extensionTitle : {
1419 defaultMessage : 'Choose an Extension' ,
@@ -37,9 +42,13 @@ class ExtensionLibrary extends React.PureComponent {
3742 }
3843 } ) ;
3944 bindAll ( this , [
40- 'handleItemSelect'
45+ 'handleItemSelect' ,
46+ 'handleToggleShowAllExtensions'
4147 ] ) ;
4248 }
49+ handleToggleShowAllExtensions ( event ) {
50+ this . props . onToggleShowAllExtensions ( event . target . checked ) ;
51+ }
4352 handleItemSelect ( item ) {
4453 const id = item . extensionId ;
4554 let url = item . extensionURL ? item . extensionURL : id ;
@@ -62,18 +71,54 @@ class ExtensionLibrary extends React.PureComponent {
6271 const extensionsParam = query . get ( 'extensions' ) || '' ;
6372 const showMeshV2 = extensionsParam . split ( ',' ) . includes ( 'meshV2' ) ;
6473
74+ const showAllExtensionsParam = query . get ( 'showAllExtensions' ) ;
75+ const showAllExtensions = showAllExtensionsParam === 'true' ? true :
76+ showAllExtensionsParam === 'false' ? false :
77+ this . props . showAllExtensions ;
78+
6579 const extensionLibraryThumbnailData = extensionLibraryContent
66- . filter ( extension => (
67- extension . extensionId !== 'meshV2' || showMeshV2
68- ) )
80+ . filter ( extension => {
81+ if ( extension . extensionId === 'meshV2' && ! showMeshV2 ) {
82+ return false ;
83+ }
84+ if ( ! showAllExtensions && extension . defaultHidden ) {
85+ return false ;
86+ }
87+ return true ;
88+ } )
6989 . map ( extension => ( {
7090 rawURL : extension . iconURL || extensionIcon ,
7191 ...extension
7292 } ) ) ;
93+
94+ const checkboxLabel = this . props . intl . formatMessage ( {
95+ defaultMessage : 'Show all extensions' ,
96+ description : 'Checkbox label to show all extensions including hidden ones' ,
97+ id : 'gui.extensionLibrary.showAllExtensions'
98+ } ) ;
99+
100+ const headerActions = (
101+ < label className = { styles . showAllExtensionsLabel } >
102+ < input
103+ aria-label = { checkboxLabel }
104+ checked = { showAllExtensions }
105+ className = { styles . showAllExtensionsCheckbox }
106+ type = "checkbox"
107+ onChange = { this . handleToggleShowAllExtensions }
108+ />
109+ < FormattedMessage
110+ defaultMessage = "Show all extensions"
111+ description = "Checkbox label to show all extensions including hidden ones"
112+ id = "gui.extensionLibrary.showAllExtensions"
113+ />
114+ </ label >
115+ ) ;
116+
73117 return (
74118 < LibraryComponent
75119 data = { extensionLibraryThumbnailData }
76120 filterable = { false }
121+ headerActions = { headerActions }
77122 id = "extensionLibrary"
78123 title = { this . props . intl . formatMessage ( messages . extensionTitle ) }
79124 visible = { this . props . visible }
@@ -88,8 +133,21 @@ ExtensionLibrary.propTypes = {
88133 intl : intlShape . isRequired ,
89134 onCategorySelected : PropTypes . func ,
90135 onRequestClose : PropTypes . func ,
136+ onToggleShowAllExtensions : PropTypes . func ,
137+ showAllExtensions : PropTypes . bool ,
91138 visible : PropTypes . bool ,
92139 vm : PropTypes . instanceOf ( VM ) . isRequired // eslint-disable-line react/no-unused-prop-types
93140} ;
94141
95- export default injectIntl ( ExtensionLibrary ) ;
142+ const mapStateToProps = state => ( {
143+ showAllExtensions : state . scratchGui . extensionFilter . showAllExtensions
144+ } ) ;
145+
146+ const mapDispatchToProps = dispatch => ( {
147+ onToggleShowAllExtensions : showAll => dispatch ( toggleShowAllExtensions ( showAll ) )
148+ } ) ;
149+
150+ export default connect (
151+ mapStateToProps ,
152+ mapDispatchToProps
153+ ) ( injectIntl ( ExtensionLibrary ) ) ;
0 commit comments