Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deployed solution redirects #1268

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/common/src/templates/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ export function computeLinks(
token = session.token;
}

// If a solution template is deployed, we don't support
// managing it in the workspace, so we kick users to AGO
const isDeployed = item.typeKeywords?.includes("Deployed");
const itemHomeUrl = getItemHomeUrl(item.id, requestOptions);
return {
self: getItemHomeUrl(item.id, requestOptions),
self: itemHomeUrl,
siteRelative: getHubRelativeUrl(
item.type,
getItemIdentifier(item),
item.typeKeywords
),
workspaceRelative: getRelativeWorkspaceUrl(
item.type,
getItemIdentifier(item)
),
workspaceRelative: isDeployed
? itemHomeUrl
: getRelativeWorkspaceUrl(item.type, getItemIdentifier(item)),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
}
36 changes: 30 additions & 6 deletions packages/common/test/templates/_internal/computeLinks.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { IItem } from "@esri/arcgis-rest-types";
import { computeLinks } from "../../../src/templates/_internal/computeLinks";
import { ArcGISContextManager, setProp } from "../../../src";
import { ArcGISContextManager } from "../../../src/ArcGISContextManager";
import { IHubEntityLinks } from "../../../src/core/types";
import { setProp } from "../../../src/objects";
import { initContextManager } from "../fixtures";
import * as getItemThumbnailUrlModule from "../../../src/resources/get-item-thumbnail-url";
import * as urlsModule from "../../../src/urls";

describe("templates: computeLinks", () => {
let authdCtxMgr: ArcGISContextManager;
let unauthdCtxMgr: ArcGISContextManager;
let item: IItem;
let getItemHomeUrlSpy: jasmine.Spy;
let getItemThumbnailUrlSpy: jasmine.Spy;

beforeEach(async () => {
item = {
Expand All @@ -16,25 +21,44 @@ describe("templates: computeLinks", () => {
} as IItem;
authdCtxMgr = await initContextManager();
unauthdCtxMgr = await ArcGISContextManager.create();

getItemHomeUrlSpy = spyOn(urlsModule, "getItemHomeUrl").and.returnValue(
"/some-item-home-url"
);
getItemThumbnailUrlSpy = spyOn(
getItemThumbnailUrlModule,
"getItemThumbnailUrl"
).and.returnValue("/some-thumbnail-url");
});

it("generates a links hash using the template's slug", () => {
setProp("properties.slug", "mock-slug", item);
const chk = computeLinks(item, authdCtxMgr.context.requestOptions);

expect(chk.self).toBe("/some-item-home-url");
expect(chk.siteRelative).toBe("/templates/mock-slug/about");
expect(chk.workspaceRelative).toBe("/workspace/templates/mock-slug");
expect(chk.thumbnail).toBe("/some-thumbnail-url");
});
it("generates a links hash using the templates's id when no slug is available", () => {
const chk = computeLinks(item, authdCtxMgr.context.requestOptions);

expect(chk.self).toBe("/some-item-home-url");
expect(chk.siteRelative).toBe("/templates/00c/about");
expect(chk.workspaceRelative).toBe("/workspace/templates/00c");
expect(chk.thumbnail).toBe("/some-thumbnail-url");
});
it("Deployed templates are redirected to the generic content route", () => {
setProp("typeKeywords", ["Deployed"], item);
const chk = computeLinks(item, unauthdCtxMgr.context.requestOptions);

expect(chk.siteRelative).toBe("/content/00c/about");
describe("Deployed templates", () => {
let chk: IHubEntityLinks;
beforeEach(() => {
setProp("typeKeywords", ["Deployed"], item);
chk = computeLinks(item, unauthdCtxMgr.context.requestOptions);
});
it("the siteRelative url redirects users to the generic content route", () => {
expect(chk.siteRelative).toBe("/content/00c/about");
});
it("the workspace relative url redirects users to the item home in AGO", () => {
expect(chk.workspaceRelative).toBe("/some-item-home-url");
});
});
});