Skip to content

Commit

Permalink
feat(hub-common): adds followers group discussion settings on site wo… (
Browse files Browse the repository at this point in the history
#1251)

* feat(hub-common): adds followers group discussion settings on site workspace

affects: @esri/hub-common

* chore(): lint

* fix(hub-common): pR feedback

affects: @esri/hub-common
  • Loading branch information
tannerjt authored Oct 8, 2023
1 parent 98c4545 commit e0beb59
Show file tree
Hide file tree
Showing 65 changed files with 317 additions and 210 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/common/e2e/associations.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
import {
ICreateOutput,
cleanupItems,
createInitiative,
createProjects,
createScopeGroup,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/e2e/fixtures/initiative.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IHubInitiative, IModel } from "../../src";
import { IModel } from "../../src";

const model: IModel = {
item: {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/e2e/fixtures/project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IHubProject, IModel } from "../../src";
import { IModel } from "../../src";

const projectmodel: IModel = {
item: {
Expand Down
1 change: 0 additions & 1 deletion packages/common/e2e/metrics.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
import {
ICreateOutput,
cleanupItems,
createInitiative,
createProjects,
createScopeGroup,
Expand Down
2 changes: 0 additions & 2 deletions packages/common/e2e/permissions.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { IArcGISContext } from "../src/ArcGISContext";
import { fetchHubEntity } from "../src/core/fetchHubEntity";
import { HubEntity } from "../src/core/types/HubEntity";
import { IHubInitiative } from "../src/core/types/IHubInitiative";
import { HubInitiative } from "../src/initiatives/HubInitiative";
import { checkPermission } from "../src/permissions/checkPermission";
import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
Expand Down
4 changes: 0 additions & 4 deletions packages/common/e2e/purge-domains.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import {
lookupDomain,
deleteSite,
removeDomain,
batch,
IArcGISContext,
failSafe,
} from "../src";
import { hostnames } from "./fixtures/sample";
import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
let count = 0;
async function processDomain(cfg: {
domain: string;
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/content/_internal/computeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { IRequestOptions } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";
import { getItemThumbnailUrl } from "../../resources";
import { IModel } from "../../types";
import { bBoxToExtent, extentToPolygon, isBBox } from "../../extent";
import { bBoxToExtent, isBBox } from "../../extent";
import { IExtent } from "@esri/arcgis-rest-types";
import Geometry = __esri.Geometry;
import { getItemHomeUrl } from "../../urls/get-item-home-url";
import { getContentEditUrl, getHubRelativeUrl } from "./internalContentUtils";
import { IHubLocation } from "../../core/types/IHubLocation";
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/content/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IItem } from "@esri/arcgis-rest-types";
import { isMaster } from "cluster";
import { fetchItemEnrichments } from "../items/_enrichments";
import { getProp } from "../objects";
import { getItemThumbnailUrl } from "../resources";
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/core/EntityEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HubSite } from "../sites/HubSite";
import { HubTemplate } from "../templates";
import { IEditorConfig, IWithEditorBehavior } from "./behaviors";
import { getTypeFromEntity } from "./getTypeFromEntity";
import { EditorType, UiSchemaElementOptions } from "./schemas";
import { EditorType } from "./schemas";
import { HubEntity } from "./types/HubEntity";
import { HubEntityEditor, IEntityEditorContext } from "./types/HubEntityEditor";

Expand Down
21 changes: 20 additions & 1 deletion packages/common/src/core/HubItemEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from "./behaviors";

import { IWithThumbnailBehavior } from "./behaviors/IWithThumbnailBehavior";
import { AccessLevel, IHubItemEntity, SettableAccessLevel } from "./types";
import { IHubItemEntity, SettableAccessLevel } from "./types";
import { sharedWith } from "./_internal/sharedWith";
import { IWithDiscussionsBehavior } from "./behaviors/IWithDiscussionsBehavior";
import { setDiscussableKeyword } from "../discussions";
Expand Down Expand Up @@ -256,6 +256,25 @@ export abstract class HubItemEntity<T extends IHubItemEntity>
});
}

/**
* Sets whether or not the followers group is discussable
* @param isDiscussable
*/
async setFollowersGroupIsDiscussable(isDiscussable: boolean) {
const group = await this.getFollowersGroup();
const typeKeywords = setDiscussableKeyword(
group.typeKeywords,
isDiscussable
);
await updateGroup({
group: {
id: group.id,
typeKeywords,
},
authentication: this.context.session,
});
}

/**
* Return a list of groups the Entity is shared to.
* @returns
Expand Down
7 changes: 1 addition & 6 deletions packages/common/src/core/behaviors/IWithEditorBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
IConfigurationSchema,
IUiSchema,
UiSchemaElementOptions,
EditorType,
} from "../schemas";
import { IConfigurationSchema, IUiSchema, EditorType } from "../schemas";
import { HubEntity, HubEntityEditor, IEntityEditorContext } from "../types";

export interface IEditorConfig {
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/core/behaviors/IWithFollowersBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export interface IWithFollowersBehavior {
* Set the access level of the followers group
*/
setFollowersGroupAccess(access: SettableAccessLevel): Promise<void>;
/**
* Set whether or not the followers group is discussable
*/
setFollowersGroupIsDiscussable(isDiscussable: boolean): Promise<void>;
}
2 changes: 1 addition & 1 deletion packages/common/src/core/behaviors/IWithSharingBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IGetItemGroupsResponse, IGroup } from "@esri/arcgis-rest-portal";
import { IGroup } from "@esri/arcgis-rest-portal";
import { AccessLevel } from "../types";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { request } from "@esri/arcgis-rest-request";
import { IHubRequestOptions } from "../../../types";
import { HubEntity } from "../../types/HubEntity";
import { IUiSchemaComboboxItem } from "../types";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const HubItemEntitySchema: IConfigurationSchema = {
type: "boolean",
default: true,
},
isDiscussable: ENTITY_IS_DISCUSSABLE_SCHEMA,
},
},
view: {
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/core/traits/IWithMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IReference } from "../types";
import { IMetric } from "../types/Metrics";

