-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(hub-common): computeLinks calls computeItemLinks (#1758)
- Loading branch information
Showing
11 changed files
with
74 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
packages/common/test/initiative-templates/_internal/computeLinks.test.ts
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
packages/common/test/initiatives/_internal/computeLinks.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.