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

Append serverless project ID to Support URL #171448

Merged
41 changes: 39 additions & 2 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ describe('Cloud Plugin', () => {
return { coreSetup, plugin };
};

it('registers help support URL', async () => {
const { plugin } = startPlugin();
it('registers help support URL: default', async () => {
const { plugin } = startPlugin({
id: undefined,
});

const coreStart = coreMock.createStart();
plugin.start(coreStart);
Expand All @@ -211,6 +213,41 @@ describe('Cloud Plugin', () => {
`);
});

it('registers help support URL: serverless projects', async () => {
const { plugin } = startPlugin({
id: 'my-awesome-project-id',
serverless: {
project_id: 'my-awesome-serverless-project-id',
},
});

const coreStart = coreMock.createStart();
plugin.start(coreStart);

expect(coreStart.chrome.setHelpSupportUrl).toHaveBeenCalledTimes(1);
expect(coreStart.chrome.setHelpSupportUrl.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://support.elastic.co/?serverless_project_id=my-awesome-serverless-project-id",
]
`);
});

it('registers help support URL: non-serverless projects', async () => {
const { plugin } = startPlugin({
id: 'my-awesome-project-id',
});

const coreStart = coreMock.createStart();
plugin.start(coreStart);

expect(coreStart.chrome.setHelpSupportUrl).toHaveBeenCalledTimes(1);
expect(coreStart.chrome.setHelpSupportUrl.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://support.elastic.co/?cloud_deployment_id=my-awesome-project-id",
]
`);
});

describe('isServerlessEnabled', () => {
it('is `true` when `serverless.projectId` is set', () => {
const { plugin } = startPlugin({
Expand Down
10 changes: 9 additions & 1 deletion x-pack/plugins/cloud/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ export class CloudPlugin implements Plugin<CloudSetup> {
}

public start(coreStart: CoreStart): CloudStart {
coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK);
let supportUrl = ELASTIC_SUPPORT_LINK;
if (this.config.serverless?.project_id) {
// serverless projects use config.id and config.serverless.project_id
supportUrl += '?serverless_project_id=' + this.config.serverless.project_id;
} else if (this.config.id) {
// non-serverless Cloud projects only use config.id
supportUrl += '?cloud_deployment_id=' + this.config.id;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I would extract that to an getSupportUrl(config: CloudConfigType): string helper function

coreStart.chrome.setHelpSupportUrl(supportUrl);

// Nest all the registered context providers under the Cloud Services Provider.
// This way, plugins only need to require Cloud's context provider to have all the enriched Cloud services.
Expand Down