@esri/hub-common 9.26.1 → 9.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/es2017/search/_internal/index.js +3 -0
  2. package/dist/es2017/search/_internal/index.js.map +1 -0
  3. package/dist/es2017/search/_internal/searchContentEntities.js +17 -5
  4. package/dist/es2017/search/_internal/searchContentEntities.js.map +1 -1
  5. package/dist/es2017/search/_internal/state.js +147 -0
  6. package/dist/es2017/search/_internal/state.js.map +1 -0
  7. package/dist/es2017/search/_searchContent.js +12 -4
  8. package/dist/es2017/search/_searchContent.js.map +1 -1
  9. package/dist/es2017/search/_searchGroups.js +1 -0
  10. package/dist/es2017/search/_searchGroups.js.map +1 -1
  11. package/dist/es2017/search/_searchUsers.js +1 -0
  12. package/dist/es2017/search/_searchUsers.js.map +1 -1
  13. package/dist/es2017/search/collectionState.js +60 -0
  14. package/dist/es2017/search/collectionState.js.map +1 -0
  15. package/dist/es2017/search/content-utils.js +14 -7
  16. package/dist/es2017/search/content-utils.js.map +1 -1
  17. package/dist/es2017/search/index.js +2 -1
  18. package/dist/es2017/search/index.js.map +1 -1
  19. package/dist/es2017/search/types/ICatalog.js +1 -0
  20. package/dist/es2017/search/types/ICatalog.js.map +1 -0
  21. package/dist/es2017/search/types/ICollection.js +1 -0
  22. package/dist/es2017/search/types/ICollection.js.map +1 -0
  23. package/dist/es2017/search/types/IFacet.js +1 -0
  24. package/dist/es2017/search/types/IFacet.js.map +1 -0
  25. package/dist/es2017/search/types/IFacetOption.js +1 -0
  26. package/dist/es2017/search/types/IFacetOption.js.map +1 -0
  27. package/dist/es2017/search/types/index.js +6 -0
  28. package/dist/es2017/search/types/index.js.map +1 -0
  29. package/dist/es2017/search/{types.js → types/types.js} +0 -0
  30. package/dist/{node/search → es2017/search/types}/types.js.map +1 -1
  31. package/dist/es2017/search/utils.js.map +1 -1
  32. package/dist/esm/search/_internal/index.js +3 -0
  33. package/dist/esm/search/_internal/index.js.map +1 -0
  34. package/dist/esm/search/_internal/searchContentEntities.js +17 -6
  35. package/dist/esm/search/_internal/searchContentEntities.js.map +1 -1
  36. package/dist/esm/search/_internal/state.js +147 -0
  37. package/dist/esm/search/_internal/state.js.map +1 -0
  38. package/dist/esm/search/_searchContent.js +13 -5
  39. package/dist/esm/search/_searchContent.js.map +1 -1
  40. package/dist/esm/search/_searchGroups.js +1 -0
  41. package/dist/esm/search/_searchGroups.js.map +1 -1
  42. package/dist/esm/search/_searchUsers.js +1 -0
  43. package/dist/esm/search/_searchUsers.js.map +1 -1
  44. package/dist/esm/search/collectionState.js +61 -0
  45. package/dist/esm/search/collectionState.js.map +1 -0
  46. package/dist/esm/search/content-utils.js +15 -7
  47. package/dist/esm/search/content-utils.js.map +1 -1
  48. package/dist/esm/search/index.js +2 -1
  49. package/dist/esm/search/index.js.map +1 -1
  50. package/dist/esm/search/types/ICatalog.js +1 -0
  51. package/dist/esm/search/types/ICatalog.js.map +1 -0
  52. package/dist/esm/search/types/ICollection.js +1 -0
  53. package/dist/esm/search/types/ICollection.js.map +1 -0
  54. package/dist/esm/search/types/IFacet.js +1 -0
  55. package/dist/esm/search/types/IFacet.js.map +1 -0
  56. package/dist/esm/search/types/IFacetOption.js +1 -0
  57. package/dist/esm/search/types/IFacetOption.js.map +1 -0
  58. package/dist/esm/search/types/index.js +6 -0
  59. package/dist/esm/search/types/index.js.map +1 -0
  60. package/dist/esm/search/{types.js → types/types.js} +0 -0
  61. package/dist/{es2017/search → esm/search/types}/types.js.map +1 -1
  62. package/dist/esm/search/utils.js.map +1 -1
  63. package/dist/node/search/_internal/index.js +6 -0
  64. package/dist/node/search/_internal/index.js.map +1 -0
  65. package/dist/node/search/_internal/searchContentEntities.js +16 -4
  66. package/dist/node/search/_internal/searchContentEntities.js.map +1 -1
  67. package/dist/node/search/_internal/state.js +158 -0
  68. package/dist/node/search/_internal/state.js.map +1 -0
  69. package/dist/node/search/_searchContent.js +14 -6
  70. package/dist/node/search/_searchContent.js.map +1 -1
  71. package/dist/node/search/_searchGroups.js +1 -0
  72. package/dist/node/search/_searchGroups.js.map +1 -1
  73. package/dist/node/search/_searchUsers.js +1 -0
  74. package/dist/node/search/_searchUsers.js.map +1 -1
  75. package/dist/node/search/collectionState.js +65 -0
  76. package/dist/node/search/collectionState.js.map +1 -0
  77. package/dist/node/search/content-utils.js +14 -7
  78. package/dist/node/search/content-utils.js.map +1 -1
  79. package/dist/node/search/index.js +2 -1
  80. package/dist/node/search/index.js.map +1 -1
  81. package/dist/node/search/types/ICatalog.js +3 -0
  82. package/dist/node/search/types/ICatalog.js.map +1 -0
  83. package/dist/node/search/types/ICollection.js +3 -0
  84. package/dist/node/search/types/ICollection.js.map +1 -0
  85. package/dist/node/search/types/IFacet.js +3 -0
  86. package/dist/node/search/types/IFacet.js.map +1 -0
  87. package/dist/node/search/types/IFacetOption.js +3 -0
  88. package/dist/node/search/types/IFacetOption.js.map +1 -0
  89. package/dist/node/search/types/index.js +9 -0
  90. package/dist/node/search/types/index.js.map +1 -0
  91. package/dist/node/search/{types.js → types/types.js} +0 -0
  92. package/dist/{esm/search → node/search/types}/types.js.map +1 -1
  93. package/dist/node/search/utils.js.map +1 -1
  94. package/dist/types/core/types/IHubEntityManager.d.ts +1 -1
  95. package/dist/types/search/_internal/index.d.ts +2 -0
  96. package/dist/types/search/_internal/searchContentEntities.d.ts +1 -1
  97. package/dist/types/search/_internal/state.d.ts +62 -0
  98. package/dist/types/search/_searchGroups.d.ts +1 -1
  99. package/dist/types/search/collectionState.d.ts +19 -0
  100. package/dist/types/search/content-utils.d.ts +6 -4
  101. package/dist/types/search/index.d.ts +2 -1
  102. package/dist/types/search/types/ICatalog.d.ts +76 -0
  103. package/dist/types/search/types/ICollection.d.ts +14 -0
  104. package/dist/types/search/types/IFacet.d.ts +15 -0
  105. package/dist/types/search/types/IFacetOption.d.ts +8 -0
  106. package/dist/types/search/types/index.d.ts +5 -0
  107. package/dist/types/search/{types.d.ts → types/types.d.ts} +24 -86
  108. package/dist/types/search/utils.d.ts +1 -1
  109. package/dist/umd/common.umd.js +238 -17
  110. package/dist/umd/common.umd.js.map +1 -1
  111. package/dist/umd/common.umd.min.js +1 -1
  112. package/dist/umd/common.umd.min.js.map +1 -1
  113. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * @esri/hub-common - v9.26.0 - Wed Apr 06 2022 16:02:42 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/hub-common - v9.27.0 - Tue Apr 12 2022 05:32:00 GMT+0000 (Coordinated Universal Time)
