@axinom/mosaic-fe-samples-host 0.2.1-rc.8 → 0.2.1

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
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ### [0.2.1](https://dev.azure.com/axinom/CMS/_git/Navy/branchCompare?baseVersion=GT@axinom/mosaic-fe-samples-host@0.2.0&targetVersion=GT@axinom/mosaic-fe-samples-host@0.2.1) (2022-11-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fe-sample-host active-profile bug fix ([0e7ffd3](https://dev.azure.com/axinom/CMS/_git/Navy/commit/0e7ffd3b6c4f680ee69b38bd3eae793a6158657a))
12
+
13
+
14
+
6
15
  ## [0.2.0](https://dev.azure.com/axinom/CMS/_git/Navy/branchCompare?baseVersion=GT@axinom/mosaic-fe-samples-host@0.1.4&targetVersion=GT@axinom/mosaic-fe-samples-host@0.2.0) (2022-10-17)
7
16
 
8
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"ScenarioHost.d.ts","sourceRoot":"","sources":["../../src/ScenarioHost/ScenarioHost.tsx"],"names":[],"mappings":"AACA,OAAO,KAMN,MAAM,OAAO,CAAC;AAaf,OAAO,EAAa,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAa7E,oBAAY,iBAAiB,GAAG;IAC9B,SAAS,EAAE,SAAS,oBAAoB,EAAE,CAAC;CAC5C,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAyOpD,CAAC;AAMF,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,SAAS,oBAAoB,EAAE,C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
@@ -1,4 +1,5 @@
1
- export declare type UserSettings = {
1
+ export interface UserSettings {
2
2
  loggerPosition: string;
3
- };
3
+ activeProfileId: string | undefined;
4
+ }
4
5
  //# sourceMappingURL=user-settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-settings.d.ts","sourceRoot":"","sources":["../../../src/common/types/user-settings.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY,GAAG;IACzB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
