Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve content source detection in environment switcher #142

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 17 additions & 2 deletions src/extension/app/store/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -532,7 +532,22 @@ export class AppStore {
*/
getContentSourceLabel() {
const { preview } = this.status;
return preview?.sourceLocation.includes('onedrive:') ? 'SharePoint' : 'Google Drive';
const { sourceLocation } = preview;

if (sourceLocation) {
return sourceLocation.includes('onedrive:')
? 'SharePoint'
: sourceLocation.includes('gdrive:')
? 'Google Drive'
: 'BYOM';
rofe marked this conversation as resolved.
Show resolved Hide resolved
}

const { mountpoint } = this.siteStore;
return mountpoint.includes('.sharepoint.com')
? 'SharePoint'
: mountpoint.includes('.google.com')
? 'Google Drive'
: 'BYOM';
rofe marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/extension/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -50,7 +50,7 @@
"polyfills.min.js",
"sp-popover.js",
"sp-tray.js",
"views/json/json.html",
"views/json/*",
"rum.js"
],
"matches": [
Expand Down
28 changes: 28 additions & 0 deletions test/app/components/plugin/env-switcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,33 @@ describe('Environment Switcher', () => {
const publishButton = recursiveQuery(notificationItem, 'sp-action-button');
expect(publishButton.hasAttribute('disabled')).to.be.true;
}).timeout(20000);

it('should not show edit if byom sourceLocation', async () => {
sidekickTest
.mockFetchSidekickConfigSuccess()
.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',
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',
'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).to.be.undefined;
});
});
});
41 changes: 41 additions & 0 deletions test/app/store/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});