Skip to content

Commit

Permalink
feat: scaffold solution template entity (#1253)
Browse files Browse the repository at this point in the history
Scaffolds the Hub Solution Template entity
  • Loading branch information
juliannemarik authored Oct 5, 2023
1 parent 96ec555 commit 54d1fe6
Show file tree
Hide file tree
Showing 43 changed files with 2,469 additions and 99 deletions.
4 changes: 4 additions & 0 deletions packages/common/src/core/EntityEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HubInitiativeTemplate } from "../initiative-templates";
import { HubPage } from "../pages/HubPage";
import { HubProject } from "../projects/HubProject";
import { HubSite } from "../sites/HubSite";
import { HubTemplate } from "../templates";
import { IEditorConfig, IWithEditorBehavior } from "./behaviors";
import { getTypeFromEntity } from "./getTypeFromEntity";
import { EditorType, UiSchemaElementOptions } from "./schemas";
Expand Down Expand Up @@ -42,6 +43,9 @@ export class EntityEditor {
if (entityType === "discussion") {
editor = HubDiscussion.fromJson(entity, context) as IWithEditorBehavior;
}
if (entityType === "template") {
editor = HubTemplate.fromJson(entity, context) as IWithEditorBehavior;
}
if (entityType === "group") {
editor = HubGroup.fromJson(
entity as unknown as HubGroup,
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/core/fetchHubEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fetchInitiative } from "../initiatives/HubInitiatives";
import { fetchPage } from "../pages/HubPages";
import { fetchProject } from "../projects/fetch";
import { fetchSite } from "../sites/HubSites";
import { fetchTemplate } from "../templates/fetch";
import { HubEntity } from "./types/HubEntity";
import { HubEntityType } from "./types/HubEntityType";
import { IArcGISContext } from "../ArcGISContext";
Expand Down Expand Up @@ -42,6 +43,9 @@ export async function fetchHubEntity(
case "content":
result = await fetchHubContent(identifier, context.requestOptions);
break;
case "template":
result = await fetchTemplate(identifier, context.requestOptions);
break;
case "group":
result = await fetchHubGroup(identifier, context.userRequestOptions);
break;
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/core/getTypeFromEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function getTypeFromEntity(
case "Discussion":
type = "discussion";
break;
case "Solution":
type = "template";
break;
case "Group":
type = "group";
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InitiativeEditorType } from "../../../initiatives/_internal/InitiativeS
import { DiscussionEditorType } from "../../../discussions/_internal/DiscussionSchema";
import { PageEditorType } from "../../../pages/_internal/PageSchema";
import { ContentEditorType } from "../../../content/_internal/ContentSchema";
import { TemplateEditorType } from "../../../templates/_internal/TemplateSchema";
import { GroupEditorType } from "../../../groups/_internal/GroupSchema";
import { ConfigurableEntity } from "./ConfigurableEntity";
import { IArcGISContext } from "../../../ArcGISContext";
Expand All @@ -20,6 +21,7 @@ import {
IHubPage,
IHubProject,
IHubSite,
IHubTemplate,
} from "../../../core/types";
import { InitiativeTemplateEditorType } from "../../../initiative-templates/_internal/InitiativeTemplateSchema";

Expand Down Expand Up @@ -171,6 +173,25 @@ export async function getEntityEditorSchemas(
);

break;
// ----------------------------------------------------
case "template":
const { TemplateSchema } = await import(
"../../../templates/_internal/TemplateSchema"
);
schema = cloneObject(TemplateSchema);

const templateModule = await {
"hub:template:edit": () =>
import("../../../templates/_internal/TemplateUiSchemaEdit"),
}[type as TemplateEditorType]();
uiSchema = await templateModule.buildUiSchema(
i18nScope,
entity as IHubTemplate,
context
);

break;
// ----------------------------------------------------
case "group":
const { GroupSchema } = await import(
"../../../groups/_internal/GroupSchema"
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/core/schemas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SiteEditorTypes } from "../../sites/_internal/SiteSchema";
import { DiscussionEditorTypes } from "../../discussions/_internal/DiscussionSchema";
import { PageEditorTypes } from "../../pages/_internal/PageSchema";
import { ContentEditorTypes } from "../../content/_internal/ContentSchema";
import { TemplateEditorTypes } from "../../templates/_internal/TemplateSchema";
import { GroupEditorTypes } from "../../groups/_internal/GroupSchema";
import { InitiativeTemplateEditorTypes } from "../../initiative-templates/_internal/InitiativeTemplateSchema";

Expand All @@ -22,6 +23,7 @@ export const validEditorTypes = [
...SiteEditorTypes,
...DiscussionEditorTypes,
...PageEditorTypes,
...TemplateEditorTypes,
...GroupEditorTypes,
...InitiativeTemplateEditorTypes,
] as const;
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/core/types/HubEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { IHubProject } from "./IHubProject";
import { IHubSite } from "./IHubSite";
import { IHubDiscussion } from "./IHubDiscussion";
import { IHubGroup } from "./IHubGroup";
import { IHubTemplate } from "./IHubTemplate";

export type HubEntity =
| IHubSite
| IHubProject
| IHubDiscussion
| IHubInitiative
| IHubPage
| IHubGroup;
| IHubGroup
| IHubTemplate;
1 change: 1 addition & 0 deletions packages/common/src/core/types/HubEntityType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const HUB_ENTITY_TYPES = [
"content",
"org",
"group",
"template",
] as const;
export type HubEntityType = (typeof HUB_ENTITY_TYPES)[number];
15 changes: 15 additions & 0 deletions packages/common/src/core/types/IHubTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IWithSlug } from "../traits";
import { IHubItemEntity, IHubItemEntityEditor } from "./IHubItemEntity";

/** Defines the properties of a Hub Template entity */
export interface IHubTemplate extends IHubItemEntity, IWithSlug {
previewUrl: string;
isDeployed: boolean;
deployedType: string;
}

/**
* This type redefines the IHubTemplate interface in such a way
* that it can be consumed by the entity editor.
*/
export type IHubTemplateEditor = IHubItemEntityEditor<IHubTemplate> & {};
1 change: 1 addition & 0 deletions packages/common/src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from "./IHubLayout";
export * from "./IHubLocation";
export * from "./IHubPage";
export * from "./IHubProject";
export * from "./IHubTemplate";
export * from "./IHubSite";
export * from "./IHubSiteTheme";
export * from "./IHubTimeline";
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/core/updateHubEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { updateProject } from "../projects/edit";
import { updateSite } from "../sites/HubSites";
import { updatePage } from "../pages/HubPages";
import { updateInitiativeTemplate } from "../initiative-templates/edit";
import { updateTemplate } from "../templates/edit";
import {
HubEntity,
HubEntityType,
Expand All @@ -16,6 +17,7 @@ import {
IHubSite,
IHubPage,
IHubInitiativeTemplate,
IHubTemplate,
} from "./types";

/**
Expand Down Expand Up @@ -63,6 +65,12 @@ export const updateHubEntity = async (
case "page":
result = await updatePage(entity as IHubPage, context.userRequestOptions);
break;
case "template":
result = await updateTemplate(
entity as IHubTemplate,
context.userRequestOptions
);
break;
case "initiativeTemplate":
result = await updateInitiativeTemplate(
entity as IHubInitiativeTemplate,
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from "./resources";
export * from "./search";
export * from "./sites";
export * from "./surveys";
export * from "./templates";
export * from "./types";
export * from "./urls";
export * from "./users";
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/permissions/HubPermissionPolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { GroupPermissionPolicies } from "../groups/_internal/GroupBusinessRules"
import { PagePermissionPolicies } from "../pages/_internal/PageBusinessRules";
import { PlatformPermissionPolicies } from "./PlatformPermissionPolicies";
import { InitiativeTemplatePermissionPolicies } from "../initiative-templates/_internal/InitiativeTemplateBusinessRules";
import { TemplatePermissionPolicies } from "../templates/_internal/TemplateBusinessRules";

// Examples of possible Permission Policies
// const DiscussionPermissionPolicies: IPermissionPolicy[] = [
// {
Expand Down Expand Up @@ -82,6 +84,7 @@ export const HubPermissionsPolicies: IPermissionPolicy[] = [
...ContentPermissionPolicies,
...GroupPermissionPolicies,
...PagePermissionPolicies,
...TemplatePermissionPolicies,
...PlatformPermissionPolicies,
...TempPermissionPolicies,
...InitiativeTemplatePermissionPolicies,
Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/permissions/types/Permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GroupPermissions } from "../../groups/_internal/GroupBusinessRules";
import { PagePermissions } from "../../pages/_internal/PageBusinessRules";
import { PlatformPermissions } from "../PlatformPermissionPolicies";
import { InitiativeTemplatePermissions } from "../../initiative-templates/_internal/InitiativeTemplateBusinessRules";
import { TemplatePermissions } from "../../templates/_internal/TemplateBusinessRules";
/**
* Defines the values for Permissions
* It's critical that the arrays defined in the modules use `as const`
Expand All @@ -27,6 +28,7 @@ const validPermissions = [
...TempPermissions,
...DiscussionPermissions,
...InitiativeTemplatePermissions,
...TemplatePermissions,
] as const;

/**
Expand All @@ -42,7 +44,8 @@ export type Permission =
| (typeof PlatformPermissions)[number]
| (typeof TempPermissions)[number]
| (typeof DiscussionPermissions)[number]
| (typeof InitiativeTemplatePermissions)[number];
| (typeof InitiativeTemplatePermissions)[number]
| (typeof TemplatePermissions)[number];

/**
* Validate a Permission
Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/search/_internal/portalSearchItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { serializeQueryForPortal } from "../serializeQueryForPortal";
import { enrichPageSearchResult } from "../../pages/HubPages";
import { enrichProjectSearchResult } from "../../projects";
import { enrichSiteSearchResult } from "../../sites";
import { enrichTemplateSearchResult } from "../../templates/fetch";
import { IHubRequestOptions } from "../../types";

import {
Expand Down Expand Up @@ -225,7 +226,9 @@ export async function itemToSearchResult(
case "Hub Project":
fn = enrichProjectSearchResult;
break;

case "Solution":
fn = enrichTemplateSearchResult;
break;
// handle old hub sites
case "Web Mapping Application":
if (item.typeKeywords.includes("hubSite")) {
Expand Down
Loading

0 comments on commit 54d1fe6

Please sign in to comment.