From 5675e83e4ba6deef31c7a80393cd17c4691be211 Mon Sep 17 00:00:00 2001 From: dobromirts Date: Mon, 24 Jun 2024 15:14:51 +0300 Subject: [PATCH 1/3] Handle different repos vnext namings --- src/app/services/code-view/angular-code-service.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/app/services/code-view/angular-code-service.ts b/src/app/services/code-view/angular-code-service.ts index 52b3296..aabc375 100644 --- a/src/app/services/code-view/angular-code-service.ts +++ b/src/app/services/code-view/angular-code-service.ts @@ -127,9 +127,6 @@ export class AngularCodeService extends CodeService { private getAngularGitHubSampleUrl(editor: string, sampleUrl: string, branch: string, demosBaseUrl: string) { const dvSample = this.isDvSample(demosBaseUrl, sampleUrl); - if (util.isLocalhost) { - branch = dvSample ? 'vnext' : 'vNext'; - } const repositoryPath = dvSample ? 'igniteui-angular-examples/tree/' : 'igniteui-live-editing-samples/tree/'; if (editor === "stackblitz") return `https://stackblitz.com/github/IgniteUI/${repositoryPath}${branch}/${sampleUrl}`; return `https://codesandbox.io/s/github/IgniteUI/${repositoryPath}${branch}/${sampleUrl}`; @@ -152,7 +149,9 @@ export class AngularCodeService extends CodeService { let demosBaseUrl = $codeView.attr(codeService.demosBaseUrlAttrName)!; let sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $codeView.attr(codeService.sampleUrlAttrName)!, $codeView.attr(codeService.githubSrc)!); let editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox"; - let branch = demosBaseUrl.indexOf("staging.infragistics.com") !== -1 ? "vNext" : "master"; + const dvSample = this.isDvSample(demosBaseUrl, sampleFileUrl); + const stagingBranch = dvSample ? 'vnext' : 'vNext'; + let branch = demosBaseUrl.indexOf("staging.infragistics.com") !== -1 ? stagingBranch : "master"; window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank'); codeService.isButtonClickInProgress = false; } From c0aebdb4bb702d5c028b957e7fce3304bc5af570 Mon Sep 17 00:00:00 2001 From: dobromirts Date: Mon, 24 Jun 2024 17:05:42 +0300 Subject: [PATCH 2/3] chore(*): update openLiveEditingSample method --- src/app/services/code-view/angular-code-service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/services/code-view/angular-code-service.ts b/src/app/services/code-view/angular-code-service.ts index aabc375..463c30e 100644 --- a/src/app/services/code-view/angular-code-service.ts +++ b/src/app/services/code-view/angular-code-service.ts @@ -146,12 +146,13 @@ export class AngularCodeService extends CodeService { private openLiveEditingSample($button: JQuery, $codeView: JQuery) { const codeService = this; codeService.isButtonClickInProgress = true; - let demosBaseUrl = $codeView.attr(codeService.demosBaseUrlAttrName)!; - let sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $codeView.attr(codeService.sampleUrlAttrName)!, $codeView.attr(codeService.githubSrc)!); - let editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox"; + const demosBaseUrl = $codeView.attr(codeService.demosBaseUrlAttrName)!; + const sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $codeView.attr(codeService.sampleUrlAttrName)!, $codeView.attr(codeService.githubSrc)!); + const editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox"; const dvSample = this.isDvSample(demosBaseUrl, sampleFileUrl); const stagingBranch = dvSample ? 'vnext' : 'vNext'; - let branch = demosBaseUrl.indexOf("staging.infragistics.com") !== -1 ? stagingBranch : "master"; + const url = new URL(demosBaseUrl); + const branch = url.hostname.includes("staging.infragistics.com") ? stagingBranch : "master"; window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank'); codeService.isButtonClickInProgress = false; } From 9bada098054a72855d859b003030d0723dd0a715 Mon Sep 17 00:00:00 2001 From: dobromirts Date: Mon, 24 Jun 2024 17:16:00 +0300 Subject: [PATCH 3/3] chore(*): enhance openLiveEditingSample with URL validation and handling --- .../code-view/angular-code-service.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/services/code-view/angular-code-service.ts b/src/app/services/code-view/angular-code-service.ts index 463c30e..5300ce5 100644 --- a/src/app/services/code-view/angular-code-service.ts +++ b/src/app/services/code-view/angular-code-service.ts @@ -146,14 +146,28 @@ export class AngularCodeService extends CodeService { private openLiveEditingSample($button: JQuery, $codeView: JQuery) { const codeService = this; codeService.isButtonClickInProgress = true; + const demosBaseUrl = $codeView.attr(codeService.demosBaseUrlAttrName)!; const sampleFileUrl = codeService.getGitHubSampleUrl(demosBaseUrl, $codeView.attr(codeService.sampleUrlAttrName)!, $codeView.attr(codeService.githubSrc)!); const editor = $button.hasClass(codeService.stkbButtonClass) ? "stackblitz" : "codesandbox"; const dvSample = this.isDvSample(demosBaseUrl, sampleFileUrl); - const stagingBranch = dvSample ? 'vnext' : 'vNext'; - const url = new URL(demosBaseUrl); - const branch = url.hostname.includes("staging.infragistics.com") ? stagingBranch : "master"; - window.open(codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl), '_blank'); + + let branch: string; + try { + let urlObj = new URL(demosBaseUrl); + if (urlObj.hostname === "staging.infragistics.com") { + branch = dvSample ? 'vnext' : 'vNext'; + } else { + branch = "master"; + } + } catch (e) { + console.error("Invalid URL:", demosBaseUrl); + codeService.isButtonClickInProgress = false; + return; + } + let url = codeService.getAngularGitHubSampleUrl(editor, sampleFileUrl, branch, demosBaseUrl); + + window.open(url, '_blank'); codeService.isButtonClickInProgress = false; }