From 24ab2c525912b67677a26722028ada4963a16b77 Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Mon, 13 May 2024 20:31:35 -0400 Subject: [PATCH 1/6] fix: display `Editor` when in json view --- src/extension/app/store/app.js | 9 ++++++++- src/extension/manifest.json | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/extension/app/store/app.js b/src/extension/app/store/app.js index b37094e6..58f6782b 100644 --- a/src/extension/app/store/app.js +++ b/src/extension/app/store/app.js @@ -532,7 +532,14 @@ export class AppStore { */ getContentSourceLabel() { const { preview } = this.status; - return preview?.sourceLocation.includes('onedrive:') ? 'SharePoint' : 'Google Drive'; + const { sourceLocation } = preview; + + // No sourceLocation on preview for JSON files + if (!sourceLocation) { + return 'Editor'; + } + + return sourceLocation.includes('onedrive:') ? 'SharePoint' : 'Google Drive'; } /** diff --git a/src/extension/manifest.json b/src/extension/manifest.json index a9f58e62..e7e5a972 100644 --- a/src/extension/manifest.json +++ b/src/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "__MSG_title__", - "version": "0.0.1", + "version": "0.0.3", "author": "Adobe", "homepage_url": "https://www.hlx.live/tools/sidekick/", "default_locale": "en", @@ -50,7 +50,7 @@ "polyfills.min.js", "sp-popover.js", "sp-tray.js", - "views/json/json.html", + "views/json/*", "rum.js" ], "matches": [ From 7c1f661619908a4962b904052ff1e1d6d1686f7e Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Mon, 13 May 2024 22:15:53 -0400 Subject: [PATCH 2/6] fix: test --- src/extension/_locales/en/messages.json | 3 +++ src/extension/app/store/app.js | 2 +- .../components/plugin/env-switcher.test.js | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/extension/_locales/en/messages.json b/src/extension/_locales/en/messages.json index 787cca4c..250012a9 100644 --- a/src/extension/_locales/en/messages.json +++ b/src/extension/_locales/en/messages.json @@ -681,5 +681,8 @@ }, "deleting_state": { "message": "Deleting..." + }, + "editor": { + "message": "Editor" } } \ No newline at end of file diff --git a/src/extension/app/store/app.js b/src/extension/app/store/app.js index 58f6782b..a4987ee9 100644 --- a/src/extension/app/store/app.js +++ b/src/extension/app/store/app.js @@ -536,7 +536,7 @@ export class AppStore { // No sourceLocation on preview for JSON files if (!sourceLocation) { - return 'Editor'; + return this.i18n('editor'); } return sourceLocation.includes('onedrive:') ? 'SharePoint' : 'Google Drive'; diff --git a/test/app/components/plugin/env-switcher.test.js b/test/app/components/plugin/env-switcher.test.js index 6298d7a0..ae71eb14 100644 --- a/test/app/components/plugin/env-switcher.test.js +++ b/test/app/components/plugin/env-switcher.test.js @@ -319,5 +319,32 @@ describe('Environment Switcher', () => { const publishButton = recursiveQuery(notificationItem, 'sp-action-button'); expect(publishButton.hasAttribute('disabled')).to.be.true; }).timeout(20000); + + it('viewing json file should say open in editor', async () => { + sidekickTest + .mockFetchSidekickConfigSuccess(true) + .mockFetchStatusSuccess(false, { + webPath: '/query-index.json', + resourcePath: '/query-index.json', + preview: { + url: 'https://main--blog--adobecom.hlx.page/query-index.json', + status: 200, + contentBusId: 'helix-content-bus/cbid/preview/query-index.json', + contentType: 'application/json', + lastModified: 'Tue, 12 Sep 2023 19:38:51 GMT', + permissions: [ + 'read', + 'write', + ], + }, + }, HelixMockContentSources.SHAREPOINT, 'https://admin.hlx.page/status/adobe/aem-boilerplate/main/placeholders.json') + .mockHelixEnvironment(HelixMockEnvironments.PREVIEW, HelixMockContentType.SHEET); + + sidekick = sidekickTest.createSidekick(); + await sidekickTest.awaitEnvSwitcher(); + + const editPlugin = recursiveQuery(sidekick, '.env-edit'); + expect(editPlugin.textContent.trim()).to.eq('Open in Editor'); + }); }); }); From eca0cbad9f45635186e3e4a281ff1d15d3e592ad Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Tue, 14 May 2024 11:30:09 -0400 Subject: [PATCH 3/6] fix: better handling of fallback and byom --- .../plugin/env-switcher/env-switcher.js | 10 ++++- src/extension/app/store/app.js | 18 +++++--- .../components/plugin/env-switcher.test.js | 7 ++-- test/app/store/app.test.js | 41 +++++++++++++++++++ 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/extension/app/components/plugin/env-switcher/env-switcher.js b/src/extension/app/components/plugin/env-switcher/env-switcher.js index be20dc65..d83dadf4 100644 --- a/src/extension/app/components/plugin/env-switcher/env-switcher.js +++ b/src/extension/app/components/plugin/env-switcher/env-switcher.js @@ -133,7 +133,15 @@ export class EnvironmentSwitcher extends ConnectedElement { if (this.currentEnv === id) { attrs.disabled = ''; } - const label = id === 'edit' ? this.appStore.i18n('open_in').replace('$1', this.appStore.getContentSourceLabel()) : this.envNames[id]; + + const contentSourceLabel = this.appStore.getContentSourceLabel(); + if (id === 'edit' && contentSourceLabel === 'BYOM') { + return createTag({ + tag: 'span', + }); + } + + const label = id === 'edit' ? this.appStore.i18n('open_in').replace('$1', contentSourceLabel) : this.envNames[id]; const menuItem = createTag({ tag: 'sp-menu-item', text: label, diff --git a/src/extension/app/store/app.js b/src/extension/app/store/app.js index a4987ee9..24e11bd7 100644 --- a/src/extension/app/store/app.js +++ b/src/extension/app/store/app.js @@ -10,7 +10,7 @@ * governing permissions and limitations under the License. */ -/* eslint-disable no-restricted-globals */ +/* eslint-disable no-restricted-globals, no-nested-ternary */ import { observable, action } from 'mobx'; import { createContext } from '@lit/context'; @@ -534,12 +534,20 @@ export class AppStore { const { preview } = this.status; const { sourceLocation } = preview; - // No sourceLocation on preview for JSON files - if (!sourceLocation) { - return this.i18n('editor'); + if (sourceLocation) { + return sourceLocation.includes('onedrive:') + ? 'SharePoint' + : sourceLocation.includes('gdrive:') + ? 'Google Drive' + : 'BYOM'; } - return sourceLocation.includes('onedrive:') ? 'SharePoint' : 'Google Drive'; + const { mountpoint } = this.siteStore; + return mountpoint.includes('.sharepoint.com') + ? 'SharePoint' + : mountpoint.includes('.google.com') + ? 'Google Drive' + : 'BYOM'; } /** diff --git a/test/app/components/plugin/env-switcher.test.js b/test/app/components/plugin/env-switcher.test.js index ae71eb14..ad66f026 100644 --- a/test/app/components/plugin/env-switcher.test.js +++ b/test/app/components/plugin/env-switcher.test.js @@ -320,9 +320,9 @@ describe('Environment Switcher', () => { expect(publishButton.hasAttribute('disabled')).to.be.true; }).timeout(20000); - it('viewing json file should say open in editor', async () => { + it('should not show edit if byom sourceLocation', async () => { sidekickTest - .mockFetchSidekickConfigSuccess(true) + .mockFetchSidekickConfigSuccess() .mockFetchStatusSuccess(false, { webPath: '/query-index.json', resourcePath: '/query-index.json', @@ -331,6 +331,7 @@ describe('Environment Switcher', () => { status: 200, contentBusId: 'helix-content-bus/cbid/preview/query-index.json', contentType: 'application/json', + sourceLocation: 'markup:https://byom.adobeioruntime.net/api/v1/web/convert/main/index.html?wcmmode=disabled', lastModified: 'Tue, 12 Sep 2023 19:38:51 GMT', permissions: [ 'read', @@ -344,7 +345,7 @@ describe('Environment Switcher', () => { await sidekickTest.awaitEnvSwitcher(); const editPlugin = recursiveQuery(sidekick, '.env-edit'); - expect(editPlugin.textContent.trim()).to.eq('Open in Editor'); + expect(editPlugin).to.be.undefined; }); }); }); diff --git a/test/app/store/app.test.js b/test/app/store/app.test.js index da9400c6..7730b137 100644 --- a/test/app/store/app.test.js +++ b/test/app/store/app.test.js @@ -1532,4 +1532,45 @@ describe('Test App Store', () => { expect(instance.login.called).to.be.false; }); }); + + describe('getContentSourceLabel', () => { + let instance; + + beforeEach(() => { + instance = new AppStore(); + }); + + it('should return "SharePoint" if sourceLocation includes "onedrive:"', () => { + instance.status = { preview: { sourceLocation: 'onedrive:example' } }; + expect(instance.getContentSourceLabel()).to.equal('SharePoint'); + }); + + it('should return "Google Drive" if sourceLocation includes "gdrive:"', () => { + instance.status = { preview: { sourceLocation: 'gdrive:example' } }; + expect(instance.getContentSourceLabel()).to.equal('Google Drive'); + }); + + it('should return "BYOM" if sourceLocation does not include known patterns', () => { + instance.status = { preview: { sourceLocation: 'dropbox:example' } }; + expect(instance.getContentSourceLabel()).to.equal('BYOM'); + }); + + it('should return "SharePoint" if mountpoint includes ".sharepoint.com"', () => { + instance.siteStore = { mountpoint: 'https://example.sharepoint.com' }; + instance.status = { preview: { sourceLocation: '' } }; + expect(instance.getContentSourceLabel()).to.equal('SharePoint'); + }); + + it('should return "Google Drive" if mountpoint includes ".google.com"', () => { + instance.siteStore = { mountpoint: 'https://drive.google.com' }; + instance.status = { preview: { sourceLocation: '' } }; + expect(instance.getContentSourceLabel()).to.equal('Google Drive'); + }); + + it('should return "BYOM" if mountpoint does not include known patterns', () => { + instance.siteStore = { mountpoint: 'https://example.com' }; + instance.status = { preview: { sourceLocation: '' } }; + expect(instance.getContentSourceLabel()).to.equal('BYOM'); + }); + }); }); From 35f584a5a2474d3e258ba5bb6d54e0ed4301c4a8 Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Tue, 14 May 2024 11:32:09 -0400 Subject: [PATCH 4/6] fix: remove editor message --- src/extension/_locales/en/messages.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/extension/_locales/en/messages.json b/src/extension/_locales/en/messages.json index 250012a9..787cca4c 100644 --- a/src/extension/_locales/en/messages.json +++ b/src/extension/_locales/en/messages.json @@ -681,8 +681,5 @@ }, "deleting_state": { "message": "Deleting..." - }, - "editor": { - "message": "Editor" } } \ No newline at end of file From 7f031448def20ecc5a8b77dbca0511ac3a95b178 Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Wed, 15 May 2024 13:33:57 -0400 Subject: [PATCH 5/6] fix: address comments --- src/extension/app/store/app.js | 12 ++++++------ test/app/store/app.test.js | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/extension/app/store/app.js b/src/extension/app/store/app.js index 24e11bd7..aa2c74c4 100644 --- a/src/extension/app/store/app.js +++ b/src/extension/app/store/app.js @@ -535,18 +535,18 @@ export class AppStore { const { sourceLocation } = preview; if (sourceLocation) { - return sourceLocation.includes('onedrive:') + return sourceLocation.startsWith('onedrive:') ? 'SharePoint' - : sourceLocation.includes('gdrive:') + : sourceLocation.startsWith('gdrive:') ? 'Google Drive' : 'BYOM'; } const { mountpoint } = this.siteStore; - return mountpoint.includes('.sharepoint.com') - ? 'SharePoint' - : mountpoint.includes('.google.com') - ? 'Google Drive' + return mountpoint.includes('.google.com') + ? 'Google Drive' + : mountpoint.includes('.sharepoint.com') || mountpoint.includes('/Shared%20Documents/sites/') + ? 'SharePoint' : 'BYOM'; } diff --git a/test/app/store/app.test.js b/test/app/store/app.test.js index 7730b137..7a73d0f3 100644 --- a/test/app/store/app.test.js +++ b/test/app/store/app.test.js @@ -1561,6 +1561,12 @@ describe('Test App Store', () => { expect(instance.getContentSourceLabel()).to.equal('SharePoint'); }); + it('should return "SharePoint" if mountpoint does not include ".sharepoint.com" but does contain /Shared%20Documents/sites/', () => { + instance.siteStore = { mountpoint: 'https://example.com/Shared%20Documents/sites/aem-boilerplate' }; + instance.status = { preview: { sourceLocation: '' } }; + expect(instance.getContentSourceLabel()).to.equal('SharePoint'); + }); + it('should return "Google Drive" if mountpoint includes ".google.com"', () => { instance.siteStore = { mountpoint: 'https://drive.google.com' }; instance.status = { preview: { sourceLocation: '' } }; From 3d8d845a226712bf185c6436e159a6b4cd8eae58 Mon Sep 17 00:00:00 2001 From: Dylan Depass Date: Thu, 16 May 2024 09:01:50 -0400 Subject: [PATCH 6/6] fix: address comment --- src/extension/app/store/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/extension/app/store/app.js b/src/extension/app/store/app.js index aa2c74c4..a466a4af 100644 --- a/src/extension/app/store/app.js +++ b/src/extension/app/store/app.js @@ -543,9 +543,10 @@ export class AppStore { } const { mountpoint } = this.siteStore; - return mountpoint.includes('.google.com') + const mountpointUrl = new URL(mountpoint); + return mountpointUrl.host.includes('.google.com') ? 'Google Drive' - : mountpoint.includes('.sharepoint.com') || mountpoint.includes('/Shared%20Documents/sites/') + : mountpointUrl.host.includes('.sharepoint.com') || mountpointUrl.pathname.includes('/Shared%20Documents/sites/') ? 'SharePoint' : 'BYOM'; }