@@ -42,7 +42,10 @@ import {
4242 TYPE_FOLDER ,
4343 CLIENT_NAME_CONTENT_EXPLORER ,
4444 DEFAULT_VIEW_FILES ,
45- DEFAULT_VIEW_RECENTS
45+ DEFAULT_VIEW_RECENTS ,
46+ ERROR_CODE_ITEM_NAME_INVALID ,
47+ ERROR_CODE_ITEM_NAME_TOO_LONG ,
48+ ERROR_CODE_ITEM_NAME_IN_USE
4649} from '../../constants' ;
4750import type {
4851 BoxItem ,
@@ -238,6 +241,17 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
238241 this . api . destroy ( true ) ;
239242 }
240243
244+ /**
245+ * Cleanup
246+ *
247+ * @private
248+ * @inheritdoc
249+ * @return {void }
250+ */
251+ componentWillUnmount ( ) {
252+ this . clearCache ( ) ;
253+ }
254+
241255 /**
242256 * Fetches the root folder on load
243257 *
@@ -258,6 +272,21 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
258272 }
259273 }
260274
275+ /**
276+ * react-modal expects the Modals app element
277+ * to be set so that it can add proper aria tags.
278+ * We need to keep setting it, since there might be
279+ * multiple widgets on the same page with their own
280+ * app elements.
281+ *
282+ * @private
283+ * @param {Object } collection item collection object
284+ * @return {void }
285+ */
286+ setModalAppElement ( ) {
287+ Modal . setAppElement ( this . appElement ) ;
288+ }
289+
261290 /**
262291 * Fetches the current folder if different
263292 * from what was already fetched before.
@@ -406,21 +435,6 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
406435 ) ;
407436 } ;
408437
409- /**
410- * react-modal expects the Modals app element
411- * to be set so that it can add proper aria tags.
412- * We need to keep setting it, since there might be
413- * multiple widgets on the same page with their own
414- * app elements.
415- *
416- * @private
417- * @param {Object } collection item collection object
418- * @return {void }
419- */
420- setModalAppElement ( ) {
421- Modal . setAppElement ( this . appElement ) ;
422- }
423-
424438 /**
425439 * Action performed when clicking on an item
426440 *
@@ -901,7 +915,7 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
901915
902916 const name = `${ nameWithoutExt } ${ extension } ` ;
903917 if ( ! nameWithoutExt . trim ( ) ) {
904- this . setState ( { errorCode : 'item_name_invalid' , isLoading : false } ) ;
918+ this . setState ( { errorCode : ERROR_CODE_ITEM_NAME_INVALID , isLoading : false } ) ;
905919 return ;
906920 }
907921
@@ -965,12 +979,12 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
965979 }
966980
967981 if ( ! name ) {
968- this . setState ( { errorCode : 'item_name_invalid' , isLoading : false } ) ;
982+ this . setState ( { errorCode : ERROR_CODE_ITEM_NAME_INVALID , isLoading : false } ) ;
969983 return ;
970984 }
971985
972986 if ( name . length > 255 ) {
973- this . setState ( { errorCode : 'item_name_too_long' , isLoading : false } ) ;
987+ this . setState ( { errorCode : ERROR_CODE_ITEM_NAME_TOO_LONG , isLoading : false } ) ;
974988 return ;
975989 }
976990
@@ -985,7 +999,7 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
985999 } ,
9861000 ( { response : { status } } ) => {
9871001 this . setState ( {
988- errorCode : status === 409 ? 'item_name_in_use' : 'item_name_invalid' ,
1002+ errorCode : status === 409 ? ERROR_CODE_ITEM_NAME_IN_USE : ERROR_CODE_ITEM_NAME_INVALID ,
9891003 isLoading : false
9901004 } ) ;
9911005 }
0 commit comments