Skip to content

Commit

Permalink
feat(): add recommendedTemplates to schema/uiSchema for initiative te…
Browse files Browse the repository at this point in the history
…mplate workspace (#1258)

* feat(): add workspace content permission

* fix(): remove alpha for testing

* fix(): typos

* fix(): revert content pane

* feat(): update schema and uiSchema

* fix(): typo in typekeywords

* test(): update spec test for init template ui schema

* test(): remove else path

* test(): move recommendedTemplatesCatalog to own module

* fix(): order of thumbnail and reinstate alpha
  • Loading branch information
jordantsanz authored Oct 12, 2023
1 parent 02d34d4 commit 339d1e6
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ export class HubInitiativeTemplate
* @param editor
*/
async fromEditor(editor: IHubInitiativeTemplateEditor): Promise<HubEntity> {
const isCreate = !editor.id;

// Setting the thumbnailCache will ensure that the thumbnail is updated on next save
if (editor._thumbnail) {
if (editor._thumbnail.blob) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const InitiativeTemplateSchema: IConfigurationSchema = {
if: { minLength: 1 },
then: { format: "uri" },
},
recommendedTemplates: {
type: "array",
items: {
type: "string",
},
},
},
// we have to do this to allow the format: url to pass through
} as IConfigurationSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IArcGISContext } from "../..";
import { IHubInitiativeTemplate } from "../../core";
import { getThumbnailUiSchemaElement } from "../../core/schemas/internal/getThumbnailUiSchemaElement";
import { IUiSchema, UiSchemaMessageTypes } from "../../core/schemas/types";
import { getRecommendedTemplatesCatalog } from "./getRecommendedTemplatesCatalog";

/**
* @private
Expand Down Expand Up @@ -85,6 +86,30 @@ export const buildUiSchema = async (
},
},
getThumbnailUiSchemaElement(i18nScope, entity),
{
type: "Control",
scope: "/properties/recommendedTemplates",
labelKey: `${i18nScope}.fields.recommendedTemplates.label`,
options: {
control: "hub-field-input-gallery-picker",
targetEntity: "item",
catalogs: getRecommendedTemplatesCatalog(
context.currentUser,
i18nScope
),
facets: [
{
label: `{{${i18nScope}.fields.recommendedTemplates.facets.sharing:translate}}`,
key: "access",
field: "access",
display: "multi-select",
operation: "OR",
},
],
canReorder: false,
linkTarget: "workspaceRelative",
},
},
],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { IHubCollection } from "../../search";
import {
getWellKnownCatalog,
WellKnownCatalog,
} from "../../search/wellKnownCatalog";
import { IUser } from "@esri/arcgis-rest-types";

export const getRecommendedTemplatesCatalog = (
user: IUser,
i18nScope: string
) => {
const catalogNames: WellKnownCatalog[] = [
"myContent",
"favorites",
"organization",
"world",
];

const catalogs = catalogNames.map((name: WellKnownCatalog) => {
const opts = { user };
const catalog = getWellKnownCatalog(
"initiativeTemplate.fields.recommendedTemplates",
name,
"item",
opts
);

// manually attach recommended templates collection
catalog.collections = [getRecommendedTemplatesCollection(i18nScope)];
return catalog;
});

return catalogs;
};

const getRecommendedTemplatesCollection = (
i18nScope: string
): IHubCollection => {
return {
targetEntity: "item",
key: "recommendedTemplates",
label: `${i18nScope}.fields.recommendedTemplates.collection.label`,
scope: {
targetEntity: "item",
filters: [
{
predicates: [
{
typekeywords: {
not: ["hubSolutionType|hubSiteApplication"],
},
},
],
},
{
predicates: [
{
typekeywords: {
any: [
"hubSolutionType|storymap",
"hubSolutionType|webmap",
"hubSolutionType|dashboard",
"hubSolutionType|hubpage",
"hubSolutionType|webexperience",
"hubSolutionType|webmappingapplication",
"hubSolutionType|form",
"hubSolutionType|featureservice",
"Template",
],
},
},
],
operation: "OR",
},
{
predicates: [
{
typekeywords: ["hubSolutionTemplate"],
},
{
type: "Solution",
typekeywords: ["Template"],
},
],
operation: "OR",
},
],
},
};
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { buildUiSchema } from "../../../src/initiative-templates/_internal/InitiativeTemplateUiSchemaEdit";
import { MOCK_CONTEXT } from "../../mocks/mock-auth";
import { UiSchemaMessageTypes } from "../../../src/core/schemas/types";
import * as getRecommendedTemplatesCatalogModule from "../../../src/initiative-templates/_internal/getRecommendedTemplatesCatalog";

describe("buildUiSchema: initiative template edit", () => {
it("returns the full initiative template edit uiSchema", async () => {
spyOn(
getRecommendedTemplatesCatalogModule,
"getRecommendedTemplatesCatalog"
).and.returnValue([]);
const uiSchema = await buildUiSchema(
"some.scope",
{
Expand Down Expand Up @@ -96,6 +101,27 @@ describe("buildUiSchema: initiative template edit", () => {
messages: [],
},
},
{
type: "Control",
scope: "/properties/recommendedTemplates",
labelKey: `some.scope.fields.recommendedTemplates.label`,
options: {
control: "hub-field-input-gallery-picker",
targetEntity: "item",
catalogs: [],
facets: [
{
label: `{{some.scope.fields.recommendedTemplates.facets.sharing:translate}}`,
key: "access",
field: "access",
display: "multi-select",
operation: "OR",
},
],
canReorder: false,
linkTarget: "workspaceRelative",
},
},
],
});
});
Expand Down
Loading

0 comments on commit 339d1e6

Please sign in to comment.