asab_webui_components 26.1.2 → 26.1.3

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/README.md CHANGED
@@ -42,6 +42,7 @@ Possible imports:
42
42
  - removeFileExtension
43
43
  - deepMerge
44
44
  - problemMarkers
45
+ - AppStoreProvider, useAppStore, useAppSelector, createAppStore, registerReducer
45
46
 
46
47
  ## Documentation
47
48
 
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.AppStoreProvider = AppStoreProvider;
8
+ exports.createAppStore = createAppStore;
8
9
  exports.useAppSelector = useAppSelector;
9
10
  exports.useAppStore = useAppStore;
10
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -19,6 +20,65 @@ function combineReducers(reducers) {
19
20
  [key]: reducers[key](state[key], action)
20
21
  }), state);
21
22
  }
23
+
24
+ /*
25
+ Method to create app store
26
+
27
+ Usage:
28
+
29
+ class Application extends Component {
30
+
31
+ ...
32
+
33
+ constructor(props) {
34
+ super(props);
35
+
36
+ // Global AppStore variables
37
+ this.AppStore = createAppStore();
38
+
39
+ ...
40
+
41
+ <AppStoreProvider app={this}>
42
+ ...
43
+
44
+
45
+ }
46
+
47
+ const state = this.App.AppStore.getState();
48
+ this.App.AppStore.dispatch({type: "myType", payload: ["abc", "def"]})
49
+ */
50
+ function createAppStore() {
51
+ // Get the initial states
52
+ var initialState = (0, _reducerRegistry.getInitialStates)();
53
+ var rootReducer = (state, action) => {
54
+ // Get the latest reducers
55
+ var reducers = (0, _reducerRegistry.getReducers)();
56
+ return combineReducers(reducers)(state, action);
57
+ };
58
+ return {
59
+ // State of the store
60
+ state: initialState,
61
+ // Listeners for subscriber methods - used for notification if something new is added to the store (dynamic update)
62
+ listeners: [],
63
+ // Get the current state
64
+ getState() {
65
+ return this.state;
66
+ },
67
+ // Update the state by dispatching an action
68
+ dispatch(action) {
69
+ this.state = rootReducer(this.state, action);
70
+ // Notify all subscribers of the action about the update
71
+ this.listeners.forEach(fn => fn(this.state));
72
+ },
73
+ // Subscribe a new listener
74
+ subscribe(fn) {
75
+ this.listeners.push(fn);
76
+ return () => {
77
+ this.listeners = this.listeners.filter(l => l !== fn);
78
+ };
79
+ }
80
+ };
81
+ }
22
82
  var AppStoreContext = /*#__PURE__*/(0, _react.createContext)();
23
83
 
24
84
  // App store
@@ -30,18 +90,30 @@ function AppStoreProvider(_ref) {
30
90
  // Keep the initial state from the registry at mount
31
91
  var initialState = (0, _reducerRegistry.getInitialStates)();
32
92
  // Pulls the current reducer set on every action:
33
- var reducerFn = (0, _react.useCallback)((state, action) => {
34
- return combineReducers((0, _reducerRegistry.getReducers)())(state, action);
35
- }, []);
93
+ var reducerFn = (0, _react.useCallback)((state, action) => combineReducers((0, _reducerRegistry.getReducers)())(state, action), []);
36
94
  var [state, dispatch] = (0, _react.useReducer)(reducerFn, initialState);
37
95
 
96
+ // Wrapped dispatch to update both React state and global AppStore.state
97
+ var wrappedDispatch = action => {
98
+ // First, dispatch to React reducer
99
+ dispatch(action);
100
+
101
+ // Immediately compute the new state manually
102
+ // This ensures this.AppStore.state is always in sync
103
+ var newState = reducerFn(app.AppStore.state, action);
104
+ app.AppStore.state = newState;
105
+
106
+ // Notify listeners (if there is a manual update)
107
+ app.AppStore.listeners.forEach(fn => fn(newState));
108
+ };
109
+
38
110
  // Set the global dispatch and state references
39
- app.AppStore.dispatch = dispatch;
40
- app.AppStore.state = state;
111
+ app.AppStore.state = state; // Initial reference
112
+ app.AppStore.dispatch = wrappedDispatch;
41
113
  return /*#__PURE__*/_react.default.createElement(AppStoreContext.Provider, {
42
114
  value: {
43
115
  state,
44
- dispatch
116
+ dispatch: wrappedDispatch
45
117
  }
46
118
  }, children);
47
119
  }
@@ -14,6 +14,66 @@ function combineReducers(reducers) {
14
14
  );
15
15
  }
16
16
 
17
+ /*
18
+ Method to create app store
19
+
20
+ Usage:
21
+
22
+ class Application extends Component {
23
+
24
+ ...
25
+
26
+ constructor(props) {
27
+ super(props);
28
+
29
+ // Global AppStore variables
30
+ this.AppStore = createAppStore();
31
+
32
+ ...
33
+
34
+ <AppStoreProvider app={this}>
35
+ ...
36
+
37
+
38
+ }
39
+
40
+ const state = this.App.AppStore.getState();
41
+ this.App.AppStore.dispatch({type: "myType", payload: ["abc", "def"]})
42
+ */
43
+ export function createAppStore() {
44
+ // Get the initial states
45
+ const initialState = getInitialStates();
46
+ const rootReducer = (state, action) => {
47
+ // Get the latest reducers
48
+ const reducers = getReducers();
49
+ return combineReducers(reducers)(state, action);
50
+ };
51
+
52
+ return {
53
+ // State of the store
54
+ state: initialState,
55
+ // Listeners for subscriber methods - used for notification if something new is added to the store (dynamic update)
56
+ listeners: [],
57
+ // Get the current state
58
+ getState() {
59
+ return this.state;
60
+ },
61
+ // Update the state by dispatching an action
62
+ dispatch(action) {
63
+ this.state = rootReducer(this.state, action);
64
+ // Notify all subscribers of the action about the update
65
+ this.listeners.forEach(fn => fn(this.state));
66
+ },
67
+ // Subscribe a new listener
68
+ subscribe(fn) {
69
+ this.listeners.push(fn);
70
+ return () => {
71
+ this.listeners = this.listeners.filter(l => l !== fn);
72
+ }
73
+ }
74
+ };
75
+ }
76
+
17
77
  const AppStoreContext = createContext();
