From 8ee7563caf3c5b8b911f730a4e86beddfe898884 Mon Sep 17 00:00:00 2001 From: gopienkonikita Date: Mon, 1 Mar 2021 18:15:11 +0300 Subject: [PATCH] Web: Client: fixed mobx warnings --- packages/asc-web-common/store/AuthStore.js | 37 ++++++-------------- packages/asc-web-common/store/ModuleStore.js | 7 +++- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/asc-web-common/store/AuthStore.js b/packages/asc-web-common/store/AuthStore.js index 29db77dbb8..10165fd6a6 100644 --- a/packages/asc-web-common/store/AuthStore.js +++ b/packages/asc-web-common/store/AuthStore.js @@ -1,4 +1,4 @@ -import { action, computed, makeObservable, observable } from "mobx"; +import { makeAutoObservable } from "mobx"; import api from "../api"; import { setWithCredentialsStatus } from "../api/client"; import history from "../history"; @@ -23,28 +23,7 @@ class AuthStore { this.moduleStore = new ModuleStore(); this.settingsStore = new SettingsStore(); - makeObservable(this, { - isLoading: observable, - isAuthenticated: observable, - isAdmin: computed, - isLoaded: computed, - language: computed, - product: computed, - availableModules: computed, - userStore: observable, - moduleStore: observable, - settingsStore: observable, - version: observable, - init: action, - login: action, - logout: action, - setIsAuthenticated: action, - replaceFileStream: action, - getEncryptionAccess: action, - setEncryptionAccess: action, - setProductVersion: action, - reset: action, - }); + makeAutoObservable(this); } init = async () => { @@ -93,9 +72,11 @@ class AuthStore { } get product() { - return this.moduleStore.modules.find( - (item) => item.id === this.settingsStore.currentProductId - ) || ""; + return ( + this.moduleStore.modules.find( + (item) => item.id === this.settingsStore.currentProductId + ) || "" + ); } get availableModules() { @@ -107,7 +88,9 @@ class AuthStore { const isUserAdmin = user.isAdmin; const customModules = this.getCustomModules(isUserAdmin); - const products = modules.map((m) => toModuleWrapper(m, false)); + + const newModules = JSON.parse(JSON.stringify(modules)); + const products = newModules.map((m) => toModuleWrapper(m, false)); const primaryProducts = products.filter((m) => m.isPrimary === true); const dummyProducts = products.filter((m) => m.isPrimary === false); diff --git a/packages/asc-web-common/store/ModuleStore.js b/packages/asc-web-common/store/ModuleStore.js index 9c38c1f841..04a81d0110 100644 --- a/packages/asc-web-common/store/ModuleStore.js +++ b/packages/asc-web-common/store/ModuleStore.js @@ -50,7 +50,12 @@ class ModuleStore { this.setModules(extendedModules); }; - toModuleWrapper = (item, noAction = true, iconName = null, iconUrl = null) => { + toModuleWrapper = ( + item, + noAction = true, + iconName = null, + iconUrl = null + ) => { switch (item.id) { case "6743007c-6f95-4d20-8c88-a8601ce5e76d": item.iconName = "CrmIcon";