3
3
  * Copyright (c) 2022 Environmental Systems Research Institute, Inc.
4
4
  * Apache-2.0
5
5
  */
@@ -12110,29 +12110,37 @@
12110
12110
  };
12111
12111
  /**
12112
12112
  * @private
12113
- * Convert portal search response to items
12113
+ * Convert portal search response to facets
12114
+ * Note: Only applicable to a "content" search
12114
12115
  * @param response
12115
12116
  * @returns
12116
12117
  */
12117
- function convertPortalResponseToFacets(response) {
12118
+ function convertPortalResponseToFacets(response, operation) {
12118
12119
  var _a;
12120
+ if (operation === void 0) { operation = "OR"; }
12119
12121
  var result = [];
12120
12122
  if ((_a = response.aggregations) === null || _a === void 0 ? void 0 : _a.counts) {
12121
12123
  response.aggregations.counts.forEach(function (entry) {
12122
12124
  var facet = {
12123
12125
  label: entry.fieldName,
12124
- attribute: entry.fieldName,
12125
- type: "multi-select",
12126
+ key: entry.fieldName,
12127
+ aggField: entry.fieldName,
12128
+ display: "multi-select",
12126
12129
  };
12127
12130
  var options = [];
12128
12131
  entry.fieldValues.forEach(function (fv) {
12129
12132
  var filter = {
12130
12133
  filterType: "content",
12131
12134
  };
12132
- filter[entry.fieldName] = fv.value;
12135
+ // construct the filter based on the operation
12136
+ var matchKey = operation === "OR" ? "any" : "all";
12137
+ var filterMatchOption = {};
12138
+ filterMatchOption[matchKey] = [fv.value];
12139
+ filter[entry.fieldName] = filterMatchOption;
12140
+ // construct the FacetOption
12133
12141
  var fo = {
12134
- label: fv.value,
12135
- value: fv.value,
12142
+ label: fv.value + " (" + fv.count + ")",
12143
+ key: fv.value,
12136
12144
  count: fv.count,
12137
12145
  selected: false,
12138
12146
  filter: filter,
@@ -12406,14 +12414,22 @@
12406
12414
  * @returns
12407
12415
  */
12408
12416
  function searchContentEntities(filter, convertFn, options) {
12409
- var _a;
12417
+ var _a, _b;
12410
12418
  // expand filter so we can serialize to either api
12411
12419
  var expanded = expandContentFilter(filter);
12412
12420
  var searchOptions = serializeContentFilterForPortal(expanded);
12413
- // Aggregations
12421
+ // DEPRECATION
12422
+ /* istanbul ignore next */
12414
12423
  if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
12424
+ // tslint:disable-next-line:no-console
12425
+ console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
12415
12426
  searchOptions.countFields = options.aggregations.join(",");
12416
- searchOptions.countSize = 200;
12427
+ searchOptions.countSize = options.aggLimit || 10;
12428
+ }
12429
+ // Aggregations
12430
+ if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
12431
+ searchOptions.countFields = options.aggFields.join(",");
12432
+ searchOptions.countSize = options.aggLimit || 10;
12417
12433
  }
12418
12434
  // properties to copy from IHubSearchOptions to the ISearchOptions
12419
12435
  var props = [
@@ -12422,7 +12438,9 @@
12422
12438
  "sortField",
12423
12439
  "sortOrder",
12424
12440
  "site",
12441
+ "start",
12425
12442
  ];
12443
+ // Include "start" here
12426
12444
  // copy the props over
12427
12445
  props.forEach(function (prop) {
12428
12446
  if (options.hasOwnProperty(prop)) {
@@ -12453,7 +12471,7 @@
12453
12471
  // referenced in the `next` section below
12454
12472
  return function searchEntities(searchOptions) {
12455
12473
  return __awaiter(this, void 0, void 0, function () {
12456
- var response, entities;
12474
+ var response, entities, facets;
12457
12475
  return __generator(this, function (_a) {
12458
12476
  switch (_a.label) {
12459
12477
  case 0: return [4 /*yield*/, searchItems(searchOptions)];
@@ -12464,10 +12482,11 @@
12464
12482
  }))];
12465
12483
  case 2:
12466
12484
  entities = _a.sent();
12485
+ facets = convertPortalResponseToFacets(response);
12467
12486
  return [2 /*return*/, {
12468
12487
  total: response.total,
12469
12488
  results: entities,
12470
- facets: [],
12489
+ facets: facets,
12471
12490
  hasNext: response.nextStart > -1,
12472
12491
  next: getNextFunction(searchOptions, response.nextStart, response.total, searchEntities),
12473
12492
  }];
@@ -14779,10 +14798,10 @@
14779
14798
  * @param options
14780
14799
  */
14781
14800
  function _searchContent(filter, options) {
14782
- var _a;
14801
+ var _a, _b;
14783
14802
  return __awaiter(this, void 0, void 0, function () {
14784
14803
  var expanded, api, searchPromise, so_1, props;
14785
- return __generator(this, function (_b) {
14804
+ return __generator(this, function (_c) {
14786
14805
  expanded = expandContentFilter(filter);
14787
14806
  api = expandApi(options.api || "arcgis");
14788
14807
  // Portal Search
@@ -14794,6 +14813,7 @@
14794
14813
  "sortField",
14795
14814
  "sortOrder",
14796
14815
  "site",
14816
+ "start",
14797
14817
  ];
14798
14818
  // copy the props over
14799
14819
  props.forEach(function (prop) {
@@ -14805,10 +14825,17 @@
14805
14825
  if (!so_1.authentication) {
14806
14826
  so_1.portal = api.url + "/sharing/rest";
14807
14827
  }
14808
- // Aggregations
14828
+ // DEPRECATION
14809
14829
  if ((_a = options.aggregations) === null || _a === void 0 ? void 0 : _a.length) {
14830
+ // tslint:disable-next-line:no-console
14831
+ console.warn("IHubSearchOptions.aggregations is deprecated. Please use .aggFields instead.");
14810
14832
  so_1.countFields = options.aggregations.join(",");
14811
- so_1.countSize = 200;
14833
+ so_1.countSize = options.aggLimit || 10;
14834
+ }
14835
+ // Aggregations
14836
+ if ((_b = options.aggFields) === null || _b === void 0 ? void 0 : _b.length) {
14837
+ so_1.countFields = options.aggFields.join(",");
14838
+ so_1.countSize = options.aggLimit || 10;
14812
14839
  }
14813
14840
  searchPromise = searchPortal(so_1);
14814
14841
  }
@@ -14896,6 +14923,7 @@
14896
14923
  "sortField",
14897
14924
  "sortOrder",
14898
14925
  "site",
14926
+ "start",
14899
14927
  ];
14900
14928
  // copy the props over
14901
14929
  props.forEach(function (prop) {
@@ -14984,6 +15012,7 @@
14984
15012
  "sortField",
14985
15013
  "sortOrder",
14986
15014
  "site",
15015
+ "start",
14987
15016
  ];
14988
15017
  // copy the props over
14989
15018
  props.forEach(function (prop) {
@@ -15037,6 +15066,196 @@
15037
15066
  });
15038
15067
  }
15039
15068
 
15069
+ /**
15070
+ * Apply the sortState to SortOptions
15071
+ *
15072
+ * @param sortOptions
15073
+ * @param sortState
15074
+ * @returns
15075
+ */
15076
+ function applySortState(sortOptions, sortState) {
15077
+ var updated = cloneObject$1(sortOptions);
15078
+ if (sortState) {
15079
+ var _a = sortState.split("|"), label = _a[0], attribute = _a[1], order = _a[2];
15080
+ updated.label = label;
15081
+ updated.attribute = attribute;
15082
+ updated.order = order;
15083
+ }
15084
+ return updated;
15085
+ }
15086
+ /**
15087
+ * Apply FacetState to a Facet
15088
+ * @param facet
15089
+ * @param state
15090
+ * @returns
15091
+ */
15092
+ function applyFacetState(facet, state) {
15093
+ var updated = cloneObject$1(facet);
15094
+ switch (facet.display) {
15095
+ case "single-select":
15096
+ updated = applySingleSelectFacetState(facet, state);
15097
+ break;
15098
+ case "multi-select":
15099
+ updated = applyMultiSelectFacetState(facet, state);
15100
+ break;
15101
+ }
15102
+ return updated;
15103
+ }
15104
+ /**
15105
+ * Apply the Facet State onto a single-select facet
15106
+ *
15107
+ * Intentionally mutates the facet.
15108
+ * @param facet
15109
+ * @param state
15110
+ * @returns
15111
+ */
15112
+ function applySingleSelectFacetState(facet, state) {
15113
+ var updated = cloneObject$1(facet);
15114
+ updated.options = updated.options.map(function (o) {
15115
+ o.selected = o.key === state[facet.key];
15116
+ return o;
15117
+ });
15118
+ return updated;
15119
+ }
15120
+ /**
15121
+ * Serialize single-select facet into IFacetState
15122
+ * @param facet
15123
+ * @returns
15124
+ */
15125
+ function serializeSingleSelectFacetState(facet) {
15126
+ var state = {};
15127
+ var selected = facet.options.find(function (o) { return o.selected; });
15128
+ if (selected) {
15129
+ state[facet.key] = selected.key;
15130
+ }
15131
+ else {
15132
+ state[facet.key] = null;
15133
+ }
15134
+ return state;
15135
+ }
15136
+ /**
15137
+ * Apply the Facet State onto a multi-select Facet
15138
+ *
15139
+ * Intentionally mutates the facet.
15140
+ * @param facet
15141
+ * @param state
15142
+ * @returns
15143
+ */
15144
+ function applyMultiSelectFacetState(facet, state) {
15145
+ var _a;
15146
+ var updated = cloneObject$1(facet);
15147
+ var selectedKeys = ((_a = state[facet.key]) === null || _a === void 0 ? void 0 : _a.split(",")) || [];
15148
+ updated.options = updated.options.map(function (o) {
15149
+ o.selected = selectedKeys.includes(o.key);
15150
+ return o;
15151
+ });
15152
+ return updated;
15153
+ }
15154
+ /**
15155
+ * Serialize multi-select facet into IFacetState
15156
+ * @param facet
15157
+ * @returns
15158
+ */
15159
+ function serializeMultiSelectFacetState(facet) {
15160
+ var state = {};
15161
+ var selected = facet.options.filter(function (o) { return o.selected; });
15162
+ var value = selected.map(function (o) { return o.key; }).join(",");
15163
+ if (value.length) {
15164
+ state[facet.key] = value;
15165
+ }
15166
+ else {
15167
+ state[facet.key] = null;
15168
+ }
15169
+ return state;
15170
+ }
15171
+ /**
15172
+ * Serialize the state of the SortOption into a key/value pair
15173
+ *
15174
+ * Called from the Sort component
15175
+ * @param sort
15176
+ * @returns
15177
+ */
15178
+ function serializeSortState(sort) {
15179
+ return sort.label + "|" + sort.attribute + "|" + sort.order;
15180
+ }
15181
+ /**
15182
+ * Serialize the state of a facet into a key/value pair
15183
+ *
15184
+ * Called from the various facet components
15185
+ * @param facet
15186
+ * @returns
15187
+ */
15188
+ function serializeFacetState(facet) {
15189
+ var state = {};
15190
+ switch (facet.display) {
15191
+ case "single-select":
15192
+ state = serializeSingleSelectFacetState(facet);
15193
+ break;
15194
+ case "multi-select":
15195
+ state = serializeMultiSelectFacetState(facet);
15196
+ break;
15197
+ }
15198
+ return state;
15199
+ }
15200
+
15201
+ /**
15202
+ * Apply ICollectionState to an ICollection
15203
+ *
15204
+ * Typically used in a Gallery or Catalog component to
15205
+ * set the inital state, based on values deserialized
15206
+ * from a query string
15207
+ * @param collection
15208
+ * @param state
15209
+ * @returns
15210
+ */
15211
+ function applyCollectionState(collection, state) {
15212
+ var updated = cloneObject$1(collection);
15213
+ // Apply default query
15214
+ if (state.query) {
15215
+ updated.defaultQuery = state.query;
15216
+ }
15217
+ // Apply Sort State
15218
+ updated.sortOption = applySortState(updated.sortOption, state.sort);
15219
+ // Look for state props for the facets and apply them
15220
+ updated.facets = updated.facets.map(function (facet) {
15221
+ // see if there is a key for this facet on the state
15222
+ if (Object.keys(state).includes(facet.key)) {
15223
+ var facetState = {};
15224
+ facetState[facet.key] = state[facet.key];
15225
+ return applyFacetState(facet, facetState);
15226
+ }
15227
+ else {
15228
+ // Ensure all options are not selected
15229
+ // because they were not included in the state
15230
+ facet.options.forEach(function (opt) {
15231
+ opt.selected = false;
15232
+ });
15233
+ return facet;
15234
+ }
15235
+ });
15236
+ //
15237
+ return updated;
15238
+ }
15239
+ /**
15240
+ * Serialize the current state of a collection into a hash that
15241
+ * can be converted into a query string
15242
+ * @param collection
15243
+ * @returns
15244
+ */
15245
+ function serializeCollectionState(collection) {
15246
+ var state = {};
15247
+ if (collection.defaultQuery) {
15248
+ state.query = collection.defaultQuery;
15249
+ }
15250
+ if (collection.sortOption) {
15251
+ state.sort = serializeSortState(collection.sortOption);
15252
+ }
15253
+ var facetState = collection.facets.reduce(function (s, facet) {
15254
+ return __assign(__assign({}, s), serializeFacetState(facet));
15255
+ }, {});
15256
+ return __assign(__assign({}, state), facetState);
15257
+ }
15258
+
15040
15259
  /**
15041
15260
  * Add telemetry config object
15042
15261
  * @private
@@ -16857,6 +17076,7 @@
16857
17076
  exports.addSiteDomains = addSiteDomains;
16858
17077
  exports.addSolutionResourceUrlToAssets = addSolutionResourceUrlToAssets;
16859
17078
  exports.addUsersToGroup = addUsersToGroup;
17079
+ exports.applyCollectionState = applyCollectionState;
16860
17080
  exports.applyPropertiesToItems = applyPropertiesToItems;
16861
17081
  exports.arrayToObject = arrayToObject;
16862
17082
  exports.atob = abab.atob;
@@ -17055,6 +17275,7 @@
17055
17275
  exports.saveSession = saveSession;
17056
17276
  exports.searchProjects = searchProjects;
17057
17277
  exports.searchSites = searchSites;
17278
+ exports.serializeCollectionState = serializeCollectionState;
17058
17279
  exports.serializeContentFilterForPortal = serializeContentFilterForPortal;
17059
17280
  exports.serializeDateRange = serializeDateRange;
17060
17281
  exports.serializeGroupFilterForPortal = serializeGroupFilterForPortal;