18
78
 
19
79
  // App store
@@ -21,18 +81,30 @@ export function AppStoreProvider({ children, app }) {
21
81
  // Keep the initial state from the registry at mount
22
82
  const initialState = getInitialStates();
23
83
  // Pulls the current reducer set on every action:
24
- const reducerFn = useCallback((state, action) => {
25
- return combineReducers(getReducers())(state, action);
26
- }, []);
84
+ const reducerFn = useCallback((state, action) => combineReducers(getReducers())(state, action), []);
27
85
 
28
86
  const [state, dispatch] = useReducer(reducerFn, initialState);
29
87
 
88
+ // Wrapped dispatch to update both React state and global AppStore.state
89
+ const wrappedDispatch = (action) => {
90
+ // First, dispatch to React reducer
91
+ dispatch(action);
92
+
93
+ // Immediately compute the new state manually
94
+ // This ensures this.AppStore.state is always in sync
95
+ const newState = reducerFn(app.AppStore.state, action);
96
+ app.AppStore.state = newState;
97
+
98
+ // Notify listeners (if there is a manual update)
99
+ app.AppStore.listeners.forEach(fn => fn(newState));
100
+ };
101
+
30
102
  // Set the global dispatch and state references
31
- app.AppStore.dispatch = dispatch;
32
- app.AppStore.state = state;
103
+ app.AppStore.state = state; // Initial reference
104
+ app.AppStore.dispatch = wrappedDispatch;
33
105
 
34
106
  return (
35
- <AppStoreContext.Provider value={{ state, dispatch }}>
107
+ <AppStoreContext.Provider value={{ state, dispatch: wrappedDispatch }}>
36
108
  {children}
37
109
  </AppStoreContext.Provider>
38
110
  );
@@ -76,9 +76,6 @@ function splDatetimeToIso(datetime) {
76
76
  // Microsecond extraction (bits 0-20)
77
77
  var microsecond = Number(datetime & BigInt(0b111111111111111111111)); // 20 bits
78
78
 
79
- // Adjust for zero-based month
80
- month += 1;
81
-
82
79
  // Check if the values are correct
83
80
  if (year < 0 || month < 1 || month > 12 || day < 1 || day > 31 || hour > 23 || minute > 59 || second > 59) {
84
81
  return 'Invalid Date';
@@ -71,9 +71,6 @@ function splDatetimeToIso(datetime) {
71
71
  // Microsecond extraction (bits 0-20)
72
72
  const microsecond = Number(datetime & BigInt(0b111111111111111111111)); // 20 bits
73
73
 
74
- // Adjust for zero-based month
75
- month += 1;
76
-
77
74
  // Check if the values are correct
78
75
  if (
79
76
  year < 0 || month < 1 || month > 12 ||
package/dist/index.js CHANGED
@@ -184,6 +184,12 @@ Object.defineProperty(exports, "classifyIPAddress", {
184
184
  return _classifyIPAddress.classifyIPAddress;
185
185
  }
186
186
  });
187
+ Object.defineProperty(exports, "createAppStore", {
188
+ enumerable: true,
189
+ get: function get() {
190
+ return _AppStore.createAppStore;
191
+ }
192
+ });
187
193
  Object.defineProperty(exports, "deepMerge", {
188
194
  enumerable: true,
189
195
  get: function get() {
@@ -29,7 +29,7 @@ function Credentials(_ref) {
29
29
  if (credentials_id == undefined) {
30
30
  return '';
31
31
  }
32
- var resources = ((_app$AppStore = app.AppStore) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.state) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.auth) === null || _app$AppStore === void 0 ? void 0 : _app$AppStore.resources) || [];
32
+ var resources = ((_app$AppStore = app.AppStore) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.getState()) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.auth) === null || _app$AppStore === void 0 ? void 0 : _app$AppStore.resources) || [];
33
33
  var resource = 'seacat:credentials:access'; // Resource required to access the Credentials List Screen
34
34
 
35
35
  // Validation on props.app
@@ -22,6 +22,6 @@ Usage:
22
22
 
23
23
  function isAuthorized(resourcesArray, app) {
24
24
  var _app$AppStore;
25
- var resources = (app === null || app === void 0 || (_app$AppStore = app.AppStore) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.state) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.auth) === null || _app$AppStore === void 0 ? void 0 : _app$AppStore.resources) || [];
25
+ var resources = (app === null || app === void 0 || (_app$AppStore = app.AppStore) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.getState()) === null || _app$AppStore === void 0 || (_app$AppStore = _app$AppStore.auth) === null || _app$AppStore === void 0 ? void 0 : _app$AppStore.resources) || [];
26
26
  return resources.includes('authz:superuser') || resourcesArray.some(resource => resources.includes(resource));
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_components",
3
- "version": "26.1.2",
3
+ "version": "26.1.3",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Components Library",
6
6
  "contributors": [