From 26cf1bc50b4e2ee21232e64b47c6bbd548b127c4 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 10 Nov 2016 14:34:55 -0800 Subject: [PATCH] Bug fix --- app/analytics/index.js | 4 +++- app/sync/index.js | 27 +++++++++++++++++++++------ app/ui/components/modals/SyncModal.js | 5 ++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/analytics/index.js b/app/analytics/index.js index 332795a4b0..fec865898f 100644 --- a/app/analytics/index.js +++ b/app/analytics/index.js @@ -14,11 +14,13 @@ export function initAnalytics(accountId) { } export function trackEvent (...args) { - google.trackEvent(...args) + google.trackEvent(...args); + console.log(`[analytics] track ${args.join(', ')}`); } export function setAccountId (accountId) { google.setAccountId(accountId); + console.log(`[analytics] account Id ${accountId}`); } export function trackLegacyEvent (event, properties) { diff --git a/app/sync/index.js b/app/sync/index.js index 309405307d..e090fdcaa2 100644 --- a/app/sync/index.js +++ b/app/sync/index.js @@ -118,21 +118,27 @@ export async function pushActiveDirtyResources (resourceGroupId = null) { for (const {id, version} of updated) { const resource = await store.getResourceByDocId(id); await store.updateResource(resource, {version, dirty: false}); - // logger.debug(`Push updated ${id}`); + } + if (updated.length) { + logger.debug(`Push updated ${updated.length} resources`); } // Update all resource versions with the ones that were returned for (const {id, version} of created) { const resource = await store.getResourceByDocId(id); await store.updateResource(resource, {version, dirty: false}); - // logger.debug(`Push created ${id}`); + } + if (created.length) { + logger.debug(`Push created ${created.length} resources`); } // Update all resource versions with the ones that were returned for (const {id, version} of removed) { const resource = await store.getResourceByDocId(id); await store.updateResource(resource, {version, dirty: false}); - // logger.debug(`Push removed ${id}`); + } + if (removed.length) { + logger.debug(`Push removed ${removed.length} resources`); } // Resolve conflicts @@ -345,6 +351,13 @@ export async function getOrCreateConfig (resourceGroupId) { } } +export async function ensureConfigExists (resourceGroupId, syncMode) { + const config = await store.getConfig(resourceGroupId); + if (!config) { + await store.insertConfig({resourceGroupId, syncMode}); + } +} + export async function createOrUpdateConfig (resourceGroupId, syncMode) { const config = await store.getConfig(resourceGroupId); const patch = {resourceGroupId, syncMode}; @@ -438,7 +451,9 @@ function _fetchResourceGroup (resourceGroupId) { // Also make sure a config exists when we first fetch it. // TODO: This exists in multiple places, so move it to one place. - createOrUpdateConfig(resourceGroupId, store.SYNC_MODE_OFF); + const config = await getOrCreateConfig(resourceGroupId); + const syncMode = config ? config.syncMode : store.SYNC_MODE_OFF; + createOrUpdateConfig(resourceGroupId, syncMode); } // Bust cached promise because we're done with it. @@ -534,7 +549,7 @@ async function _createResourceGroup (name = '') { } // Create a config for it - await createOrUpdateConfig(resourceGroup.id, store.SYNC_MODE_OFF); + await ensureConfigExists(resourceGroup.id, store.SYNC_MODE_OFF); logger.debug(`Created ResourceGroup ${resourceGroup.id}`); return resourceGroup; @@ -568,7 +583,7 @@ async function _createResourceForDoc (doc) { if (!workspaceResource) { const workspaceResourceGroup = await _createResourceGroup(workspace.name); - await createOrUpdateConfig(workspaceResourceGroup.id, store.SYNC_MODE_OFF); + await ensureConfigExists(workspaceResourceGroup.id, store.SYNC_MODE_OFF); workspaceResource = await _createResource(workspace, workspaceResourceGroup.id); } diff --git a/app/ui/components/modals/SyncModal.js b/app/ui/components/modals/SyncModal.js index 094a8d7ab9..30c5f6dd2a 100644 --- a/app/ui/components/modals/SyncModal.js +++ b/app/ui/components/modals/SyncModal.js @@ -45,8 +45,7 @@ class SyncModal extends Component { trackEvent('Sync', 'Push'); } - async _handleSyncModeChange (syncData, e) { - const syncMode = e.target.value; + async _handleSyncModeChange (syncData, syncMode) { const {resourceGroupId} = syncData.resource; await sync.createOrUpdateConfig(resourceGroupId, syncMode); @@ -169,7 +168,7 @@ class SyncModal extends Component {