From c427315b0ff42b582c8401311351a8f95ae9cef7 Mon Sep 17 00:00:00 2001 From: Caleb Pomar Date: Mon, 6 May 2024 13:30:03 -0600 Subject: [PATCH 1/2] fix(hub-common): allow unified downloads feature flag to be used on prod, fix format display order affects: @esri/hub-common --- .../content/_internal/ContentBusinessRules.ts | 1 - .../common/src/downloads/_internal/_types.ts | 14 +++++----- .../getCreateReplicaFormats.ts | 21 +++++++++++---- .../getCreateReplicaFormats.test.ts | 26 +++++++++++++++---- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/common/src/content/_internal/ContentBusinessRules.ts b/packages/common/src/content/_internal/ContentBusinessRules.ts index a30a4619e6a..ad38de07c2e 100644 --- a/packages/common/src/content/_internal/ContentBusinessRules.ts +++ b/packages/common/src/content/_internal/ContentBusinessRules.ts @@ -138,6 +138,5 @@ export const ContentPermissionPolicies: IPermissionPolicy[] = [ { permission: "temp:hub:content:downloads:unifiedList", availability: ["flag"], - environments: ["qaext", "devext"], }, ]; diff --git a/packages/common/src/downloads/_internal/_types.ts b/packages/common/src/downloads/_internal/_types.ts index 83d8acb04eb..69d5dc93153 100644 --- a/packages/common/src/downloads/_internal/_types.ts +++ b/packages/common/src/downloads/_internal/_types.ts @@ -36,28 +36,30 @@ export type ExportImageFormat = (typeof EXPORT_IMAGE_FORMATS)[number]; /** * Formats supported by the paging operation endpoint of the Hub Download API. + * Listed in the default order of appearance in the UI. */ export const HUB_PAGING_JOB_FORMATS = [ ServiceDownloadFormat.CSV, + ServiceDownloadFormat.SHAPEFILE, ServiceDownloadFormat.GEOJSON, ServiceDownloadFormat.KML, - ServiceDownloadFormat.SHAPEFILE, ] as const; export type HubPagingJobFormat = (typeof HUB_PAGING_JOB_FORMATS)[number]; /** * Known formats supported by the /createReplica endpoint of the Hub Download API. + * Listed in the default order of appearance in the UI. * NOTE: this is may be incomplete and should be updated as needed. */ export const CREATE_REPLICA_FORMATS = [ ServiceDownloadFormat.CSV, - ServiceDownloadFormat.EXCEL, - ServiceDownloadFormat.FEATURE_COLLECTION, - ServiceDownloadFormat.FILE_GDB, + ServiceDownloadFormat.SHAPEFILE, ServiceDownloadFormat.GEOJSON, + ServiceDownloadFormat.FILE_GDB, + ServiceDownloadFormat.FEATURE_COLLECTION, + ServiceDownloadFormat.EXCEL, ServiceDownloadFormat.GEO_PACKAGE, - ServiceDownloadFormat.JSON, - ServiceDownloadFormat.SHAPEFILE, ServiceDownloadFormat.SQLITE, + ServiceDownloadFormat.JSON, ] as const; export type CreateReplicaFormat = (typeof CREATE_REPLICA_FORMATS)[number]; diff --git a/packages/common/src/downloads/_internal/format-fetchers/getCreateReplicaFormats.ts b/packages/common/src/downloads/_internal/format-fetchers/getCreateReplicaFormats.ts index 61ffa5b214b..c3c255a964d 100644 --- a/packages/common/src/downloads/_internal/format-fetchers/getCreateReplicaFormats.ts +++ b/packages/common/src/downloads/_internal/format-fetchers/getCreateReplicaFormats.ts @@ -1,6 +1,6 @@ import { IHubEditableContent } from "../../../core/types/IHubEditableContent"; import { IDynamicDownloadFormat } from "../../types"; -import { CreateReplicaFormat } from "../_types"; +import { CreateReplicaFormat, CREATE_REPLICA_FORMATS } from "../_types"; /** * @private @@ -12,8 +12,19 @@ import { CreateReplicaFormat } from "../_types"; export function getCreateReplicaFormats( entity: IHubEditableContent ): IDynamicDownloadFormat[] { - return (entity.serverExtractFormats || []).map((format: string) => ({ - type: "dynamic", - format: format as CreateReplicaFormat, - })); + const allFormats = entity.serverExtractFormats || []; + // List recognized formats in the order they are defined in CREATE_REPLICA_FORMATS + const recognizedFormats: CreateReplicaFormat[] = + CREATE_REPLICA_FORMATS.filter((format) => allFormats.includes(format)); + // List any unrecognized formats (we'll append these to the end of the final array) + const unrecognizedFormats = allFormats.filter( + (format) => !CREATE_REPLICA_FORMATS.includes(format as CreateReplicaFormat) + ); + + return [...recognizedFormats, ...unrecognizedFormats].map( + (format: string) => ({ + type: "dynamic", + format: format as CreateReplicaFormat, + }) + ); } diff --git a/packages/common/test/downloads/_internal/format-fetchers/getCreateReplicaFormats.test.ts b/packages/common/test/downloads/_internal/format-fetchers/getCreateReplicaFormats.test.ts index ef6951f391c..8bb6e6ba9fa 100644 --- a/packages/common/test/downloads/_internal/format-fetchers/getCreateReplicaFormats.test.ts +++ b/packages/common/test/downloads/_internal/format-fetchers/getCreateReplicaFormats.test.ts @@ -3,22 +3,38 @@ import { IHubEditableContent } from "../../../../src/core/types/IHubEditableCont import { getCreateReplicaFormats } from "../../../../src/downloads/_internal/format-fetchers/getCreateReplicaFormats"; describe("getCreateReplicaFormats", () => { - it("should return available createReplica formats", () => { + it("should return an empty array if there are no formats", () => { + const entity = {} as unknown as IHubEditableContent; + const result = getCreateReplicaFormats(entity); + expect(result).toEqual([]); + }); + it("should return recognized createReplica formats in a predefined order", () => { const entity = { serverExtractFormats: [ + // Out of order ServiceDownloadFormat.JSON, ServiceDownloadFormat.GEOJSON, ], } as unknown as IHubEditableContent; const result = getCreateReplicaFormats(entity); expect(result.map((r) => r.format)).toEqual([ - ServiceDownloadFormat.JSON, ServiceDownloadFormat.GEOJSON, + ServiceDownloadFormat.JSON, ]); }); - it("should return an empty array if there are no formats", () => { - const entity = {} as unknown as IHubEditableContent; + it("should return unrecognized createReplica formats at the end", () => { + const entity = { + serverExtractFormats: [ + ServiceDownloadFormat.GEOJSON, + "unknown-format", + ServiceDownloadFormat.JSON, + ], + } as unknown as IHubEditableContent; const result = getCreateReplicaFormats(entity); - expect(result).toEqual([]); + expect(result.map((r) => r.format)).toEqual([ + ServiceDownloadFormat.GEOJSON, + ServiceDownloadFormat.JSON, + "unknown-format" as ServiceDownloadFormat, + ]); }); }); From 06c588af0338908456f922a64fdb41746ee652c0 Mon Sep 17 00:00:00 2001 From: Caleb Pomar Date: Mon, 6 May 2024 13:43:05 -0600 Subject: [PATCH 2/2] fix(hub-common): fix property path when fetching metadata for additional resources affects: @esri/hub-common --- packages/common/src/content/fetch.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/common/src/content/fetch.ts b/packages/common/src/content/fetch.ts index 38645b6e84f..617a2315b86 100644 --- a/packages/common/src/content/fetch.ts +++ b/packages/common/src/content/fetch.ts @@ -267,12 +267,14 @@ export const fetchHubContent = async ( const model = { item }; const enrichments: IHubEditableContentEnrichments = {}; - enrichments.metadata = await fetchItemEnrichments( + const { metadata } = await fetchItemEnrichments( item, ["metadata"], requestOptions as IHubRequestOptions ); + enrichments.metadata = metadata; + if (isHostedFeatureServiceItem(item)) { enrichments.server = await getService({ ...requestOptions,