Skip to content

Commit

Permalink
fix(hub-common): fix unified list feature flag, format order, and add…
Browse files Browse the repository at this point in the history
…itional resource calculation (#1501)
  • Loading branch information
sonofflynn89 authored May 6, 2024
1 parent dcc59e5 commit 46d4715
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,5 @@ export const ContentPermissionPolicies: IPermissionPolicy[] = [
{
permission: "temp:hub:content:downloads:unifiedList",
availability: ["flag"],
environments: ["qaext", "devext"],
},
];
4 changes: 3 additions & 1 deletion packages/common/src/content/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions packages/common/src/downloads/_internal/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
});
});

0 comments on commit 46d4715

Please sign in to comment.