From 91c69428ed0dc2dd26b00c6dd5a6684f25515a34 Mon Sep 17 00:00:00 2001 From: Abin Mn Date: Tue, 26 Oct 2021 21:18:20 +0530 Subject: Cleanup/remove feature toggle for todo, workspace, service proxy (#2134) * Remove DEFAULT_FEATURES_CONFIG from config * Remove static controller Co-authored-by: Madhuri B --- src/features/settingsWS/actions.ts | 13 ---- src/features/settingsWS/index.ts | 28 -------- src/features/settingsWS/state.ts | 13 ---- src/features/settingsWS/store.js | 132 ------------------------------------- src/features/todos/index.ts | 25 +------ src/features/todos/store.js | 9 --- src/features/workspaces/index.ts | 22 +------ src/features/workspaces/store.js | 8 --- 8 files changed, 3 insertions(+), 247 deletions(-) delete mode 100755 src/features/settingsWS/actions.ts delete mode 100755 src/features/settingsWS/index.ts delete mode 100755 src/features/settingsWS/state.ts delete mode 100755 src/features/settingsWS/store.js (limited to 'src/features') diff --git a/src/features/settingsWS/actions.ts b/src/features/settingsWS/actions.ts deleted file mode 100755 index 03a398eb5..000000000 --- a/src/features/settingsWS/actions.ts +++ /dev/null @@ -1,13 +0,0 @@ -import PropTypes from 'prop-types'; -import { createActionsFromDefinitions } from '../../actions/lib/actions'; - -export const settingsWSActions = createActionsFromDefinitions( - { - greet: { - name: PropTypes.string.isRequired, - }, - }, - PropTypes.checkPropTypes, -); - -export default settingsWSActions; diff --git a/src/features/settingsWS/index.ts b/src/features/settingsWS/index.ts deleted file mode 100755 index 9bb206d82..000000000 --- a/src/features/settingsWS/index.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { reaction } from 'mobx'; -import { SettingsWSStore } from './store'; - -const debug = require('debug')('Ferdi:feature:settingsWS'); - -export const settingsStore = new SettingsWSStore(); - -export default function initSettingsWebSocket( - stores: { features: any }, - actions: any, -) { - const { features } = stores; - - // Toggle SettingsWebSocket feature - reaction( - () => features.features.isSettingsWSEnabled, - isEnabled => { - if (isEnabled) { - debug('Initializing `settingsWS` feature'); - settingsStore.start(stores, actions); - } else if (settingsStore) { - debug('Disabling `settingsWS` feature'); - settingsStore.stop(); - } - }, - { fireImmediately: true }, - ); -} diff --git a/src/features/settingsWS/state.ts b/src/features/settingsWS/state.ts deleted file mode 100755 index 7b16b2b6e..000000000 --- a/src/features/settingsWS/state.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { observable } from 'mobx'; - -const defaultState = { - isFeatureActive: false, -}; - -export const settingsWSState = observable(defaultState); - -export function resetState() { - Object.assign(settingsWSState, defaultState); -} - -export default settingsWSState; diff --git a/src/features/settingsWS/store.js b/src/features/settingsWS/store.js deleted file mode 100755 index 3b9e10825..000000000 --- a/src/features/settingsWS/store.js +++ /dev/null @@ -1,132 +0,0 @@ -import { observable } from 'mobx'; -import WebSocket from 'ws'; -import ms from 'ms'; - -import { FeatureStore } from '../utils/FeatureStore'; -import { createReactions } from '../../stores/lib/Reaction'; -import { WS_API } from '../../environment-remote'; - -const debug = require('debug')('Ferdi:feature:settingsWS:store'); - -export class SettingsWSStore extends FeatureStore { - stores = null; - - actions = null; - - ws = null; - - pingTimeout = null; - - reconnectTimeout = null; - - @observable connected = false; - - start(stores, actions) { - this.stores = stores; - this.actions = actions; - - this._registerReactions( - createReactions([ - this._initialize.bind(this), - this._reconnect.bind(this), - this._close.bind(this), - ]), - ); - } - - connect() { - try { - const wsURL = `${WS_API}/ws/${this.stores.user.data.id}`; - debug('Setting up WebSocket to', wsURL); - - this.ws = new WebSocket(wsURL); - - this.ws.on('open', () => { - debug('Opened WebSocket'); - this.send({ - action: 'authorize', - token: this.stores.user.authToken, - }); - - this.connected = true; - - this.heartbeat(); - }); - - this.ws.on('message', data => { - const resp = JSON.parse(data); - debug('Received message', resp); - - if (resp.id) { - this.stores.user.getUserInfoRequest.patch(result => { - if (!result) return; - - debug('Patching user object with new values'); - Object.assign(result, resp); - }); - } - }); - - this.ws.on('ping', this.heartbeat.bind(this)); - } catch (error) { - console.error(error); - } - } - - heartbeat() { - debug('Heartbeat'); - clearTimeout(this.pingTimeout); - - this.pingTimeout = setTimeout(() => { - debug('Terminating connection, reconnecting in 35'); - this.ws.terminate(); - - this.connected = false; - }, ms('35s')); - } - - send(data) { - if (this.ws && this.ws.readyState === 1) { - this.ws.send(JSON.stringify(data)); - debug('Sending data', data); - } else { - debug('WebSocket is not initialized'); - } - } - - // Reactions - - _initialize() { - if (this.stores.user.data.id && !this.ws) { - this.connect(); - } - } - - _reconnect() { - if (!this.connected) { - debug('Trying to reconnect in 30s'); - this.reconnectTimeout = setInterval(() => { - debug('Trying to reconnect'); - this.connect(); - }, ms('30s')); - } else { - debug('Clearing reconnect interval'); - clearInterval(this.reconnectTimeout); - } - } - - _close() { - if (!this.stores.user.isLoggedIn) { - debug('Stopping reactions'); - this._stopReactions(); - - if (this.ws) { - debug('Terminating connection'); - this.ws.terminate(); - this.ws = null; - } - } - } -} - -export default SettingsWSStore; diff --git a/src/features/todos/index.ts b/src/features/todos/index.ts index 3665812e6..2fa8c3130 100644 --- a/src/features/todos/index.ts +++ b/src/features/todos/index.ts @@ -1,29 +1,8 @@ -import { reaction } from 'mobx'; import TodoStore from './store'; -const debug = require('debug')('Ferdi:feature:todos'); - export const todosStore = new TodoStore(); -export default function initTodos( - stores: { todos?: any; features?: any }, - actions: any, -) { +export default function initTodos(stores: { todos?: any }, actions: any) { stores.todos = todosStore; - const { features } = stores; - - // Toggle todos feature - reaction( - () => features.features.isTodosEnabled, - isEnabled => { - if (isEnabled) { - debug('Initializing `todos` feature'); - todosStore.start(stores, actions); - } else if (todosStore.isFeatureActive) { - debug('Disabling `todos` feature'); - todosStore.stop(); - } - }, - { fireImmediately: true }, - ); + todosStore.start(stores, actions); } diff --git a/src/features/todos/store.js b/src/features/todos/store.js index 010a029ff..d158ed480 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js @@ -23,8 +23,6 @@ const debug = require('debug')('Ferdi:feature:todos:store'); export default class TodoStore extends FeatureStore { @observable stores = null; - @observable isFeatureEnabled = false; - @observable isFeatureActive = false; @observable webview = null; @@ -123,7 +121,6 @@ export default class TodoStore extends FeatureStore { // REACTIONS this._allReactions = createReactions([ - this._setFeatureEnabledReaction, this._updateTodosConfig, this._firstLaunchReaction, this._routeCheckReaction, @@ -262,12 +259,6 @@ export default class TodoStore extends FeatureStore { // Reactions - _setFeatureEnabledReaction = () => { - const { isTodosEnabled } = this.stores.features.features; - - this.isFeatureEnabled = isTodosEnabled; - }; - _updateTodosConfig = () => { // Resend the config if any part changes in Franz: this._onTodosClientInitialized(); diff --git a/src/features/workspaces/index.ts b/src/features/workspaces/index.ts index ecca64b41..25975936a 100644 --- a/src/features/workspaces/index.ts +++ b/src/features/workspaces/index.ts @@ -1,28 +1,8 @@ -import { reaction } from 'mobx'; import WorkspacesStore from './store'; -import { resetApiRequests } from './api'; - -const debug = require('debug')('Ferdi:feature:workspaces'); export const workspaceStore = new WorkspacesStore(); export default function initWorkspaces(stores, actions) { stores.workspaces = workspaceStore; - const { features } = stores; - - // Toggle workspace feature - reaction( - () => features.features.isWorkspaceEnabled, - isEnabled => { - if (isEnabled && !workspaceStore.isFeatureActive) { - debug('Initializing `workspaces` feature'); - workspaceStore.start(stores, actions); - } else if (workspaceStore.isFeatureActive) { - debug('Disabling `workspaces` feature'); - workspaceStore.stop(); - resetApiRequests(); - } - }, - { fireImmediately: true }, - ); + workspaceStore.start(stores, actions); } diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 0fa43b723..17ec17b3a 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -18,8 +18,6 @@ import { KEEP_WS_LOADED_USID } from '../../config'; const debug = require('debug')('Ferdi:feature:workspaces:store'); export default class WorkspacesStore extends FeatureStore { - @observable isFeatureEnabled = true; - @observable isFeatureActive = false; @observable activeWorkspace = null; @@ -97,7 +95,6 @@ export default class WorkspacesStore extends FeatureStore { this._allReactions = createReactions([ this._openDrawerWithSettingsReaction, - this._setFeatureEnabledReaction, this._cleanupInvalidServiceReferences, this._setActiveServiceOnWorkspaceSwitchReaction, this._activateLastUsedWorkspaceReaction, @@ -251,11 +248,6 @@ export default class WorkspacesStore extends FeatureStore { // Reactions - _setFeatureEnabledReaction = () => { - const { isWorkspaceEnabled } = this.stores.features.features; - this.isFeatureEnabled = isWorkspaceEnabled; - }; - _setWorkspaceBeingEditedReaction = () => { const { pathname } = this.stores.router.location; const match = matchRoute('/settings/workspaces/edit/:id', pathname); -- cgit v1.2.3-70-g09d2