@automattic/jetpack-shared-extension-utils 0.13.4 → 0.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.13.6] - 2024-01-02
9
+ ### Added
10
+ - Added prefilling for jetpack modules data during store initialization. [#34794]
11
+
12
+ ### Changed
13
+ - Made module updates more precise inside the modules store. [#34801]
14
+
15
+ ## [0.13.5] - 2023-12-19
16
+ ### Changed
17
+ - Updated package dependencies. [#34694]
18
+
8
19
  ## [0.13.4] - 2023-12-06
9
20
  ### Changed
10
21
  - Updated package dependencies. [#34416]
@@ -298,6 +309,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
298
309
  ### Changed
299
310
  - Core: prepare utility for release
300
311
 
312
+ [0.13.6]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.13.5...0.13.6
313
+ [0.13.5]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.13.4...0.13.5
301
314
  [0.13.4]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.13.3...0.13.4
302
315
  [0.13.3]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.13.2...0.13.3
303
316
  [0.13.2]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.13.1...0.13.2
package/README.md CHANGED
@@ -51,11 +51,11 @@ const SampleComponent = props => {
51
51
  // Jetpack modules will be pulled after first selection `isModuleActive`.
52
52
  export default compose( [
53
53
  withSelect( ( select, props ) => {
54
- const { isModuleActive, areModulesLoading, areModulesUpdating } = select( 'jetpack-modules' );
54
+ const { isModuleActive, areModulesLoading, isModuleUpdating } = select( 'jetpack-modules' );
55
55
  return {
56
56
  isModuleActive: isModuleActive( 'contact-form' ),
57
57
  isLoadingModules: areModulesLoading(),
58
- isChangingStatus: areModulesUpdating(),
58
+ isChangingStatus: isModuleUpdating( 'contact-form' ),
59
59
  };
60
60
  } ),
61
61
  withDispatch( dispatch => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-shared-extension-utils",
3
- "version": "0.13.4",
3
+ "version": "0.13.6",
4
4
  "description": "Utility functions used by the block editor extensions",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/shared-extension-utils/#readme",
6
6
  "bugs": {
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@automattic/jetpack-analytics": "^0.1.29",
21
- "@automattic/jetpack-components": "^0.45.5",
22
- "@automattic/jetpack-connection": "^0.30.10",
21
+ "@automattic/jetpack-components": "^0.45.9",
22
+ "@automattic/jetpack-connection": "^0.30.11",
23
23
  "@wordpress/api-fetch": "6.44.0",
24
24
  "@wordpress/compose": "6.24.0",
25
25
  "@wordpress/data": "9.17.0",
@@ -39,8 +39,8 @@
39
39
  "react-dom": "18.2.0",
40
40
  "jetpack-js-tools": "workspace:*",
41
41
  "@automattic/jetpack-webpack-config": "workspace:*",
42
- "@testing-library/dom": "8.20.1",
43
- "@testing-library/react": "13.4.0",
42
+ "@testing-library/dom": "9.3.3",
43
+ "@testing-library/react": "14.1.2",
44
44
  "@testing-library/user-event": "14.5.1",
45
45
  "@babel/plugin-transform-react-jsx": "7.23.4",
46
46
  "@wordpress/babel-plugin-import-jsx-pragma": "4.30.0"
@@ -7,6 +7,7 @@ import {
7
7
  import { JETPACK_MODULES_STORE_ID } from '.';
8
8
 
9
9
  export const SET_JETPACK_MODULES = 'SET_JETPACK_MODULES';
10
+ export const SET_MODULE_UPDATING = 'SET_MODULE_UPDATING';
10
11
 
11
12
  /**
12
13
  * Yield actions to update module status
@@ -20,7 +21,7 @@ export const SET_JETPACK_MODULES = 'SET_JETPACK_MODULES';
20
21
  export function* updateJetpackModuleStatus( settings ) {
21
22
  try {
22
23
  const originalData = select( JETPACK_MODULES_STORE_ID ).getJetpackModules();
23
- yield setIsUpdating( true );
24
+ yield setIsUpdating( settings.name, true );
24
25
  if ( originalData.data?.[ settings.name ]?.activated !== settings.active ) {
25
26
  yield setJetpackModules( originalData );
26
27
  }
@@ -33,7 +34,7 @@ export function* updateJetpackModuleStatus( settings ) {
33
34
  yield setJetpackModules( oldSettings );
34
35
  return false;
35
36
  } finally {
36
- yield setIsUpdating( false );
37
+ yield setIsUpdating( settings.name, false );
37
38
  }
38
39
  }
39
40
 
@@ -74,11 +75,12 @@ function setIsLoading( isLoading ) {
74
75
  /**
75
76
  * Set modules as updating action
76
77
  *
78
+ * @param {string} name - Name of the module.
77
79
  * @param {boolean} isUpdating - If the modules are updating or not.
78
80
  * @returns {object} - an action object.
79
81
  */
80
- function setIsUpdating( isUpdating ) {
81
- return setJetpackModules( { isUpdating } );
82
+ function setIsUpdating( name, isUpdating ) {
83
+ return { type: SET_MODULE_UPDATING, name, isUpdating };
82
84
  }
83
85
 
84
86
  /**
@@ -1,4 +1,4 @@
1
- import { createReduxStore, register } from '@wordpress/data';
1
+ import { createReduxStore, register, dispatch } from '@wordpress/data';
2
2
  import actions from './actions';
3
3
  import controls from './controls';
4
4
  import reducer from './reducer';
@@ -6,7 +6,6 @@ import resolvers from './resolvers';
6
6
  import selectors from './selectors';
7
7
 
8
8
  export const JETPACK_MODULES_STORE_ID = 'jetpack-modules';
9
-
10
9
  const store = createReduxStore( JETPACK_MODULES_STORE_ID, {
11
10
  reducer,
12
11
  actions,
@@ -14,4 +13,18 @@ const store = createReduxStore( JETPACK_MODULES_STORE_ID, {
14
13
  resolvers,
15
14
  selectors,
16
15
  } );
16
+
17
17
  register( store );
18
+
19
+ const initialData =
20
+ window?.Initial_State?.getModules || // Jetpack Dashboard
21
+ window?.Jetpack_Editor_Initial_State?.modules || // Gutenberg
22
+ null;
23
+
24
+ // This is a temporary fix to have store filled properly.
25
+ // TODO: Create a proper solution after fixing initial issue (https://github.com/Automattic/jetpack/issues/34793).
26
+ if ( initialData !== null ) {
27
+ dispatch( JETPACK_MODULES_STORE_ID ).setJetpackModules( {
28
+ data: { ...initialData },
29
+ } );
30
+ }
@@ -1,6 +1,6 @@
1
1
  const defaultState = {
2
2
  isLoading: false,
3
- isUpdating: false,
3
+ isUpdating: {},
4
4
  data: {},
5
5
  };
6
6
 
@@ -11,6 +11,16 @@ const setModulesData = ( state = defaultState, action ) => {
11
11
  ...state,
12
12
  ...action.options,
13
13
  };
14
+ case 'SET_MODULE_UPDATING':
15
+ return {
16
+ ...state,
17
+ ...{
18
+ isUpdating: {
19
+ ...state.isUpdating,
20
+ [ action.name ]: action.isUpdating,
21
+ },
22
+ },
23
+ };
14
24
  }
15
25
  return state;
16
26
  };
@@ -1,4 +1,4 @@
1
- import { setJetpackModules, fetchModules } from './actions';
1
+ import { setJetpackModules } from './actions';
2
2
  import { fetchJetpackModules } from './controls';
3
3
 
4
4
  /**
@@ -18,13 +18,4 @@ export function* getJetpackModules() {
18
18
  }
19
19
  }
20
20
 
21
- /**
22
- * When requesting data on particular module
23
- * we want to make sure to have the latest state
24
- * @returns {boolean} - if action was completed successfully.
25
- */
26
- export function isModuleActive() {
27
- return fetchModules();
28
- }
29
-
30
- export default { getJetpackModules, isModuleActive };
21
+ export default { getJetpackModules };
@@ -7,7 +7,7 @@ const jetpackModulesSelectors = {
7
7
  isModuleActive: ( state, moduleName ) =>
8
8
  isSimpleSite() || ( state?.data?.[ moduleName ]?.activated ?? false ),
9
9
  areModulesLoading: state => state.isLoading ?? false,
10
- areModulesUpdating: state => state.isUpdating ?? false,
10
+ isModuleUpdating: ( state, moduleName ) => state?.isUpdating?.[ moduleName ] ?? false,
11
11
  };
12
12
 
13
13
  export default jetpackModulesSelectors;