Skip to content

Commit

Permalink
fix(hub-common): fix fetchHubContent does not support slugs (#1216)
Browse files Browse the repository at this point in the history
affects: @esri/hub-common
  • Loading branch information
tomwayson authored Sep 15, 2023
1 parent e126a0a commit d3a4eba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions packages/common/src/content/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,32 @@ export const fetchContent = async (
return content;
};

/**
* fetch a content entity by identifier
* @param identifier
* @param requestOptions
* @returns content entity
*/
export const fetchHubContent = async (
identifier: string,
requestOptions: IRequestOptions
): Promise<IHubEditableContent> => {
// NOTE: We can't just call `getModel` because we need to be able
// to properly handle other types like PDFs that don't have JSON data
const item = await getItem(identifier, requestOptions);
// NOTE: b/c we have to support slugs we use fetchContent() to get the item
// by telling it to not fetch any enrichments
// which we then fetch as needed after we have the item
const options = {
...requestOptions,
enrichments: [],
} as IFetchContentOptions;
const { item } = await fetchContent(identifier, options);
const model = { item };
const enrichments: IItemAndIServerEnrichments = {};
if (isHostedFeatureServiceItem(item)) {
enrichments.server = await getService({
...requestOptions,
url: parseServiceUrl(item.url),
});
}
const model: IModel = { item };
return modelToHubEditableContent(model, requestOptions, enrichments);
};

Expand Down
7 changes: 4 additions & 3 deletions packages/common/test/content/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IItem } from "@esri/arcgis-rest-portal";
import { IFeatureServiceDefinition } from "@esri/arcgis-rest-types";

export const HOSTED_FEATURE_SERVICE_GUID = "9001";
export const HOSTED_FEATURE_SERVICE_GUID = "A1295DEF67814571B99EDDEA65748143";
export const HOSTED_FEATURE_SERVICE_URL =
"https://services.arcgis.com/:orgId/arcgis/rest/services/:serviceName/FeatureServer";
export const HOSTED_FEATURE_SERVICE_ITEM: IItem = {
Expand Down Expand Up @@ -32,14 +32,15 @@ export const HOSTED_FEATURE_SERVICE_DEFINITION = {
capabilities: "Extract,Query",
} as IFeatureServiceDefinition;

export const NON_HOSTED_FEATURE_SERVICE_GUID = "9002";
export const NON_HOSTED_FEATURE_SERVICE_GUID =
"A1295DEF67814571B99EDDEA65748142";
export const NON_HOSTED_FEATURE_SERVICE_ITEM: IItem = {
...HOSTED_FEATURE_SERVICE_ITEM,
id: NON_HOSTED_FEATURE_SERVICE_GUID,
typeKeywords: [],
};

export const PDF_GUID = "9003";
export const PDF_GUID = "A1295DEF67814571B99EDDEA65748148";
export const PDF_ITEM: IItem = {
id: PDF_GUID,
access: "public",
Expand Down

0 comments on commit d3a4eba

Please sign in to comment.