Skip to content

Commit e2d54e0

Browse files
committed
Using 'import' also for two ADO API components.
1 parent 6b6a7ed commit e2d54e0

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

src/Globals.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,22 @@
33

44
// @ts-check
55

6+
import { WorkItemTrackingRestClient } from 'azure-devops-extension-api/WorkItemTracking';
7+
import { CommonServiceIds } from 'azure-devops-extension-api/Common/CommonServices';
8+
9+
610
// WorkItemTrackingRestClient: https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/workitemtrackingrestclient
711
export var gWorkItemRESTClient;
812

913
// ILocationService: https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/ilocationservice
1014
export var gLocationService;
1115

12-
// An enum that holds the known field types. E.g. gFieldTypeEnum.Html === 4.
13-
// It is basically https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/fieldtype,
14-
// except that this documentation is incorrect (it shows the wrong numerical ids). (Apparently, the enum 'FieldType'
15-
// exists several times in the API with different definitions, and the tool that creates the documentation cannot handle it?)
16-
// The correct one is this:
17-
// https://github.com/microsoft/azure-devops-node-api/blob/fa534aef7d79ab4a30ae2b8823654795b6eed1aa/api/interfaces/WorkItemTrackingInterfaces.ts#L460
18-
export var gFieldTypeEnum;
1916

20-
21-
export async function InitSharedGlobals(adoSDK, adoAPI, adoCommonServices, workItemTracking)
17+
export async function InitSharedGlobals(adoSDK, adoAPI)
2218
{
23-
gFieldTypeEnum = workItemTracking.FieldType;
24-
25-
gLocationService = await adoSDK.getService(adoCommonServices.CommonServiceIds.LocationService);
19+
gLocationService = await adoSDK.getService(CommonServiceIds.LocationService);
2620

2721
// getClient(): https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/#azure-devops-extension-api-getclient
2822
// Gives a WorkItemTrackingRestClient: https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/workitemtrackingrestclient
29-
gWorkItemRESTClient = adoAPI.getClient(workItemTracking.WorkItemTrackingRestClient);
23+
gWorkItemRESTClient = adoAPI.getClient(WorkItemTrackingRestClient);
3024
}

