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

feat: preview a visualforce page with open command #418

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ OPTIONS

DESCRIPTION
Opens the specified Lightning Page in Lightning App Builder. Lightning Page files have the suffix .flexipage-meta.xml,
and are stored in the flexipages directory. If you specify a different type of file, this command opens your org’s
and are stored in the flexipages directory. If you specify a visualforce page (with a .page suffix) this command let you preview your visualforce page. If you specify a different type of file, this command opens your org’s
home page.

The file opens in your default browser.
Expand Down
2 changes: 1 addition & 1 deletion messages/open.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "edit a Lightning Page with Lightning App Builder\nOpens the specified Lightning Page in Lightning App Builder. Lightning Page files have the suffix .flexipage-meta.xml, and are stored in the flexipages directory. If you specify a different type of file, this command opens your org’s home page.\n\nThe file opens in your default browser.\nIf no browser-based editor is available for the selected file, this command opens your org's home page.\nTo generate a URL for the browser-based editor but not open the editor, use --urlonly.",
"description": "edit a Lightning Page with Lightning App Builder\nOpens the specified Lightning Page in Lightning App Builder. Lightning Page files have the suffix .flexipage-meta.xml, and are stored in the flexipages directory. \nIf you specify a Visualforce page, which has a .page suffix, the page opens in your browser so you can preview it. If you specify a different type of file, this command opens your org’s home page.\n\nThe file opens in your default browser.\nIf no browser-based editor is available for the selected file, this command opens your org's home page.\nTo generate a URL for the browser-based editor but not open the editor, use --urlonly.",
"examples": [
"$ sfdx force:source:open -f path/to/source",
"$ sfdx force:source:open -r -f path/to/source",
Expand Down
36 changes: 24 additions & 12 deletions src/commands/force/source/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export class Open extends SourceCommand {

private async doOpen(): Promise<void> {
const typeName = this.getTypeNameDefinitionByFileName(path.resolve(this.flags.sourcefile as string));
const openPath = typeName === 'FlexiPage' ? await this.setUpOpenPath() : await this.buildFrontdoorUrl();
let openPath;
if (typeName === 'FlexiPage' || typeName === 'ApexPage') {
// if it is a lightning page
openPath = await this.setUpOpenPath(typeName);
} else {
openPath = await this.buildFrontdoorUrl();
}

this.openResult = await this.open(openPath);
}
Expand Down Expand Up @@ -98,18 +104,24 @@ export class Open extends SourceCommand {
return this.flags.urlonly ? result : this.openBrowser(url, result);
}

private async setUpOpenPath(): Promise<string> {
private async setUpOpenPath(pageType: string): Promise<string> {
try {
const flexipage = await this.org
.getConnection()
.singleRecordQuery<{ Id: string }>(
`SELECT id FROM flexipage WHERE DeveloperName='${path.basename(
this.flags.sourcefile as string,
'.flexipage-meta.xml'
)}'`,
{ tooling: true }
);
return `/visualEditor/appBuilder.app?pageId=${flexipage.Id}`;
if (pageType === 'FlexiPage') {
const flexipage = await this.org
.getConnection()
.singleRecordQuery<{ Id: string }>(
`SELECT id FROM flexipage WHERE DeveloperName='${path.basename(
this.flags.sourcefile as string,
'.flexipage-meta.xml'
)}'`,
{ tooling: true }
);
return `/visualEditor/appBuilder.app?pageId=${flexipage.Id}`;
} else if (pageType === 'ApexPage') {
return `/apex/${path.basename(this.flags.sourcefile as string, '.page')}`;
} else {
return '_ui/flexipage/ui/FlexiPageFilterListPage';
}
} catch (error) {
return '_ui/flexipage/ui/FlexiPageFilterListPage';
}
Expand Down
26 changes: 26 additions & 0 deletions test/commands/source/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ describe('force:source:open', () => {
},
},
] as SourceComponent[];
const apexPageComponents = [
{
name: 'MyPage',
type: {
id: 'page',
name: 'ApexPage',
suffix: 'page',
directoryName: 'pages',
inFolder: false,
strictDirectoryName: false,
},
},
] as SourceComponent[];
const testIp = '1.1.1.1';
const orgId = '00DJ0000003htplMAA';
const defaultDir = join('my', 'default', 'package');
Expand Down Expand Up @@ -108,6 +121,9 @@ describe('force:source:open', () => {
if (fsPath.includes('layout')) {
return layoutComponents;
}
if (fsPath.includes('page')) {
return apexPageComponents;
}
}
);
stubMethod(sandbox, MyDomainResolver.prototype, 'resolve').resolves(testIp);
Expand Down Expand Up @@ -140,4 +156,14 @@ describe('force:source:open', () => {
url: `${frontDoorUrl}&retURL=${encodeURIComponent(decodeURIComponent(frontDoorUrl))}`,
});
});

it('given a visualforce page url return /apex/pagename', async () => {
const sourcefile = 'force-app/main/default/pages/MyPage.page';
const result = await runOpenCmd(['--sourcefile', sourcefile, '--json', '--urlonly']);
expect(result).to.deep.equal({
orgId,
username,
url: `${frontDoorUrl}&retURL=%2Fapex%2FMyPage`,
});
});
});