Skip to content

Commit

Permalink
GH-244 - Extensible source support
Browse files Browse the repository at this point in the history
* Provides ability to let project spec an `editUrlFormat` object
* Supports `{{contentSourceUrl}} {{org}} {{site}} {{pathname}}` placeholders in pattern
  • Loading branch information
auniverseaway committed Sep 18, 2024
1 parent 6c9d4cb commit c27170c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/extension/app/store/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,14 @@ export class AppStore {
* @returns {string} The content source label
*/
getContentSourceLabel() {
const { contentSourceType } = this.siteStore;
const { contentSourceType, contentSourceEditLabel } = this.siteStore;

if (contentSourceType === 'onedrive') {
return 'SharePoint';
} else if (contentSourceType === 'google') {
return 'Google Drive';
} else if (contentSourceEditLabel) {
return contentSourceEditLabel;
} else {
return 'BYOM';
}
Expand Down Expand Up @@ -1088,6 +1090,27 @@ export class AppStore {
}
}

getBYOMSourceUrl() {
const {
owner,
repo,
contentSourceUrl,
contentSourceEditPattern,
} = this.siteStore;
if (!contentSourceEditPattern || typeof contentSourceEditPattern !== 'string') return undefined;

let { pathname } = this.location;
if (pathname.endsWith('/')) pathname += 'index';

const url = contentSourceEditPattern
.replace('{{contentSourceUrl}}', contentSourceUrl)
.replace('{{org}}', owner)
.replace('{{site}}', repo)
.replace('{{pathname}}', pathname);

return url;
}

/**
* Switches to (or opens) a given environment.
* @param {string} targetEnv One of the following environments:
Expand Down Expand Up @@ -1128,7 +1151,7 @@ export class AppStore {

if (targetEnv === 'edit') {
const updatedStatus = await this.fetchStatus(false, true);
envUrl = updatedStatus.edit && updatedStatus.edit.url;
envUrl = updatedStatus.edit?.url || this.getBYOMSourceUrl();
}

const [customView] = this.findViews(VIEWS.CUSTOM);
Expand Down
5 changes: 5 additions & 0 deletions src/extension/app/store/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ export class SiteStore {
lang,
contentSourceUrl,
contentSourceType,
editUrlLabel,
editUrlPattern,
previewHost,
liveHost,
outerHost: legacyLiveHost,
Expand Down Expand Up @@ -273,6 +275,9 @@ export class SiteStore {
this.giturl = giturl;
this.contentSourceUrl = contentSourceUrl;
this.contentSourceType = contentSourceType;
this.contentSourceEditLabel = editUrlLabel;
this.contentSourceEditPattern = editUrlPattern;

this.mountpoints = contentSourceUrl ? [contentSourceUrl] : (mountpoints || []);
[this.mountpoint] = this.mountpoints;
this.adminVersion = adminVersion;
Expand Down
2 changes: 2 additions & 0 deletions src/extension/types/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
* @prop {string} [liveHost] The host name of a custom live CDN
* @prop {string} [host] The production host name to publish content to
* @prop {string} [devOrigin] The origin of the local development environment
* @prop {string} [editUrlLabel] The custom label of the edit content source
* @prop {string} [editUrlPattern] The pattern of the edit content source
* @prop {string} [adminVersion] The specific version of admin service to use
* @prop {boolean} [disabled] Is the project disabled?
* @description Represents the sidekick configuration from the user via the options view
Expand Down
20 changes: 20 additions & 0 deletions test/app/store/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,20 @@ describe('Test App Store', () => {
expect(fetchStatusSpy.calledWith(false, true)).to.be.true;
});

it('switches from preview to BYOM editor', async () => {
instance.siteStore.contentSourceUrl = 'https://aemcloud.com';
instance.siteStore.contentSourceEditLabel = 'Universal Editor';
instance.siteStore.contentSourceEditPattern = '{{contentSourceUrl}}{{pathname}}?cmd=open';

const fetchStatusStub = sidekickTest.sandbox.stub(instance, 'fetchStatus');
fetchStatusStub.resolves({});

instance.location = new URL(mockStatus.preview.url);
instance.status = mockStatus;
await instance.switchEnv('edit');
expect(loadPage.calledWith('https://aemcloud.com/index?cmd=open')).to.be.true;
});

it('switches from live to preview', async () => {
instance.location = new URL(mockStatus.live.url);
instance.status = mockStatus;
Expand Down Expand Up @@ -1533,6 +1547,12 @@ describe('Test App Store', () => {
expect(instance.getContentSourceLabel()).to.equal('Google Drive');
});

it('should return "Document Authoring" if a label is provided', () => {
instance.siteStore.contentSourceType = 'markup';
instance.siteStore.contentSourceEditLabel = 'Document Authoring';
expect(instance.getContentSourceLabel()).to.equal('Document Authoring');
});

it('should return "BYOM" for everything else', () => {
instance.siteStore.contentSourceType = 'markup';
expect(instance.getContentSourceLabel()).to.equal('BYOM');
Expand Down
13 changes: 13 additions & 0 deletions test/app/store/site.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,18 @@ describe('Test Site Store', () => {
expect(appStore.siteStore.owner).to.equal('adobe');
expect(appStore.siteStore.repo).to.equal('aem-boilerplate');
});

it('with custom sourceEditUrl', async () => {
/**
* @type {SidekickOptionsConfig | ClientConfig}
*/
const config = {
...defaultConfig,
editUrlLabel: 'Universal Editor',
editUrlPattern: '{{contentSourceUrl}}{{pathname}}?cmd=open',
};
await appStore.loadContext(sidekickElement, config);
expect(appStore.siteStore.contentSourceEditLabel).to.equal('Universal Editor');
});
});
});

0 comments on commit c27170c

Please sign in to comment.