1
+ {"version":3,"file":"user-settings.d.ts","sourceRoot":"","sources":["../../../src/common/types/user-settings.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC"}
@@ -28,6 +28,4 @@ export declare const setUserSettings: (value: UserSettings) => void;
28
28
  * Generate a Short ID with the given length. The ID will be in hexadecimal.
29
29
  */
30
30
  export declare const generateShortUniqueId: (length?: number) => string;
31
- export declare const getActiveProfileId: () => string;
32
- export declare const setActiveProfileId: (value: string | number | boolean | (string | number | boolean)[] | undefined) => void;
33
31
  //# sourceMappingURL=storage-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.d.ts","sourceRoot":"","sources":["../../../src/common/utils/storage-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAMtD;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,YAkD3C,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,aAAa,EAE9C,CAAC;AAEF,eAAO,MAAM,eAAe,aAAc,aAAa,EAAE,KAAG,IAO3D,CAAC;AAEF,eAAO,MAAM,WAAW,kBAAmB,aAAa,KAAG,IAe1D,CAAC;AAEF,eAAO,MAAM,kBAAkB,eACpB,aAAa,OACjB,MAAM,MAGZ,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AACH,eAAO,MAAM,oCAAoC,YAYhD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,YAMlC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,YAAY,KAAG,IAErD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,YAAY,MAAM,WAKnD,CAAC"}
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { isValidElement, createElement, Component, forwardRef, useState, useImperativeHandle, createContext, useContext, useRef, useEffect } from 'react';
1
+ import React, { isValidElement, createElement, Component, forwardRef, useState, useImperativeHandle, createContext, useContext, useRef, useCallback, useEffect } from 'react';
2
2
  import { useLocation, Link, Switch, Route, useHistory, NavLink, BrowserRouter } from 'react-router-dom';
3
3
  import { Grid, Segment, Header, Select, Button, Divider, List, Tab, Form, Dropdown, Search } from 'semantic-ui-react';
4
4
 
@@ -140,7 +140,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
140
140
 
141
141
  const KEY_PROFILE_DATA = 'AX_PROFILE_DATA';
142
142
  const KEY_USER_SETTINGS = 'AX_USER_SETTINGS';
143
- const KEY_ACTIVE_PROFILE = 'AX_ACTIVE_PROFILE';
144
143
  /**
145
144
  * The structure of the `ProfileConfig` type maintained in code can undergo several structural changes overtime.
146
145
  * However, there may exist objects that were created using prior versions of the type persisted on client local-storages.
@@ -223,10 +222,13 @@ const setProfileVariable = (profile, key, value, comment) => {
223
222
  * latest `UserSettings` type in code by substituting reasonable defaults where necessary and eliminating obsolete properties.
224
223
  */
225
224
  const migrateUserSettingsStructuralChanges = () => {
226
- var _a;
225
+ var _a, _b;
227
226
  const existingUserSettings = getUserSettings();
227
+ const allProfiles = getAllProfiles();
228
+ const firstProfileId = allProfiles.length > 0 ? allProfiles[0].id : undefined;
228
229
  const migratedUserSettings = {
229
230
  loggerPosition: (_a = existingUserSettings.loggerPosition) !== null && _a !== void 0 ? _a : '70%',
231
+ activeProfileId: (_b = existingUserSettings.activeProfileId) !== null && _b !== void 0 ? _b : firstProfileId,
230
232
  };
231
233
  setUserSettings(migratedUserSettings);
232
234
  };
@@ -243,12 +245,6 @@ const setUserSettings = (value) => {
243
245
  const generateShortUniqueId = (length = 8) => {
244
246
  const randomId = Math.floor(Math.random() * Math.pow(16, length)).toString(16);
245
247
  return ('0'.repeat(length - randomId.length) + randomId).toUpperCase();
246
- };
247
- const getActiveProfileId = () => {
248
- return JSON.parse(localStorage.getItem(KEY_ACTIVE_PROFILE) || '');
249
- };
250
- const setActiveProfileId = (value) => {
251
- localStorage.setItem(KEY_ACTIVE_PROFILE, JSON.stringify(value));
252
248
  };
253
249
 
254
250
  /**
@@ -297,22 +293,37 @@ const ScenarioHost = ({ scenarios }) => {
297
293
  var _a;
298
294
  const groupedScenarios = getGroupedScenarios(scenarios);
299
295
  const { pathname } = useLocation();
296
+ const [userSettings] = useState(getUserSettings());
300
297
  const [profiles] = useState(getAllProfiles());
301
- const [activeProfile, setActiveProfile] = useState(profiles.length > 0 ? profiles[0] : undefined);
298
+ /**
299
+ * We read the `activeProfileId` from the UserSettings saved in the local-storage, and check if that exists
300
+ * in the `profiles` found in the local-storage.
301
+ *
302
+ * If there is a match, we return the profile matching to that ID, if not, we either return `undefined`
303
+ * or return the 1st profile in the array.
304
+ */
305
+ const getActiveProfileFromUserSettings = () => {
306
+ if (profiles.length > 0) {
307
+ const activeProfileIndex = profiles.findIndex((profile) => profile.id === userSettings.activeProfileId);
308
+ if (activeProfileIndex < 0) {
309
+ return profiles[0];
310
+ }
311
+ else {
312
+ return profiles[activeProfileIndex];
313
+ }
314
+ }
315
+ else {
316
+ return undefined;
317
+ }
318
+ };
319
+ const [activeProfile, setActiveProfile] = useState(getActiveProfileFromUserSettings());
302
320
  // Reference to the logger component. This can be used to log new messages.
303
321
  const loggerRef = useRef(null);
304
- const handleProfileChanged = (event, data) => {
322
+ const handleProfileChanged = useCallback((event, data) => {
305
323
  const activeProfileIndex = profiles.findIndex((profile) => profile.id === data.value);
306
324
  setActiveProfile(profiles[activeProfileIndex]);
307
- setActiveProfileId(data.value);
308
- };
309
- useEffect(() => {
310
- const storageProfileId = getActiveProfileId();
311
- if (storageProfileId !== (activeProfile === null || activeProfile === void 0 ? void 0 : activeProfile.id)) {
312
- const activeProfileIndex = profiles.findIndex((profile) => profile.id === storageProfileId);
313
- setActiveProfile(profiles[activeProfileIndex]);
314
- }
315
- }, [activeProfile === null || activeProfile === void 0 ? void 0 : activeProfile.id, profiles]);
325
+ setUserSettings(Object.assign(Object.assign({}, userSettings), { activeProfileId: profiles[activeProfileIndex].id }));
326
+ }, [profiles, userSettings]);
316
327
  const ScenarioErrorFallback = (info) => {
317
328
  return (React.createElement(Segment, { basic: true },
318
329
  React.createElement(Header, { size: "huge" }, "Something went wrong"),