Skip to content

Commit

Permalink
fix(hub-content): getLayerContent should update hubId
Browse files Browse the repository at this point in the history
affects: @esri/hub-content
  • Loading branch information
tomwayson committed Sep 20, 2021
1 parent 007341f commit 6222c27
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
14 changes: 10 additions & 4 deletions packages/content/src/enrichments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const getLayer = (content: IHubContent, layerId?: number) => {
isFeatureService(content.type) && getOnlyQueryLayer(layers);
};

const getOnlyQueryLayer = (layers: ILayerDefinition[] = []) => {
const layer = Array.isArray(layers) && layers.length === 1 && layers[0];
const getOnlyQueryLayer = (layers: ILayerDefinition[]) => {
const layer = layers && layers.length === 1 && layers[0];
return layer && layer.capabilities.includes("Query") && layer;
};

Expand Down Expand Up @@ -597,11 +597,17 @@ export const getLayerContent = (
if (!layer) {
return;
}
const { type, name, description } = layer;
const { item } = content;
// get type name and description from layer
const { id, type, name, description } = layer;
// get family and normalized type based on layer type
const family = getFamily(type);
const normalizedType = normalizeItemType({ ...content.item, type });
const normalizedType = normalizeItemType({ ...item, type });
const layerContent = { ...content, layer, type, family, normalizedType };
if (item.access === "public") {
// we assume this is in the index,
layerContent.hubId = `${item.id}_${id}`;
}
if (shouldUseLayerInfo(layerContent)) {
// NOTE: composer updated dataset name and description
// but b/c the layer enrichments now happen _after_ datasetToContent()
Expand Down
36 changes: 26 additions & 10 deletions packages/content/test/enrichments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,36 @@ describe("getLayerContent", () => {
capabilities: "Query",
},
] as Array<Partial<arcgisRestFeatureLayer.ILayerDefinition>>;
it("multi-layer feature service w/ layerId", () => {
const content = {
let item: arcgisRestPortal.IItem;
beforeEach(() => {
item = {
id: "3ae",
type: "Feature Service",
title: "Item Title",
description: "Item description",
summary: "Item snippet",
layers,
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/LocalGovernment/Recreation/FeatureServer",
access: "public",
owner: "me",
tags: ["test"],
created: 1526675011000,
modified: 1526675614000,
numViews: 1,
size: null,
};
});
it("non-public, multi-layer feature service w/ layerId", () => {
item.access = "private";
const content = {
...item,
layers,
} as IHubContent;
content.item = item;
let layerId = 0;
let layerContent = getLayerContent(content, layerId);
let layer = layers[0];
expect(layerContent.layer).toEqual(layer, "should set layer");
expect(layerContent.hubId).toBeUndefined("should not set hubId");
expect(layerContent.type).toBe(layer.type, "should set type");
expect(layerContent.family).toBe("dataset", "should set family");
expect(layerContent.title).toEqual(layer.name, "should set title");
Expand Down Expand Up @@ -224,19 +240,19 @@ describe("getLayerContent", () => {
"should set url"
);
});
it("single-layer feature service w/o layerId", () => {
it("public, single-layer feature service w/o layerId", () => {
const layer = layers[0];
const content = {
id: "3ae",
type: "Feature Service",
title: "Item Title",
description: "Item description",
summary: "Item snippet",
...item,
layers: [layer],
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/LocalGovernment/Recreation/FeatureServer",
} as IHubContent;
content.item = item;
const layerContent = getLayerContent(content);
expect(layerContent.layer).toEqual(layer, "should set layer");
expect(layerContent.hubId).toBe(
`${item.id}_${layer.id}`,
"should set hubId"
);
expect(layerContent.type).toBe(layer.type, "should set type");
expect(layerContent.family).toBe("dataset", "should set family");
expect(layerContent.title).toEqual(content.title, "should not set title");
Expand Down

0 comments on commit 6222c27

Please sign in to comment.