Skip to content

Commit 8a077fb

Browse files
authored
Merge pull request #1517 from Esri/layer-subtypes
get tracking view settings
2 parents 4a07f47 + dbe6d63 commit 8a077fb

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

packages/common/src/featureServiceHelpers.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,33 @@ export function _updateTypeKeywords(itemTemplate: IItemTemplate, createResponse:
436436
return itemTemplate;
437437
}
438438

439+
/**
440+
* Add layer urls from tracking views to the templateDictionary to be used for adlib replacements
441+
*
442+
* @param itemTemplate Item to be created; n.b.: this item is modified
443+
* @param templateDictionary Hash mapping property names to replacement values
444+
* @returns void
445+
* @private
446+
*/
447+
export function _setTrackingViewLayerSettings(itemTemplate: IItemTemplate, templateDictionary: any): void {
448+
const url = itemTemplate.item.url;
449+
const newId = itemTemplate.itemId;
450+
let k;
451+
Object.keys(templateDictionary).some((_k) => {
452+
if (newId === templateDictionary[_k].itemId) {
453+
k = _k;
454+
return true;
455+
}
456+
});
457+
458+
itemTemplate.properties.layers.forEach((l) => {
459+
const id = l.id.toString();
460+
templateDictionary[k][`layer${id}`] = {
461+
url: checkUrlPathTermination(url) + id,
462+
};
463+
});
464+
}
465+
439466
/**
440467
* Create the name mapping object that will allow for all templatized field
441468
* references to be de-templatized.
@@ -759,6 +786,7 @@ export function addFeatureServiceLayersAndTables(
759786
): Promise<void> {
760787
return new Promise((resolve, reject) => {
761788
if (isTrackingViewTemplate(itemTemplate)) {
789+
_setTrackingViewLayerSettings(itemTemplate, templateDictionary);
762790
resolve(null);
763791
} else {
764792
// Create a hash of various properties that contain field references

packages/common/test/featureServiceHelpers.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
587587
displayField: "DisplayField",
588588
editFieldsInfo: ["CreateDate"],
589589
subtypeField: "SubtypeField",
590-
subtypes: [{a:"A"}],
590+
subtypes: [{ a: "A" }],
591591
templates: [
592592
{
593593
A: null,
@@ -654,7 +654,7 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
654654
],
655655
editFieldsInfo: ["CreateDate"],
656656
subtypeField: "SubtypeField",
657-
subtypes: [{a:"A"}],
657+
subtypes: [{ a: "A" }],
658658
templates: [
659659
{
660660
A: null,
@@ -3517,25 +3517,42 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
35173517
).toBeRejected();
35183518
});
35193519

3520-
it("should skip tracking view", async () => {
3520+
it("should skip tracking view and collect replacement details", async () => {
35213521
const expectedUrl: string =
35223522
"https://services123.arcgis.com/org1234567890/arcgis/rest/services/ROWPermits_publiccomment/FeatureServer";
3523+
const itemId = "aaaaf0ffbdf042adb4ad24124b378d20";
3524+
const sourceItemId = "bbbaf0ffbdf042adb4ad24124b378d20";
35233525

35243526
itemTemplate = templates.getItemTemplate("Feature Service", [], expectedUrl);
35253527
itemTemplate.item.typeKeywords = ["Location Tracking View"];
35263528
itemTemplate.item.properties = {
35273529
trackViewGroup: "grp123",
35283530
};
3531+
itemTemplate.itemId = itemId;
3532+
3533+
const templateDictionary = {};
3534+
templateDictionary[sourceItemId] = {
3535+
itemId,
3536+
};
35293537

35303538
await addFeatureServiceLayersAndTables(
35313539
itemTemplate,
3532-
{},
3540+
templateDictionary,
35333541
{
35343542
layers: [],
35353543
tables: [],
35363544
},
35373545
MOCK_USER_SESSION,
35383546
);
3547+
3548+
const expectedTemplateDictionary = {
3549+
itemId,
3550+
layer0: {
3551+
url: `${expectedUrl}/0`,
3552+
},
3553+
};
3554+
3555+
expect(expectedTemplateDictionary).toEqual(templateDictionary[sourceItemId] as any);
35393556
});
35403557
});
35413558

packages/common/test/restHelpers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
19291929
contingentValues,
19301930
subtypeField: "SubtypeField",
19311931
defaultSubtypeCode: "0",
1932-
subtypes: [{a: "A"}]
1932+
subtypes: [{ a: "A" }],
19331933
},
19341934
};
19351935

@@ -1976,7 +1976,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
19761976
url: adminUrl + "0/updateDefinition",
19771977
params: {
19781978
updateDefinition: {
1979-
subtypeField: "SubtypeField"
1979+
subtypeField: "SubtypeField",
19801980
},
19811981
},
19821982
args,
@@ -1985,7 +1985,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
19851985
url: adminUrl + "0/updateDefinition",
19861986
params: {
19871987
updateDefinition: {
1988-
defaultSubtypeCode: "0"
1988+
defaultSubtypeCode: "0",
19891989
},
19901990
},
19911991
args,
@@ -1994,7 +1994,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
19941994
url: adminUrl + "0/addToDefinition",
19951995
params: {
19961996
addToDefinition: {
1997-
subtypes: [{a: "A"}]
1997+
subtypes: [{ a: "A" }],
19981998
},
19991999
},
20002000
args,

0 commit comments

Comments
 (0)