From af102b4ed051571ee8cd8e13100acd28e520a4ac Mon Sep 17 00:00:00 2001 From: Kees Schollaart Date: Thu, 15 Mar 2018 21:09:35 +0100 Subject: [PATCH] ExtensionDataService keys can be max 50 characters, temporary implementation / fix. --- src/sprint-goal.ts | 60 +++++++++++++++++++++++++++++++++------------- vss-extension.json | 2 +- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/sprint-goal.ts b/src/sprint-goal.ts index c606bdc..b862094 100644 --- a/src/sprint-goal.ts +++ b/src/sprint-goal.ts @@ -9,7 +9,7 @@ import StatusIndicator = require("VSS/Controls/StatusIndicator"); import sg = require("./SprintGoalApplicationInsightsWrapper"); export class SprintGoal { - private iterationId: number; + private iterationId: string; private teamId: string; private storageUri: string; private waitControl: StatusIndicator.WaitControl; @@ -134,15 +134,21 @@ export class SprintGoal { } public getSprintGoalFromCookie = (): SprintGoalDto => { - var goal = this.getCookie(this.iterationId + this.teamId + "goalText"); + var goal = this.getCookie(this.getConfigKey(this.iterationId, this.teamId) + "goalText"); + var sprintGoalInTabLabel = false; - if (!goal) { - goal = this.getCookie(this.iterationId + "goalText"); - sprintGoalInTabLabel = (this.getCookie(this.iterationId + "sprintGoalInTabLabel") == "true"); - } - else { - // team specific setting - sprintGoalInTabLabel = (this.getCookie(this.iterationId + this.teamId + "sprintGoalInTabLabel") == "true"); + if (goal) { + sprintGoalInTabLabel = (this.getCookie(this.getConfigKey(this.iterationId, this.teamId) + "sprintGoalInTabLabel") == "true"); + + } else { + var goal = this.getCookie(this.iterationId + this.teamId + "goalText"); + if (goal) { + sprintGoalInTabLabel = (this.getCookie(this.iterationId + this.teamId + "sprintGoalInTabLabel") == "true"); + } + else { + goal = this.getCookie(this.iterationId + "goalText"); + sprintGoalInTabLabel = (this.getCookie(this.iterationId + "sprintGoalInTabLabel") == "true"); + } } if (!goal) return undefined; @@ -168,7 +174,7 @@ export class SprintGoal { if (this.ai) this.ai.trackEvent("SaveSettings", sprintConfig); var configIdentifier: string = this.iterationId.toString(); - var configIdentifierWithTeam: string = this.iterationId.toString() + this.teamId; + var configIdentifierWithTeam: string = this.getConfigKey(this.iterationId, this.teamId); this.updateSprintGoalCookie(configIdentifier, sprintConfig); this.updateSprintGoalCookie(configIdentifierWithTeam, sprintConfig); @@ -196,7 +202,8 @@ export class SprintGoal { if (forceReload || !currentGoalInCookie || !cookieSupport) { var configIdentifier = this.iterationId.toString(); - var configIdentifierWithTeam = this.iterationId.toString() + this.teamId; + var oldConfigIdentifierWithTeam = this.iterationId.toString() + this.teamId; + var configIdentifierWithTeam = this.getConfigKey(this.iterationId, this.teamId); return this.fetchSettingsFromExtensionDataService(configIdentifierWithTeam).then((teamGoal: SprintGoalDto): IPromise => { if (teamGoal) { @@ -209,13 +216,27 @@ export class SprintGoal { }); } else { - // fallback, also for backward compatibility: project/iteration level settings - return this.fetchSettingsFromExtensionDataService(configIdentifier).then((iterationGoal) => { - if (iterationGoal) { - this.updateSprintGoalCookie(configIdentifier, iterationGoal); + return this.fetchSettingsFromExtensionDataService(oldConfigIdentifierWithTeam).then((oldTeamGoal) => { + if (oldTeamGoal) { + this.updateSprintGoalCookie(configIdentifier, oldTeamGoal); + this.updateSprintGoalCookie(configIdentifierWithTeam, oldTeamGoal); + return oldTeamGoal; } - return iterationGoal; + else return null; + }).then((goal) => { + if (goal) { + return Q.fcall((): SprintGoalDto => { + return goal; + }); + } + return this.fetchSettingsFromExtensionDataService(configIdentifier).then((iterationGoal) => { + if (iterationGoal) { + this.updateSprintGoalCookie(configIdentifier, iterationGoal); + } + return iterationGoal; + }) }); + } }); } @@ -246,6 +267,11 @@ export class SprintGoal { }); } + private getConfigKey = (iterationId: string, teamId: string) => { + // https://github.com/Microsoft/vss-web-extension-sdk/issues/75 + return iterationId.toString().substring(0, 15) + teamId.toString().substring(0, 15) + } + private updateSprintGoalCookie = (key: string, sprintGoal: SprintGoalDto) => { this.setCookie(key + "goalText", sprintGoal.goal); this.setCookie(key + "sprintGoalInTabLabel", sprintGoal.sprintGoalInTabLabel); @@ -256,7 +282,7 @@ export class SprintGoal { $("#cookieWarning").show(); } if (!sprintGoal) { - $("#sprintGoalInTabLabel").prop("checked", false); + $("#sprintGoalInTabLabel").prop("checked", true); $("#goal").val("") } else { diff --git a/vss-extension.json b/vss-extension.json index aa4b0e1..9db5963 100644 --- a/vss-extension.json +++ b/vss-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "id": "sprint-goal", "name": "Sprint Goal", - "version": "3.0.45", + "version": "3.1.0", "publisher": "keesschollaart", "public": true, "helpMarkDown": "[More Information](https://github.com/keesschollaart81/vsts-sprint-goal)",