src/HistoryDiffPageScript.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { COMMENT_UPDATE_ID, GetCommentsWithHistory, GetTableInfosForEachComment
77
import { InitSharedGlobals } from './Globals.js';
88
import { GetAllRevisionUpdates, GetTableInfosForEachRevisionUpdate } from './RevisionUpdates.js';
99
import { FormatDate, GetIdentityAvatarHtml, GetIdentityName } from './Utils.js';
10+
import { WorkItemTrackingServiceIds } from 'azure-devops-extension-api/WorkItemTracking';
1011

1112

1213
var gAdoSDK;
1314
var gAdoAPI;
14-
var gWorkItemFormServiceId;
1515
var gUnloadedCalled = false;
1616

1717

@@ -145,7 +145,7 @@ async function LoadAndSetDiffInHTMLDocument()
145145
// Not stored as global variable during initialization because the instance is tied to a certain work item,
146146
// and when the 'onLoaded' event is called, we might have switched to another work item. So need to get it again.
147147
const [workItemFormService, projectName] = await Promise.all([
148-
gAdoSDK.getService(gWorkItemFormServiceId),
148+
gAdoSDK.getService(WorkItemTrackingServiceIds.WorkItemFormService),
149149
GetProjectName()
150150
]);
151151

@@ -319,7 +319,7 @@ function CreateWorkItemPageEvents()
319319
// encountered. For example, if there are two successive bugs, the user shows the history diff on the first bug,
320320
// then moves on to the next bug, ADO will show immediately our history diff tab, but this function is not called
321321
// again. Instead, the 'onUnloaded' and 'onLoaded' events are called (see CreateWorkItemPageEvents()).
322-
async function InitializeHistoryDiff(adoSDK, adoAPI, workItemTracking, adoCommonServices)
322+
async function InitializeHistoryDiff(adoSDK, adoAPI)
323323
{
324324
// Called by the ADO API after the client received and applied the ADO theme. Also called when the user changes the theme
325325
// while our extension is already loaded. The event doesn't seem to be documented, but it can be seen in the source:
@@ -345,9 +345,8 @@ async function InitializeHistoryDiff(adoSDK, adoAPI, workItemTracking, adoCommon
345345

346346
gAdoSDK = adoSDK;
347347
gAdoAPI = adoAPI;
348-
gWorkItemFormServiceId = workItemTracking.WorkItemTrackingServiceIds.WorkItemFormService;
349348

350-
await InitSharedGlobals(adoSDK, adoAPI, adoCommonServices, workItemTracking);
349+
await InitSharedGlobals(adoSDK, adoAPI);
351350

352351
// We first get the work item revisions from ADO, and only then tell ADO that we have loaded successfully.
353352
// This causes ADO to show the 'spinning loading indicator' until we are ready.
@@ -358,12 +357,10 @@ async function InitializeHistoryDiff(adoSDK, adoAPI, workItemTracking, adoCommon
358357

359358

360359
require(['azure-devops-extension-sdk',
361-
'azure-devops-extension-api',
362-
'azure-devops-extension-api/WorkItemTracking',
363-
'azure-devops-extension-api/Common/CommonServices'
360+
'azure-devops-extension-api'
364361
],
365362
// @ts-ignore
366-
function (adoSDK, adoAPI, workItemTracking, adoCommonServices) {
367-
InitializeHistoryDiff(adoSDK, adoAPI, workItemTracking, adoCommonServices);
363+
function (adoSDK, adoAPI) {
364+
InitializeHistoryDiff(adoSDK, adoAPI);
368365
}
369366
);

src/RevisionUpdates.js

+31-22
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33

44
// @ts-check
55

6-
import { TryGetHTMLLinkNameAndUrlForArtifactLink } from "./ArtifactLinkToURL";
7-
import { gFieldTypeEnum, gWorkItemRESTClient } from "./Globals";
8-
import { EscapeHtml, FormatDate, GetIdentityAvatarHtml, GetIdentityName, RemoveStyle } from "./Utils";
6+
import { TryGetHTMLLinkNameAndUrlForArtifactLink } from './ArtifactLinkToURL';
7+
import { gWorkItemRESTClient } from './Globals';
8+
import { EscapeHtml, FormatDate, GetIdentityAvatarHtml, GetIdentityName, RemoveStyle } from './Utils';
99
// @ts-ignore
1010
import * as htmldiff from 'node-htmldiff';
1111

12+
// An enum that holds the known field types. E.g. FieldTypeEnum.Html === 4.
13+
// It is basically https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/fieldtype,
14+
// except that this documentation is incorrect (it shows the wrong numerical ids). (Apparently, the enum 'FieldType'
15+
// exists several times in the API with different definitions, and the tool that creates the documentation cannot handle it?)
16+
// The correct one is this:
17+
// https://github.com/microsoft/azure-devops-node-api/blob/fa534aef7d79ab4a30ae2b8823654795b6eed1aa/api/interfaces/WorkItemTrackingInterfaces.ts#L460
18+
import { FieldType as FieldTypeEnum } from 'azure-devops-extension-api/WorkItemTracking';
19+
20+
1221

1322
export async function GetTableInfosForEachRevisionUpdate(revisionUpdates, fieldsPropertiesMap, currentProjectName)
1423
{
@@ -243,7 +252,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
243252
}
244253

245254
if (fieldReferenceName === 'Microsoft.VSTS.TCM.Steps') {
246-
// The steps of a test case show up as a field of type 'gFieldTypeEnum.Html', which is lie. It does not contain valid html that
255+
// The steps of a test case show up as a field of type 'FieldTypeEnum.Html', which is lie. It does not contain valid html that
247256
// a browser can display. It seems to be simply XML, with each individual step description being (escaped) html.
248257
// TODO: Can we still show a meaningful proper diff?
249258
// https://devblogs.microsoft.com/devops/how-to-use-test-step-using-rest-client-helper/
@@ -254,7 +263,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
254263
else if (fieldReferenceName === 'Microsoft.VSTS.TCM.Parameters') {
255264
// This field is used in 'shared parameter set' work items, which are work items that can be referenced by test case items.
256265
// https://learn.microsoft.com/en-us/azure/devops/test/repeat-test-with-different-data?view=azure-devops#share-parameters-between-test-cases
257-
// The field type is reported as 'gFieldTypeEnum.Html', although in reality it is some general XML. For example:
266+
// The field type is reported as 'FieldTypeEnum.Html', although in reality it is some general XML. For example:
258267
// "<parameterSet><paramNames><param>someVar</param><param>var</param></paramNames><paramData lastId=\"1\"><dataRow id=\"1\"><kvp key=\"someVar\" value=\"test value\"/><kvp key=\"var\" value=\"another value\"/></dataRow></paramData></parameterSet>"
259268
return '(Showing the diff of a shared parameter set is not supported.)';
260269
}
@@ -265,11 +274,11 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
265274
return '(Showing the diff of parameter values is not supported.)';
266275
}
267276

268-
// Azure DevOps (at least 2019) reports identities (e.g. the 'System.CreatedBy' field) as 'gFieldTypeEnum.String', but the 'isIdentity' flag is set.
277+
// Azure DevOps (at least 2019) reports identities (e.g. the 'System.CreatedBy' field) as 'FieldTypeEnum.String', but the 'isIdentity' flag is set.
269278
// An identity is probably an 'IdentityReference': https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-api/identityreference
270279
let fieldType = fieldsPropertiesMap?.[fieldReferenceName]?.type;
271280
if (fieldsPropertiesMap?.[fieldReferenceName]?.isIdentity) {
272-
fieldType = gFieldTypeEnum.Identity;
281+
fieldType = FieldTypeEnum.Identity;
273282
}
274283
// Note for picklists: It seems that they are used only for user-added fields. They appear as combo boxes.
275284
// Similar to identities, picklists are also identified via an additional flag in the 'WorkItemField' interface. So PicklistString,
@@ -279,7 +288,7 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
279288
// simply treat picklists as a string/integer/double.
280289

281290
switch (fieldType) {
282-
case gFieldTypeEnum.Html:
291+
case FieldTypeEnum.Html:
283292
return DiffHtmlText(value.oldValue, value.newValue);
284293

285294
// 'History' means the comments. Unfortunately, they are quite special: When a user adds a new comment, it shows
@@ -290,11 +299,11 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
290299
// => We actually filter out the 'System.History' entry somewhere else. I think that apart from 'System.History',
291300
// no other field can use the 'History' field type. Hence, this code here is probably dead. We have dedicated REST
292301
// API requests somewhere else to get the history of comments.
293-
case gFieldTypeEnum.History:
302+
case FieldTypeEnum.History:
294303
return value.hasOwnProperty('newValue') ? `<ins class="diffCls">${RemoveStyle(value.newValue)}</ins>` : '';
295304

296-
case gFieldTypeEnum.String:
297-
case gFieldTypeEnum.PlainText:
305+
case FieldTypeEnum.String:
306+
case FieldTypeEnum.PlainText:
298307
{
299308
// We simply feed htmldiff the values with escaped special characters, meaning that htmldiff should not see any HTML elements.
300309
// Using a different diff-library (jsdiff or diff-match-patch) is not worth the additional dependency, since the only work item
@@ -309,27 +318,27 @@ function GetDiffFromUpdatedField(fieldsPropertiesMap, fieldReferenceName, value)
309318
return diff;
310319
}
311320

312-
case gFieldTypeEnum.Integer:
313-
case gFieldTypeEnum.PicklistInteger: // See note above: Shouldn't appear, but if it does, can be treated as integer.
314-
case gFieldTypeEnum.Double:
315-
case gFieldTypeEnum.PicklistDouble: // See note above: Shouldn't appear, but if it does, can be treated as double.
316-
case gFieldTypeEnum.PicklistString: // See note above: Shouldn't appear, but if it does, can be treated as string.
317-
case gFieldTypeEnum.Guid: // Guids are given as plain strings.
318-
case gFieldTypeEnum.Boolean:
319-
case gFieldTypeEnum.TreePath:
321+
case FieldTypeEnum.Integer:
322+
case FieldTypeEnum.PicklistInteger: // See note above: Shouldn't appear, but if it does, can be treated as integer.
323+
case FieldTypeEnum.Double:
324+
case FieldTypeEnum.PicklistDouble: // See note above: Shouldn't appear, but if it does, can be treated as double.
325+
case FieldTypeEnum.PicklistString: // See note above: Shouldn't appear, but if it does, can be treated as string.
326+
case FieldTypeEnum.Guid: // Guids are given as plain strings.
327+
case FieldTypeEnum.Boolean:
328+
case FieldTypeEnum.TreePath:
320329
return (value.hasOwnProperty('oldValue') ? `<del class="diffCls">${EscapeHtml(value.oldValue)}</del>` : '')
321330
+ (value.hasOwnProperty('newValue') ? `<ins class="diffCls">${EscapeHtml(value.newValue)}</ins>` : '');
322331

323-
case gFieldTypeEnum.DateTime:
332+
case FieldTypeEnum.DateTime:
324333
return (value.hasOwnProperty('oldValue') ? `<del class="diffCls">${FormatDate(value.oldValue)}</del>` : '')
325334
+ (value.hasOwnProperty('newValue') ? `<ins class="diffCls">${FormatDate(value.newValue)}</ins>` : '');
326335

327-
case gFieldTypeEnum.Identity:
336+
case FieldTypeEnum.Identity:
328337
return (value.hasOwnProperty('oldValue') ? `<del class="diffCls">${FormatIdentityForFieldDiff(value.oldValue)}</del>` : '')
329338
+ (value.hasOwnProperty('newValue') ? `<ins class="diffCls">${FormatIdentityForFieldDiff(value.newValue)}</ins>` : '');
330339

331340
default:
332-
console.log(`HistoryDiff: Unknown field type '${fieldType}' (${gFieldTypeEnum?.[fieldType]}), oldValueType: ${typeof value.oldValue}, newValueType: ${typeof value.newValue}`);
341+
console.log(`HistoryDiff: Unknown field type '${fieldType}' (${FieldTypeEnum?.[fieldType]}), oldValueType: ${typeof value.oldValue}, newValueType: ${typeof value.newValue}`);
333342
return undefined;
334343
}
335344
}

vss-extension.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "HistoryDiff",
44
"publisher": "Sedenion",
5-
"version": "1.3.0.33",
5+
"version": "1.3.0.37",
66
"name": "History Diff",
77
"description": "Azure DevOps extension to show the history of work item fields with proper diffs.",
88
"public": true,

0 commit comments

Comments
 (0)