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

refactor(hub-common): computeLinks calls computeItemLinks #1758

Merged
merged 1 commit into from
Dec 4, 2024
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
39 changes: 39 additions & 0 deletions packages/common/src/core/_internal/computeItemLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { IItem } from "@esri/arcgis-rest-types";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { getItemHomeUrl } from "../../urls";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";

/**
* Compute the links that get appended to a Hub Initiative
* search result and entity
*
* @param item
* @param requestOptions
*/
export function computeItemLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

return {
self: getItemHomeUrl(item.id, requestOptions),
siteRelative: getHubRelativeUrl(
item.type,
getItemIdentifier(item),
item.typeKeywords
),
siteRelativeEntityType: getHubRelativeUrl(item.type),
workspaceRelative: getRelativeWorkspaceUrl(item.type, item.id),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
}
25 changes: 3 additions & 22 deletions packages/common/src/initiative-templates/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { UserSession } from "@esri/arcgis-rest-auth";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { IItem } from "@esri/arcgis-rest-types";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { getRelativeWorkspaceUrl, IHubEntityLinks } from "../../core";
import { getItemIdentifier } from "../../items";
import { getItemThumbnailUrl } from "../../resources";
import { getItemHomeUrl } from "../../urls";
import { IHubEntityLinks } from "../../core";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";

/**
* Compute the links that get appended to a Hub Initiative Template
Expand All @@ -19,20 +15,5 @@ export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

return {
self: getItemHomeUrl(item.id, requestOptions),
siteRelative: getHubRelativeUrl(item.type, getItemIdentifier(item)),
siteRelativeEntityType: getHubRelativeUrl(item.type),
workspaceRelative: getRelativeWorkspaceUrl(
item.type,
getItemIdentifier(item)
),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
return computeItemLinks(item, requestOptions);
}
28 changes: 4 additions & 24 deletions packages/common/src/initiatives/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { IItem } from "@esri/arcgis-rest-types";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { getItemHomeUrl } from "../../urls";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { IItem } from "@esri/arcgis-rest-types";
import { IHubEntityLinks } from "../../core";

/**
* Compute the links that get appended to a Hub Initiative
Expand All @@ -19,20 +14,5 @@ export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

return {
self: getItemHomeUrl(item.id, requestOptions),
siteRelative: getHubRelativeUrl(item.type, getItemIdentifier(item)),
siteRelativeEntityType: getHubRelativeUrl(item.type),
workspaceRelative: getRelativeWorkspaceUrl(
item.type,
getItemIdentifier(item)
),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
return computeItemLinks(item, requestOptions);
}
21 changes: 4 additions & 17 deletions packages/common/src/pages/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { IItem } from "@esri/arcgis-rest-types";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { getItemHomeUrl } from "../../urls";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";

/**
* Compute the links that get appended to a Hub Site
Expand All @@ -19,18 +14,10 @@ export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

const links = computeItemLinks(item, requestOptions);
return {
self: getItemHomeUrl(item.id, requestOptions),
siteRelative: getHubRelativeUrl(item.type, item.id, item.typeKeywords),
siteRelativeEntityType: getHubRelativeUrl("page"),
...links,
// add the layout relative link
layoutRelative: `/pages/${item.id}/edit`,
workspaceRelative: getRelativeWorkspaceUrl(item.type, item.id),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
}
29 changes: 5 additions & 24 deletions packages/common/src/projects/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import { IItem } from "@esri/arcgis-rest-types";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { getItemHomeUrl } from "../../urls";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { IItem } from "@esri/arcgis-rest-types";
import { IHubEntityLinks } from "../../core";

/**
* Compute the links that get appended to a Hub Project
* search result and entity
*
* @param item
* @param requestOptions
* @returns
*/
export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

return {
self: getItemHomeUrl(item.id, requestOptions),
siteRelative: getHubRelativeUrl(item.type, getItemIdentifier(item)),
siteRelativeEntityType: getHubRelativeUrl(item.type),
workspaceRelative: getRelativeWorkspaceUrl(
item.type,
getItemIdentifier(item)
),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
return computeItemLinks(item, requestOptions);
}
19 changes: 5 additions & 14 deletions packages/common/src/sites/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { IItem } from "@esri/arcgis-rest-types";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";

/**
* Compute the links that get appended to a Hub Site
Expand All @@ -18,18 +15,12 @@ export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}

const links = computeItemLinks(item, requestOptions);
return {
...links,
// for sites we use the site's url as the self link
self: item.url,
siteRelative: getHubRelativeUrl(item.type, item.id, item.typeKeywords),
siteRelativeEntityType: getHubRelativeUrl(item.type),
// add the layout relative link
layoutRelative: "/edit",
workspaceRelative: getRelativeWorkspaceUrl(item.type, item.id),
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
};
}
41 changes: 13 additions & 28 deletions packages/common/src/templates/_internal/computeLinks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { IItem } from "@esri/arcgis-rest-types";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { getItemHomeUrl } from "../../urls";
import { IHubEntityLinks } from "../../core/types";
import { getItemIdentifier } from "../../items";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { computeItemLinks } from "../../core/_internal/computeItemLinks";

/**
* Compute the links that get appended to a Hub Template
Expand All @@ -19,32 +14,22 @@ export function computeLinks(
item: IItem,
requestOptions: IRequestOptions
): IHubEntityLinks {
let token: string;
if (requestOptions.authentication) {
const session: UserSession = requestOptions.authentication as UserSession;
token = session.token;
}
const links = computeItemLinks(item, requestOptions);

// 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);
const siteRelativeUrl = getHubRelativeUrl(
item.type,
getItemIdentifier(item),
item.typeKeywords
);
const { self, siteRelative, workspaceRelative } = links;
// templates have an advanced edit link
const advancedEditRelative = `${(siteRelative as string)
.split("/")
.slice(0, -1)
.join("/")}/edit/advanced`;
return {
self: itemHomeUrl,
siteRelative: siteRelativeUrl,
siteRelativeEntityType: getHubRelativeUrl(item.type),
workspaceRelative: isDeployed
? itemHomeUrl
: getRelativeWorkspaceUrl(item.type, getItemIdentifier(item)),
advancedEditRelative: `${siteRelativeUrl
.split("/")
.slice(0, -1)
.join("/")}/edit/advanced`,
thumbnail: getItemThumbnailUrl(item, requestOptions, token),
...links,
// handle deployed templates
workspaceRelative: isDeployed ? self : workspaceRelative,
// add advanced edit relative link
advancedEditRelative,
};
}

This file was deleted.

46 changes: 0 additions & 46 deletions packages/common/test/initiatives/_internal/computeLinks.test.ts

This file was deleted.

Loading
Loading