/**
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/core/types/IAccessResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IPolicyCheck } from "../../permissions/types/IPolicyCheck";
import { PolicyResponse } from "../../permissions/types/PolicyResponse";

export interface IAccessResponse {
Expand Down
8 changes: 1 addition & 7 deletions packages/common/src/core/types/IHubInitiative.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
IWithSlug,
IWithLayout,
IWithPermissions,
IWithCatalog,
} from "../traits";
import {} from "../traits/IWithCatalog";
import { IWithSlug, IWithPermissions, IWithCatalog } from "../traits";
import { IWithMetrics } from "../traits/IWithMetrics";
import { IHubItemEntity, IHubItemEntityEditor } from "./IHubItemEntity";

Expand Down
1 change: 1 addition & 0 deletions packages/common/src/core/types/IHubItemEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ export type IHubItemEntityEditor<T> = Omit<T, "extent"> & {
_followers?: {
groupAccess?: AccessLevel;
showFollowAction?: boolean;
isDiscussable?: boolean;
};
};
1 change: 0 additions & 1 deletion packages/common/src/core/types/IHubProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
IWithCatalog,
} from "../traits/index";
import { IHubItemEntity, IHubItemEntityEditor } from "./IHubItemEntity";
import { IExtent } from "@esri/arcgis-rest-feature-layer";

/**
* Defines the properties of a Hub Project object
Expand Down
11 changes: 1 addition & 10 deletions packages/common/src/discussions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@ import {
AclCategory,
AclSubCategory,
IChannel,
IChannelAclPermission,
SharingAccess,
} from "./api/types";
import {
IFilter,
IHubSearchOptions,
IHubSearchResponse,
IHubSearchResult,
IPredicate,
IQuery,
hubSearch,
} from "../search";
import { IFilter, IPredicate, IQuery } from "../search";

/**
* Utility to determine if a given IGroup, IItem, IHubContent, or IHubItemEntity
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/groups/addGroupMembers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IAuthenticationManager } from "@esri/arcgis-rest-request";
import { IUser } from "@esri/arcgis-rest-types";
import { failSafe } from "../utils";
import { autoAddUsers } from "./autoAddUsers";
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/metrics/resolveMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getProp } from "../objects/get-prop";
import { IPredicate, IQuery } from "../search/types/IHubCatalog";
import { combineQueries } from "../search/_internal/combineQueries";
import { IHubSearchOptions } from "../search/types/IHubSearchOptions";
import { memoize } from "../utils/memoize";
import { portalSearchItemsAsItems } from "../search/_internal/portalSearchItems";

/**
Expand Down
7 changes: 1 addition & 6 deletions packages/common/src/pages/HubPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ import { getPropertyMap } from "./_internal/getPropertyMap";
import { computeProps } from "./_internal/computeProps";
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";
import { IUserItemOptions, removeItem } from "@esri/arcgis-rest-portal";
import {
DEFAULT_PAGE,
DEFAULT_PAGE_MODEL,
HUB_PAGE_ITEM_TYPE,
ENTERPRISE_PAGE_ITEM_TYPE,
} from "./defaults";
import { DEFAULT_PAGE, DEFAULT_PAGE_MODEL } from "./defaults";

/**
* @private
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/pages/_internal/computeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { processEntityFeatures } from "../../permissions/_internal/processEntity
import { PageDefaultFeatures } from "./PageBusinessRules";
import { getItemHomeUrl } from "../../urls/get-item-home-url";
import { IHubPage } from "../../core/types/IHubPage";
import { getHubRelativeUrl } from "../../content/_internal/internalContentUtils";
import { getRelativeWorkspaceUrl } from "../../core/getRelativeWorkspaceUrl";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/projects/HubProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
IHubCardViewModel,
} from "../core/types/IHubCardViewModel";
import { projectToCardModel } from "./view";
import { cloneObject, maybePush } from "../util";
import { cloneObject } from "../util";
import { createProject, editorToProject, updateProject } from "./edit";
import { ProjectEditorType } from "./_internal/ProjectSchema";
import { enrichEntity } from "../core/enrichEntity";
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/search/_internal/explainPredicate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { GenericResult, IPredicateExplanation } from "../explainQueryResult";
import { cloneObject } from "../../util";
import { IMatchOptions } from "../types";
import {
PREDICATE_DATE_PROPS,
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from "@esri/arcgis-rest-portal";
import { isPageType } from "../content/_internal/internalContentUtils";
import { IHubSite } from "../core";
import { getProp } from "../objects/get-prop";
import { ISearchResponse } from "../types";
import { cloneObject } from "../util";
import { IHubSearchResult } from "./types";
Expand Down
19 changes: 17 additions & 2 deletions packages/common/src/sites/HubSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { IContainsResponse, IDeepCatalogInfo, IHubCatalog } from "../search";
import { deepContains } from "../core/_internal/deepContains";

import {
applyVersion,
createVersion,
deleteVersion,
getVersion,
Expand All @@ -47,7 +46,13 @@ import { cloneObject } from "../util";
import { PropertyMapper } from "../core/_internal/PropertyMapper";
import { getPropertyMap } from "./_internal/getPropertyMap";

import { IHubSiteEditor, IModel, setProp, SettableAccessLevel } from "../index";
import {
IHubSiteEditor,
IModel,
isDiscussable,
setProp,
SettableAccessLevel,
} from "../index";
import { SiteEditorType } from "./_internal/SiteSchema";

/**
Expand Down Expand Up @@ -424,6 +429,9 @@ export class HubSite
editor
);

const followersGroup = await this.getFollowersGroup();
setProp("_followers.isDiscussable", isDiscussable(followersGroup), editor);

editor._discussions = this.entity.features["hub:site:feature:discussions"];

return editor;
Expand Down Expand Up @@ -458,6 +466,13 @@ export class HubSite

delete editor._thumbnail;

// set whether or not the followers group is discussable
if (editor._followers?.isDiscussable !== undefined) {
await this.setFollowersGroupIsDiscussable(
editor._followers.isDiscussable
);
}

// set the followers group access
if (editor._followers?.groupAccess) {
await this.setFollowersGroupAccess(
Expand Down
17 changes: 17 additions & 0 deletions packages/common/src/sites/_internal/SiteUiSchemaFollowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ export const buildUiSchema = async (
},
},
},
{
labelKey: `${i18nScope}.fields.followers.discussable.label`,
scope: "/properties/_followers/properties/isDiscussable",
type: "Control",
options: {
control: "hub-field-input-radio",
labels: [
`{{${i18nScope}.fields.followers.discussable.enabled.label:translate}}`,
`{{${i18nScope}.fields.followers.discussable.disabled.label:translate}}`,
],
descriptions: [
`{{${i18nScope}.fields.followers.discussable.enabled.description:translate}}`,
`{{${i18nScope}.fields.followers.discussable.disabled.description:translate}}`,
],
icons: ["speech-bubbles", "circle-disallowed"],
},
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getProp } from "../../objects/get-prop";
import { IHubCatalog } from "../../search/types/IHubCatalog";
import { IModel } from "../../types";

Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/Hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IUser } from "@esri/arcgis-rest-types";
// imported with a full path
import { ArcGISContextManager } from "../src/ArcGISContextManager";
import { Hub } from "../src/Hub";
import { IArcGISContextManagerOptions, IHubProject } from "../src";
import { IArcGISContextManagerOptions } from "../src";
import { MOCK_AUTH } from "./mocks/mock-auth";
// import * as ProjectsModule from "../src/projects/HubProjects";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IItem } from "@esri/arcgis-rest-types";
import { getContentEditUrl } from "../../../src/content/_internal/internalContentUtils";
import { IHubRequestOptions, IModel } from "../../../src/types";
import { IHubRequestOptions } from "../../../src/types";
import { cloneObject } from "../../../src/util";
import { MOCK_HUB_REQOPTS } from "../../mocks/mock-auth";

Expand Down
1 change: 0 additions & 1 deletion packages/common/test/content/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
cloneObject,
enrichContentSearchResult,
IHubRequestOptions,
IHubSearchResult,
} from "../../src";
import * as FetchEnrichments from "../../src/items/_enrichments";

Expand Down
Loading

0 comments on commit e0beb59

Please sign in to comment.