diff --git a/packages/common/src/featureServiceHelpers.ts b/packages/common/src/featureServiceHelpers.ts index 2e5486b6c..3c57e34d1 100644 --- a/packages/common/src/featureServiceHelpers.ts +++ b/packages/common/src/featureServiceHelpers.ts @@ -436,6 +436,33 @@ export function _updateTypeKeywords(itemTemplate: IItemTemplate, createResponse: return itemTemplate; } +/** + * Add layer urls from tracking views to the templateDictionary to be used for adlib replacements + * + * @param itemTemplate Item to be created; n.b.: this item is modified + * @param templateDictionary Hash mapping property names to replacement values + * @returns void + * @private + */ +export function _setTrackingViewLayerSettings(itemTemplate: IItemTemplate, templateDictionary: any): void { + const url = itemTemplate.item.url; + const newId = itemTemplate.itemId; + let k; + Object.keys(templateDictionary).some((_k) => { + if (newId === templateDictionary[_k].itemId) { + k = _k; + return true; + } + }); + + itemTemplate.properties.layers.forEach((l) => { + const id = l.id.toString(); + templateDictionary[k][`layer${id}`] = { + url: checkUrlPathTermination(url) + id, + }; + }); +} + /** * Create the name mapping object that will allow for all templatized field * references to be de-templatized. @@ -759,6 +786,7 @@ export function addFeatureServiceLayersAndTables( ): Promise { return new Promise((resolve, reject) => { if (isTrackingViewTemplate(itemTemplate)) { + _setTrackingViewLayerSettings(itemTemplate, templateDictionary); resolve(null); } else { // Create a hash of various properties that contain field references diff --git a/packages/common/test/featureServiceHelpers.test.ts b/packages/common/test/featureServiceHelpers.test.ts index 419a90940..0bac04b64 100644 --- a/packages/common/test/featureServiceHelpers.test.ts +++ b/packages/common/test/featureServiceHelpers.test.ts @@ -587,7 +587,7 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service displayField: "DisplayField", editFieldsInfo: ["CreateDate"], subtypeField: "SubtypeField", - subtypes: [{a:"A"}], + subtypes: [{ a: "A" }], templates: [ { A: null, @@ -654,7 +654,7 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service ], editFieldsInfo: ["CreateDate"], subtypeField: "SubtypeField", - subtypes: [{a:"A"}], + subtypes: [{ a: "A" }], templates: [ { A: null, @@ -3517,25 +3517,42 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service ).toBeRejected(); }); - it("should skip tracking view", async () => { + it("should skip tracking view and collect replacement details", async () => { const expectedUrl: string = "https://services123.arcgis.com/org1234567890/arcgis/rest/services/ROWPermits_publiccomment/FeatureServer"; + const itemId = "aaaaf0ffbdf042adb4ad24124b378d20"; + const sourceItemId = "bbbaf0ffbdf042adb4ad24124b378d20"; itemTemplate = templates.getItemTemplate("Feature Service", [], expectedUrl); itemTemplate.item.typeKeywords = ["Location Tracking View"]; itemTemplate.item.properties = { trackViewGroup: "grp123", }; + itemTemplate.itemId = itemId; + + const templateDictionary = {}; + templateDictionary[sourceItemId] = { + itemId, + }; await addFeatureServiceLayersAndTables( itemTemplate, - {}, + templateDictionary, { layers: [], tables: [], }, MOCK_USER_SESSION, ); + + const expectedTemplateDictionary = { + itemId, + layer0: { + url: `${expectedUrl}/0`, + }, + }; + + expect(expectedTemplateDictionary).toEqual(templateDictionary[sourceItemId] as any); }); }); diff --git a/packages/common/test/restHelpers.test.ts b/packages/common/test/restHelpers.test.ts index 98ba645fc..2ce47baf8 100644 --- a/packages/common/test/restHelpers.test.ts +++ b/packages/common/test/restHelpers.test.ts @@ -1929,7 +1929,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack contingentValues, subtypeField: "SubtypeField", defaultSubtypeCode: "0", - subtypes: [{a: "A"}] + subtypes: [{ a: "A" }], }, }; @@ -1976,7 +1976,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack url: adminUrl + "0/updateDefinition", params: { updateDefinition: { - subtypeField: "SubtypeField" + subtypeField: "SubtypeField", }, }, args, @@ -1985,7 +1985,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack url: adminUrl + "0/updateDefinition", params: { updateDefinition: { - defaultSubtypeCode: "0" + defaultSubtypeCode: "0", }, }, args, @@ -1994,7 +1994,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack url: adminUrl + "0/addToDefinition", params: { addToDefinition: { - subtypes: [{a: "A"}] + subtypes: [{ a: "A" }], }, }, args,