@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/dist/index.js CHANGED
@@ -148,7 +148,6 @@ var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
148
148
 
149
149
  const KEY_PROFILE_DATA = 'AX_PROFILE_DATA';
150
150
  const KEY_USER_SETTINGS = 'AX_USER_SETTINGS';
151
- const KEY_ACTIVE_PROFILE = 'AX_ACTIVE_PROFILE';
152
151
  /**
153
152
  * The structure of the `ProfileConfig` type maintained in code can undergo several structural changes overtime.
154
153
  * However, there may exist objects that were created using prior versions of the type persisted on client local-storages.
@@ -231,10 +230,13 @@ const setProfileVariable = (profile, key, value, comment) => {
231
230
  * latest `UserSettings` type in code by substituting reasonable defaults where necessary and eliminating obsolete properties.
232
231
  */
233
232
  const migrateUserSettingsStructuralChanges = () => {
234
- var _a;
233
+ var _a, _b;
235
234
  const existingUserSettings = getUserSettings();
235
+ const allProfiles = getAllProfiles();
236
+ const firstProfileId = allProfiles.length > 0 ? allProfiles[0].id : undefined;
236
237
  const migratedUserSettings = {
237
238
  loggerPosition: (_a = existingUserSettings.loggerPosition) !== null && _a !== void 0 ? _a : '70%',
239
+ activeProfileId: (_b = existingUserSettings.activeProfileId) !== null && _b !== void 0 ? _b : firstProfileId,
238
240
  };
239
241
  setUserSettings(migratedUserSettings);
240
242
  };
@@ -251,12 +253,6 @@ const setUserSettings = (value) => {
251
253
  const generateShortUniqueId = (length = 8) => {
252
254
  const randomId = Math.floor(Math.random() * Math.pow(16, length)).toString(16);
253
255
  return ('0'.repeat(length - randomId.length) + randomId).toUpperCase();
254
- };
255
- const getActiveProfileId = () => {
256
- return JSON.parse(localStorage.getItem(KEY_ACTIVE_PROFILE) || '');
257
- };
258
- const setActiveProfileId = (value) => {
259
- localStorage.setItem(KEY_ACTIVE_PROFILE, JSON.stringify(value));
260
256
  };
261
257
 
262
258
  /**
@@ -305,22 +301,37 @@ const ScenarioHost = ({ scenarios }) => {
305
301
  var _a;
306
302
  const groupedScenarios = getGroupedScenarios(scenarios);
307
303
  const { pathname } = reactRouterDom.useLocation();
304
+ const [userSettings] = React.useState(getUserSettings());
308
305
  const [profiles] = React.useState(getAllProfiles());
309
- const [activeProfile, setActiveProfile] = React.useState(profiles.length > 0 ? profiles[0] : undefined);
306
+ /**
307
+ * We read the `activeProfileId` from the UserSettings saved in the local-storage, and check if that exists
308
+ * in the `profiles` found in the local-storage.
309
+ *
310
+ * If there is a match, we return the profile matching to that ID, if not, we either return `undefined`
311
+ * or return the 1st profile in the array.
312
+ */
313
+ const getActiveProfileFromUserSettings = () => {
314
+ if (profiles.length > 0) {
315
+ const activeProfileIndex = profiles.findIndex((profile) => profile.id === userSettings.activeProfileId);
316
+ if (activeProfileIndex < 0) {
317
+ return profiles[0];
318
+ }
319
+ else {
320
+ return profiles[activeProfileIndex];
321
+ }
322
+ }
323
+ else {
324
+ return undefined;
325
+ }
326
+ };
327
+ const [activeProfile, setActiveProfile] = React.useState(getActiveProfileFromUserSettings());
310
328
  // Reference to the logger component. This can be used to log new messages.
311
329
  const loggerRef = React.useRef(null);
312
- const handleProfileChanged = (event, data) => {
330
+ const handleProfileChanged = React.useCallback((event, data) => {
313
331
  const activeProfileIndex = profiles.findIndex((profile) => profile.id === data.value);
314
332
  setActiveProfile(profiles[activeProfileIndex]);
315
- setActiveProfileId(data.value);
316
- };
317
- React.useEffect(() => {
318
- const storageProfileId = getActiveProfileId();
319
- if (storageProfileId !== (activeProfile === null || activeProfile === void 0 ? void 0 : activeProfile.id)) {
320
- const activeProfileIndex = profiles.findIndex((profile) => profile.id === storageProfileId);
321
- setActiveProfile(profiles[activeProfileIndex]);
322
- }
323
- }, [activeProfile === null || activeProfile === void 0 ? void 0 : activeProfile.id, profiles]);
333
+ setUserSettings(Object.assign(Object.assign({}, userSettings), { activeProfileId: profiles[activeProfileIndex].id }));
334
+ }, [profiles, userSettings]);
324
335
  const ScenarioErrorFallback = (info) => {
325
336
  return (React__default['default'].createElement(semanticUiReact.Segment, { basic: true },
326
337
  React__default['default'].createElement(semanticUiReact.Header, { size: "huge" }, "Something went wrong"),