From 2172df2d407ebc6ae3588f34aa59d2e4eb5f9930 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 10 Nov 2016 14:14:39 -0800 Subject: [PATCH] Update SyncModal to only show current Workspace --- app/sync/index.js | 2 +- app/ui/components/SyncButton.js | 7 +- app/ui/components/modals/SyncModal.js | 295 ++++++++++++-------------- 3 files changed, 141 insertions(+), 163 deletions(-) diff --git a/app/sync/index.js b/app/sync/index.js index ab38e5169..309405307 100644 --- a/app/sync/index.js +++ b/app/sync/index.js @@ -4,8 +4,8 @@ import * as fetch from '../common/fetch'; import * as crypt from './crypt'; import * as session from './session'; import * as store from './storage'; -import Logger from './logger'; import * as misc from '../common/misc'; +import Logger from './logger'; export const FULL_SYNC_INTERVAL = 60E3; export const QUEUE_DEBOUNCE_TIME = 1E3; diff --git a/app/ui/components/SyncButton.js b/app/ui/components/SyncButton.js index a3291736d..eef91222a 100644 --- a/app/ui/components/SyncButton.js +++ b/app/ui/components/SyncButton.js @@ -51,12 +51,13 @@ class SyncButton extends Component { } render () { + const {workspaceId} = this.props; + const {state: buttonState} = this.state; if (session.isLoggedIn()) { return ( ) } else { diff --git a/app/ui/components/modals/SyncModal.js b/app/ui/components/modals/SyncModal.js index 6487ec13e..094a8d7ab 100644 --- a/app/ui/components/modals/SyncModal.js +++ b/app/ui/components/modals/SyncModal.js @@ -20,8 +20,9 @@ class SyncModal extends Component { email: 'n/a', sessionId: 'n/a', dirty: [], - syncData: [], syncingResourceGroups: {}, + workspace: null, + syncData: null } } @@ -39,7 +40,7 @@ class SyncModal extends Component { delete syncingResourceGroups[resourceGroupId]; this.setState({syncingResourceGroups}); - await this._updateModal(); + await this._updateModal(this.state.workspace); trackEvent('Sync', 'Push'); } @@ -50,7 +51,7 @@ class SyncModal extends Component { await sync.createOrUpdateConfig(resourceGroupId, syncMode); // Refresh the modal - this._updateModal(); + this._updateModal(this.state.workspace); trackEvent('Sync', 'Change Mode', syncMode); } @@ -68,55 +69,50 @@ class SyncModal extends Component { sync.logout(); } - async _updateModal () { - const workspaces = await models.workspace.all(); - const syncData = []; - for (const workspace of workspaces) { + async _updateModal (workspace) { + // Get or create any related sync data + const resource = await sync.getOrCreateResourceForDoc(workspace); + const resourceGroupId = resource.resourceGroupId; + const config = await sync.getOrCreateConfig(resourceGroupId); - // Get or create any related sync data - const resource = await sync.getOrCreateResourceForDoc(workspace); - const resourceGroupId = resource.resourceGroupId; - const config = await sync.getOrCreateConfig(resourceGroupId); + // Analyze it + const dirty = await syncStorage.findActiveDirtyResourcesForResourceGroup(resourceGroupId); + const all = await syncStorage.findResourcesForResourceGroup(resourceGroupId); + const numClean = all.length - dirty.length; + const syncPercent = all.length === 0 ? 100 : parseInt(numClean / all.length * 1000) / 10; - // Analyze it - const dirty = await syncStorage.findActiveDirtyResourcesForResourceGroup(resourceGroupId); - const all = await syncStorage.findResourcesForResourceGroup(resourceGroupId); - const numClean = all.length - dirty.length; - - let syncPercent; - if (all.length === 0) { - syncPercent = 100; - } else { - syncPercent = parseInt(numClean / all.length * 1000) / 10 - } - - syncData.push({ - resource, - syncPercent, - syncMode: config.syncMode, - name: workspace.name, - }); - } + const syncData ={ + resource, + syncPercent, + syncMode: config.syncMode, + name: workspace.name, + }; this.setState({ syncData, + workspace, email: session.getEmail(), firstName: session.getFirstName(), sessionId: session.getCurrentSessionId(), }); } - async show () { + async show (workspaceId) { if (!session.isLoggedIn()) { console.error('Not logged in'); return; } - this.modal.show(); + const workspace = await models.workspace.getById(workspaceId); + if (!workspace) { + return; + } - clearInterval(this._interval); - await this._updateModal(); - this._interval = setInterval(() => this._updateModal(), 2000); + this.modal.show(); + await this._updateModal(workspace); + + clearInterval(this._interval); // Make sure it's off + this._interval = setInterval(() => this._updateModal(workspace), 2000); } hide () { @@ -125,10 +121,17 @@ class SyncModal extends Component { } render () { - const s = this.state; + const { + email, + sessionId, + workspace, + syncData, + syncingResourceGroups + } = this.state; + const data = [ - ['Email', s.email], - ['Session', s.sessionId], + ['Email', email], + ['Session', sessionId], ['Full Sync', `${sync.FULL_SYNC_INTERVAL / 1000} second interval`], ['Partial Sync', `${sync.PUSH_DEBOUNCE_TIME / 1000} seconds after change`], ]; @@ -143,134 +146,108 @@ class SyncModal extends Component { const allLogs = sync.logger.tail(); const logs = allLogs.slice(allLogs.length - 500); - return ( - this.modal = m} tall={true} wide={true}> - - Sync Settings - {" "} - ({s.email}) - - - - - - - - - - - - - - - - - - - - - - + let modalBody = null; + if (syncData) { + const {syncMode, syncPercent, resource} = syncData; + const {resourceGroupId} = resource; + modalBody = ( + + + + + + + + + + + + + +

{workspace ? workspace.name : 'Loading...'} {syncPercent}%

+
+ +    + +
+ +
+
+
+ +

+ Here is some useful debug info in case you need to report a bug. +

+
WorkspaceSyncSyncedTeam
+ + {data.map(([label, value]) => ( + + + - - - {this.state.syncData.map(data => { - const {syncMode, name, syncPercent, resource} = data; - const {resourceGroupId} = resource; - return ( - - - - - - - ) - } - )} - -
{label} + {value} +
{name} - -    - - - {syncPercent}% - - -
-
- -

- Here is some useful debug info in case you need to report a bug. -

- - - {data.map(([label, value]) => ( - - - - - ))} - -
{label} - {value} -
-
- -
- {logs.map((entry, i) => { - function pad (n, length) { - let s = n + ''; - while (s.length < length) { - s = '0' + s; - } - return s; + ))} + + + + +
+ {logs.map((entry, i) => { + function pad (n, length) { + let s = n + ''; + while (s.length < length) { + s = '0' + s; } + return s; + } - const dateString = - pad(entry.date.getFullYear(), 4) + '/' + - pad(entry.date.getMonth() + 1, 2) + '/' + - pad(entry.date.getDate(), 2) + ' ' + - pad(entry.date.getHours(), 2) + ':' + - pad(entry.date.getMinutes(), 2) + ':' + - pad(entry.date.getSeconds(), 2); - return ( -
+                const dateString =
+                  pad(entry.date.getFullYear(), 4) + '/' +
+                  pad(entry.date.getMonth() + 1, 2) + '/' +
+                  pad(entry.date.getDate(), 2) + ' ' +
+                  pad(entry.date.getHours(), 2) + ':' +
+                  pad(entry.date.getMinutes(), 2) + ':' +
+                  pad(entry.date.getSeconds(), 2);
+                return (
+                  
                   {dateString}
-                      {" "}
-                      
+                    {" "}
+                    
                   [{entry.type}]
                   
-                      {" "}
-                      {entry.message}
+                    {" "}
+                    {entry.message}
                   
- ) - })} -
-
- - + ) + })} +
+
+
+ ) + } + + return ( + this.modal = m} tall={true} wide={true}> + Sync Settings + {modalBody}
this._handleLogout()}>